mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-02-23 14:59:07 +08:00
working on extracting of updates
This commit is contained in:
parent
9b6c18cd6b
commit
3811f7d704
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
.sass-cache
|
.sass-cache
|
||||||
vendor/*
|
vendor/*
|
||||||
storage/textures/*
|
storage/textures/*
|
||||||
|
storage/update_cache/*
|
||||||
node_modules/*
|
node_modules/*
|
||||||
resources/assets/src/bower_components/*
|
resources/assets/src/bower_components/*
|
||||||
koala-config.json
|
koala-config.json
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use Arr;
|
use Arr;
|
||||||
use Log;
|
use Log;
|
||||||
use Utils;
|
use Utils;
|
||||||
|
use ZipArchive;
|
||||||
use App\Services\Storage;
|
use App\Services\Storage;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@ -140,7 +141,43 @@ class UpdateController extends Controller
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'extract':
|
case 'extract':
|
||||||
//
|
|
||||||
|
if (!file_exists($tmp_path)) exit('No file available');
|
||||||
|
|
||||||
|
$extract_dir = storage_path("update_cache/{$this->latestVersion}");
|
||||||
|
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$res = $zip->open($tmp_path);
|
||||||
|
|
||||||
|
if ($res === true) {
|
||||||
|
Log::info("[ZipArchive] Extracting file $tmp_path");
|
||||||
|
|
||||||
|
try {
|
||||||
|
$zip->extractTo($extract_dir);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
exit('发生错误:'.$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
exit('更新包解压缩失败。错误代码:'.$res);
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
if (Storage::copyDir($extract_dir, base_path()) !== true) {
|
||||||
|
|
||||||
|
Storage::removeDir(storage_path('update_cache'));
|
||||||
|
exit('无法覆盖文件。');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Log::info("[Extracter] Covering files");
|
||||||
|
Storage::removeDir(storage_path('update_cache'));
|
||||||
|
|
||||||
|
Log::info("[Extracter] Cleaning cache");
|
||||||
|
}
|
||||||
|
|
||||||
|
return json('更新完成', 0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -70,7 +70,7 @@ class Storage
|
|||||||
$size = 0;
|
$size = 0;
|
||||||
while($filename = @readdir($resource)) {
|
while($filename = @readdir($resource)) {
|
||||||
if ($filename != "." && $filename != "..") {
|
if ($filename != "." && $filename != "..") {
|
||||||
$path = $dir.$filename;
|
$path = "$dir/$filename";
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
// recursion
|
// recursion
|
||||||
self::removeDir($path."/");
|
self::removeDir($path."/");
|
||||||
@ -96,7 +96,7 @@ class Storage
|
|||||||
$size = 0;
|
$size = 0;
|
||||||
while($filename = @readdir($resource)) {
|
while($filename = @readdir($resource)) {
|
||||||
if ($filename != "." && $filename != "..") {
|
if ($filename != "." && $filename != "..") {
|
||||||
$path = $dir.$filename;
|
$path = "$dir/$filename";
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
// recursion
|
// recursion
|
||||||
$size += self::getDirSize($path);
|
$size += self::getDirSize($path);
|
||||||
@ -121,7 +121,7 @@ class Storage
|
|||||||
$resource = opendir($dir);
|
$resource = opendir($dir);
|
||||||
while($filename = readdir($resource)) {
|
while($filename = readdir($resource)) {
|
||||||
if ($filename != "." && $filename != "..") {
|
if ($filename != "." && $filename != "..") {
|
||||||
$path = $dir.$filename;
|
$path = "$dir/$filename";
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
// recursion
|
// recursion
|
||||||
$file_num = self::getFileNum($path, $file_num);
|
$file_num = self::getFileNum($path, $file_num);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-07-22 14:02:44
|
* @Date: 2016-07-22 14:02:44
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-11-25 12:45:28
|
* @Last Modified time: 2016-11-25 13:10:36
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -353,17 +353,33 @@ function downloadUpdates() {
|
|||||||
|
|
||||||
var interval_id = window.setInterval(function() {
|
var interval_id = window.setInterval(function() {
|
||||||
|
|
||||||
|
$('#imported-progress').html(progress);
|
||||||
|
$('.progress-bar').css('width', progress+'%').attr('aria-valuenow', progress);
|
||||||
|
|
||||||
if (progress == 100) {
|
if (progress == 100) {
|
||||||
clearInterval(interval_id);
|
clearInterval(interval_id);
|
||||||
|
|
||||||
$('#modal-start-download').modal('toggle');
|
toastr.success('正在解压更新包');
|
||||||
|
|
||||||
|
console.log("Start extracting");
|
||||||
|
$.ajax({
|
||||||
|
url: './update/download?action=extract',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json'
|
||||||
|
})
|
||||||
|
.done(function(json) {
|
||||||
|
console.log("Files covered");
|
||||||
|
$('#modal-start-download').modal('toggle');
|
||||||
|
|
||||||
|
swal({
|
||||||
|
type: 'success',
|
||||||
|
html: json.msg
|
||||||
|
}).then(function() {
|
||||||
|
window.location = "../";
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(showAjaxError);
|
||||||
|
|
||||||
swal({
|
|
||||||
type: 'success',
|
|
||||||
html: '下载完成!'
|
|
||||||
}).then(function(new_name) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: './update/download?action=get-file-size',
|
url: './update/download?action=get-file-size',
|
||||||
@ -372,9 +388,6 @@ function downloadUpdates() {
|
|||||||
.done(function(json) {
|
.done(function(json) {
|
||||||
progress = (json.size / file_size * 100).toFixed(2);
|
progress = (json.size / file_size * 100).toFixed(2);
|
||||||
|
|
||||||
$('#imported-progress').html(progress);
|
|
||||||
$('.progress-bar').css('width', progress+'%').attr('aria-valuenow', progress);
|
|
||||||
|
|
||||||
console.log("Progress: "+progress);
|
console.log("Progress: "+progress);
|
||||||
})
|
})
|
||||||
.fail(showAjaxError);
|
.fail(showAjaxError);
|
||||||
|
2
storage/update_cache/.gitignore
vendored
2
storage/update_cache/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
Loading…
Reference in New Issue
Block a user