Browse Source

调整文件上传检测参数( xkey 统一改名 key )

邹景立 4 years ago
parent
commit
c3093b487f
2 changed files with 10 additions and 11 deletions
  1. 8 8
      app/admin/controller/api/Upload.php
  2. 2 3
      app/admin/view/api/upload.js

+ 8 - 8
app/admin/controller/api/Upload.php

@@ -62,26 +62,26 @@ class Upload extends Controller
     public function state()
     {
         [$this->name, $this->safe] = [input('name', null), $this->getSafe()];
-        $data = ['uptype' => $this->getType(), 'xkey' => input('xkey'), 'safe' => intval($this->safe)];
-        if ($info = Storage::instance($data['uptype'])->info($data['xkey'], $this->safe, $this->name)) {
+        $data = ['uptype' => $this->getType(), 'safe' => intval($this->safe), 'key' => input('key')];
+        if ($info = Storage::instance($data['uptype'])->info($data['key'], $this->safe, $this->name)) {
             $data['url'] = $info['url'];
             $this->success('文件已经上传', $data, 200);
         } elseif ('local' === $data['uptype']) {
-            $data['url'] = LocalStorage::instance()->url($data['xkey'], $this->safe, $this->name);
+            $data['url'] = LocalStorage::instance()->url($data['key'], $this->safe, $this->name);
             $data['server'] = LocalStorage::instance()->upload();
         } elseif ('qiniu' === $data['uptype']) {
-            $data['url'] = QiniuStorage::instance()->url($data['xkey'], $this->safe, $this->name);
-            $data['token'] = QiniuStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
+            $data['url'] = QiniuStorage::instance()->url($data['key'], $this->safe, $this->name);
+            $data['token'] = QiniuStorage::instance()->buildUploadToken($data['key'], 3600, $this->name);
             $data['server'] = QiniuStorage::instance()->upload();
         } elseif ('alioss' === $data['uptype']) {
-            $token = AliossStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
+            $token = AliossStorage::instance()->buildUploadToken($data['key'], 3600, $this->name);
             $data['url'] = $token['siteurl'];
             $data['policy'] = $token['policy'];
             $data['signature'] = $token['signature'];
             $data['OSSAccessKeyId'] = $token['keyid'];
             $data['server'] = AliossStorage::instance()->upload();
         } elseif ('txcos' === $data['uptype']) {
-            $token = TxcosStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
+            $token = TxcosStorage::instance()->buildUploadToken($data['key'], 3600, $this->name);
             $data['url'] = $token['siteurl'];
             $data['q-ak'] = $token['q-ak'];
             $data['policy'] = $token['policy'];
@@ -114,7 +114,7 @@ class Upload extends Controller
         if (in_array($this->extension, ['php', 'sh'])) {
             return json(['uploaded' => false, 'error' => ['message' => '可执行文件禁止上传到本地服务器']]);
         }
-        [$this->safe, $this->uptype, $this->name] = [$this->getSafe(), $this->getType(), input('xkey')];
+        [$this->uptype, $this->safe, $this->name] = [$this->getType(), $this->getSafe(), input('key')];
         if (empty($this->name)) $this->name = Storage::name($file->getPathname(), $this->extension, '', 'md5_file');
         if ($this->uptype === 'local') {
             $local = LocalStorage::instance();

+ 2 - 3
app/admin/view/api/upload.js

@@ -25,12 +25,11 @@ define(['md5'], function (SparkMD5, allowMime) {
                     md5file(file).then(function (file) {
                         option.element.triggerHandler('upload.hash', file);
                         jQuery.ajax("{:url('admin/api.upload/state')}", {
-                            data: {xkey: file.xkey, uptype: option.uptype, safe: option.safe, name: file.name}, method: 'post', success: function (ret) {
+                            data: {key: file.xkey, uptype: option.uptype, safe: option.safe, name: file.name}, method: 'post', success: function (ret) {
                                 if (parseInt(ret.code) === 404) {
                                     file.xurl = ret.data.url;
                                     option.uploader.config.url = ret.data.server;
-                                    option.uploader.config.data.key = ret.data.xkey;
-                                    option.uploader.config.data.xkey = ret.data.xkey;
+                                    option.uploader.config.data.key = ret.data.key;
                                     option.uploader.config.data.safe = ret.data.safe;
                                     option.uploader.config.data.uptype = ret.data.uptype;
                                     if (ret.data.uptype === 'qiniu') {