ComposerUpdate&优化文件上传

This commit is contained in:
Anyon 2020-03-27 10:19:58 +08:00
parent 4b1ee3933a
commit 059e6459a8
6 changed files with 25 additions and 17 deletions

View File

@ -57,9 +57,8 @@ class Upload extends Controller
*/ */
public function state() public function state()
{ {
$this->name = input('name', null); list($this->name, $this->safe) = [input('name', null), boolval(input('safe'))];
$this->safe = boolval(input('safe')); $data = ['uptype' => $this->getType(), 'xkey' => input('xkey'), 'safe' => $this->safe];
$data = ['uptype' => $this->getType(), 'xkey' => input('xkey')];
if ($info = Storage::instance($data['uptype'])->info($data['xkey'], $this->safe, $this->name)) { if ($info = Storage::instance($data['uptype'])->info($data['xkey'], $this->safe, $this->name)) {
$data['url'] = $info['url']; $data['url'] = $info['url'];
$this->success('文件已经上传', $data, 200); $this->success('文件已经上传', $data, 200);
@ -78,8 +77,7 @@ class Upload extends Controller
$data['OSSAccessKeyId'] = $token['keyid']; $data['OSSAccessKeyId'] = $token['keyid'];
$data['server'] = AliossStorage::instance()->upload(); $data['server'] = AliossStorage::instance()->upload();
} }
$data['safe'] = intval($this->safe); $this->success('获取授权参数', $data, 404);
$this->success('获取上传参数', $data, 404);
} }
/** /**
@ -106,7 +104,16 @@ class Upload extends Controller
} }
list($this->safe, $this->uptype, $this->name) = [boolval(input('safe')), $this->getType(), input('xkey')]; list($this->safe, $this->uptype, $this->name) = [boolval(input('safe')), $this->getType(), input('xkey')];
if (empty($this->name)) $this->name = Storage::name($file->getPathname(), $this->extension, '', 'md5_file'); if (empty($this->name)) $this->name = Storage::name($file->getPathname(), $this->extension, '', 'md5_file');
$info = Storage::instance($this->uptype)->set($this->name, file_get_contents($file->getRealPath()), $this->safe, $file->getOriginalName()); if ($this->uptype === 'local') {
$local = LocalStorage::instance();
$realpath = dirname($realname = $local->path($this->name, $this->safe));
file_exists($realpath) && is_dir($realpath) || mkdir($realpath, 0755, true);
@move_uploaded_file($file->getPathname(), $realname);
$info = $local->info($this->name, $this->safe, $file->getOriginalName());
} else {
$bina = file_get_contents($file->getRealPath());
$info = Storage::instance($this->uptype)->set($this->name, $bina, $this->safe, $file->getOriginalName());
}
if (is_array($info) && isset($info['url'])) { if (is_array($info) && isset($info['url'])) {
return json(['uploaded' => true, 'filename' => $this->name, 'url' => $this->safe ? $this->name : $info['url']]); return json(['uploaded' => true, 'filename' => $this->name, 'url' => $this->safe ? $this->name : $info['url']]);
} else { } else {

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e" "reference": "233e269155871ca9ef6b818536687d5862acef5b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/233e269155871ca9ef6b818536687d5862acef5b",
"reference": "ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e", "reference": "233e269155871ca9ef6b818536687d5862acef5b",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -958,7 +958,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "homepage": "http://framework.thinkadmin.top",
"time": "2020-03-25T02:06:11+00:00" "time": "2020-03-26T10:28:21+00:00"
}, },
{ {
"name": "zoujingli/wechat-developer", "name": "zoujingli/wechat-developer",

View File

@ -935,12 +935,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e" "reference": "233e269155871ca9ef6b818536687d5862acef5b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/233e269155871ca9ef6b818536687d5862acef5b",
"reference": "ec34c3a4e22f6f9a484c4728db0c63e6c9e0371e", "reference": "233e269155871ca9ef6b818536687d5862acef5b",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -956,7 +956,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2020-03-25T02:06:11+00:00", "time": "2020-03-26T10:28:21+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2020-03-25 10:13:48 // This file is automatically generated at:2020-03-27 10:03:07
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -138,7 +138,7 @@ class WorkQueue extends Queue
if (isset($this->queue['loops_time']) && $this->queue['loops_time'] > 0) { if (isset($this->queue['loops_time']) && $this->queue['loops_time'] > 0) {
try { try {
$this->qService->initialize($this->code)->reset($this->queue['loops_time']); $this->qService->initialize($this->code)->reset($this->queue['loops_time']);
} catch (\Exception $exception) { } catch (\Exception|\Error $exception) {
$this->app->log->error("Queue {$this->queue['code']} Loops Failed. {$exception->getMessage()}"); $this->app->log->error("Queue {$this->queue['code']} Loops Failed. {$exception->getMessage()}");
} }
} }

View File

@ -139,8 +139,9 @@ class QueueService extends Service
if (empty($rscript) && ($queue = $this->app->db->name('SystemQueue')->where($map)->find())) { if (empty($rscript) && ($queue = $this->app->db->name('SystemQueue')->where($map)->find())) {
throw new \think\admin\Exception(lang('think_library_queue_exist'), 0, $queue['code']); throw new \think\admin\Exception(lang('think_library_queue_exist'), 0, $queue['code']);
} }
$this->code = CodeExtend::uniqidDate(16, 'Q');
$this->app->db->name('SystemQueue')->strict(false)->failException(true)->insert([ $this->app->db->name('SystemQueue')->strict(false)->failException(true)->insert([
'code' => $this->code = CodeExtend::uniqidDate(16, 'Q'), 'code' => $this->code,
'title' => $title, 'title' => $title,
'command' => $command, 'command' => $command,
'attempts' => '0', 'attempts' => '0',