diff --git a/app/admin/controller/Config.php b/app/admin/controller/Config.php index ce718e23f..879da3b13 100644 --- a/app/admin/controller/Config.php +++ b/app/admin/controller/Config.php @@ -21,6 +21,7 @@ use think\admin\service\AdminService; use think\admin\service\ModuleService; use think\admin\service\RuntimeService; use think\admin\service\SystemService; +use think\admin\Storage; use think\admin\storage\AliossStorage; use think\admin\storage\QiniuStorage; use think\admin\storage\TxcosStorage; @@ -53,6 +54,7 @@ class Config extends Controller public function index() { $this->title = '系统参数配置'; + $this->files = Storage::types(); $this->super = AdminService::isSuper(); $this->version = ModuleService::getVersion(); $this->fetch(); diff --git a/app/admin/controller/api/Upload.php b/app/admin/controller/api/Upload.php index 52c5cc319..ef9585767 100644 --- a/app/admin/controller/api/Upload.php +++ b/app/admin/controller/api/Upload.php @@ -22,6 +22,7 @@ use think\admin\model\SystemFile; use think\admin\service\AdminService; use think\admin\Storage; use think\admin\storage\AliossStorage; +use think\admin\storage\AlistStorage; use think\admin\storage\LocalStorage; use think\admin\storage\QiniuStorage; use think\admin\storage\TxcosStorage; @@ -107,34 +108,47 @@ class Upload extends Controller $extr = ['id' => $file->id ?? 0, 'url' => $info['url'], 'key' => $info['key']]; $this->success('文件已经上传', array_merge($data, $extr), 200); } elseif ('local' === $data['uptype']) { - $data['url'] = LocalStorage::instance()->url($data['key'], $safe, $name); - $data['server'] = LocalStorage::instance()->upload(); + $local = LocalStorage::instance(); + $data['url'] = $local->url($data['key'], $safe, $name); + $data['server'] = $local->upload(); } elseif ('qiniu' === $data['uptype']) { - $data['url'] = QiniuStorage::instance()->url($data['key'], $safe, $name); - $data['token'] = QiniuStorage::instance()->buildUploadToken($data['key'], 3600, $name); - $data['server'] = QiniuStorage::instance()->upload(); + $qiniu = QiniuStorage::instance(); + $data['url'] = $qiniu->url($data['key'], $safe, $name); + $data['token'] = $qiniu->token($data['key'], 3600, $name); + $data['server'] = $qiniu->upload(); } elseif ('alioss' === $data['uptype']) { - $token = AliossStorage::instance()->buildUploadToken($data['key'], 3600, $name); + $alioss = AliossStorage::instance(); + $token = $alioss->token($data['key'], 3600, $name); $data['url'] = $token['siteurl']; $data['policy'] = $token['policy']; $data['signature'] = $token['signature']; $data['OSSAccessKeyId'] = $token['keyid']; - $data['server'] = AliossStorage::instance()->upload(); + $data['server'] = $alioss->upload(); } elseif ('txcos' === $data['uptype']) { - $token = TxcosStorage::instance()->buildUploadToken($data['key'], 3600, $name); + $txcos = TxcosStorage::instance(); + $token = $txcos->token($data['key'], 3600, $name); $data['url'] = $token['siteurl']; $data['q-ak'] = $token['q-ak']; $data['policy'] = $token['policy']; $data['q-key-time'] = $token['q-key-time']; $data['q-signature'] = $token['q-signature']; $data['q-sign-algorithm'] = $token['q-sign-algorithm']; - $data['server'] = TxcosStorage::instance()->upload(); + $data['server'] = $txcos->upload(); } elseif ('upyun' === $data['uptype']) { - $token = UpyunStorage::instance()->buildUploadToken($data['key'], 3600, $name, input('hash', '')); + $upyun = UpyunStorage::instance(); + $token = $upyun->token($data['key'], 3600, $name, input('hash', '')); $data['url'] = $token['siteurl']; $data['policy'] = $token['policy']; + $data['server'] = $upyun->upload(); $data['authorization'] = $token['authorization']; - $data['server'] = UpyunStorage::instance()->upload(); + } elseif ('alist' === $data['uptype']) { + $alist = AlistStorage::instance(); + $data['url'] = $alist->url($data['key']); + $data['server'] = $alist->upload(); + $data['filepath'] = $alist->real($data['key'], true); + $data['authorization'] = $alist->token(); + } else { + $this->error('未知的存储引擎!'); } $file->save(['xurl' => $data['url'], 'isfast' => 0, 'issafe' => $data['safe']]); $this->success('获取上传授权参数', array_merge($data, ['id' => $file->id ?? 0]), 404); diff --git a/app/admin/view/api/upload.js b/app/admin/view/api/upload.js index 97e12056d..41cb590d7 100644 --- a/app/admin/view/api/upload.js +++ b/app/admin/view/api/upload.js @@ -114,13 +114,19 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { file.xsafe = ret.data.safe, file.xpath = ret.data.key, file.xtype = ret.data.uptype; if (parseInt(ret.code) === 404) { var uploader = {}; + uploader.uptype = ret.data.uptype; uploader.url = ret.data.server; + uploader.head = {}; uploader.form = new FormData(); uploader.form.append('key', ret.data.key); uploader.form.append('safe', ret.data.safe); uploader.form.append('uptype', ret.data.uptype); if (ret.data.uptype === 'qiniu') { uploader.form.append('token', ret.data.token); + } else if (ret.data.uptype === 'alist') { + uploader.type = 'put'; + uploader.head['file-path'] = ret.data['filepath']; + uploader.head['authorization'] = ret.data['authorization']; } else if (ret.data.uptype === 'alioss') { uploader.form.append('policy', ret.data['policy']); uploader.form.append('signature', ret.data['signature']); @@ -145,8 +151,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { uploader.form.append('Content-Disposition', 'inline;filename=' + encodeURIComponent(file.name)); } uploader.form.append('file', file, file.name), jQuery.ajax({ - xhrFields: {withCredentials: ret.data.uptype === 'local'}, - url: uploader.url, data: uploader.form, type: 'post', xhr: function (xhr) { + xhrFields: {withCredentials: ret.data.uptype === 'local'}, headers: uploader.head, + url: uploader.url, data: uploader.form, type: uploader.type || 'post', xhr: function (xhr) { xhr = new XMLHttpRequest(); return xhr.upload.addEventListener('progress', function (event) { file.xtotal = event.total, file.xloaded = event.loaded || 0; @@ -167,6 +173,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { /*! 检查单个文件上传返回的结果 */ if (typeof ret === 'object' && ret.code < 1) { that.event('upload.error', {file: file}, file, ret.info || '上传失败'); + } else if (uploader.uptype === 'alist' && parseInt(ret.code) !== 200) { + that.event('upload.error', {file: file}, file, ret.message || '上传失败'); } else { that.done(ret, file.index, file, done, '上传成功'); } diff --git a/app/admin/view/config/index.html b/app/admin/view/config/index.html index 25d5bdee9..15397f4c1 100644 --- a/app/admin/view/config/index.html +++ b/app/admin/view/config/index.html @@ -67,18 +67,19 @@ {if !sysconf('storage.local_http_protocol')}{php}sysconf('storage.local_http_protocol','follow');{/php}{/if}
- {foreach ['local'=>'本地服务器存储','qiniu'=>'七牛云对象存储','upyun'=>'又拍云USS存储','alioss'=>'阿里云OSS存储','txcos'=>'腾讯云COS存储'] as $k => $v}{if sysconf('storage.type') eq $k} + {foreach $files as $k => $v}{if sysconf('storage.type') eq $k} {if auth('storage')}{$v}{else}{$v}{/if} {else} {if auth('storage')}{$v}{else}{$v}{/if} {/if}{/foreach}
-

本地服务器存储:文件直接上传到本地服务器的 `static/upload` 目录,不支持大文件上传,占用服务器磁盘空间,访问时消耗服务器带宽流量。

-

七牛云对象存储:文件直接上传到七牛云存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

-

又拍云USS存储:文件直接上传到又拍云 USS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

-

阿里云OSS存储:文件直接上传到阿里云 OSS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

-

腾讯云COS存储:文件直接上传到腾讯云 COS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

+

本地服务器存储:文件上传到本地服务器的 `static/upload` 目录,不支持大文件上传,占用服务器磁盘空间,访问时消耗服务器带宽流量。

+

自建Alist存储:文件上传到 Alist 存储的服务器或云存储空间,根据服务配置可支持大文件上传,不占用本身服务器空间及服务器带宽流量。

+

七牛云对象存储:文件上传到七牛云存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

+

又拍云USS存储:文件上传到又拍云 USS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

+

阿里云OSS存储:文件上传到阿里云 OSS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

+

腾讯云COS存储:文件上传到腾讯云 COS 存储空间,支持大文件上传,不占用服务器空间及服务器带宽流量,支持 CDN 加速访问,访问量大时推荐使用。

@@ -113,7 +114,7 @@
管理程序版本,将显示在后台左上角标题。
-
公网备案号Baian
+
公网备案号Beian
- 请输入 32JWT 接口密钥,在使用 JWT 接口时需要使用其密钥进行加密及签名! + 请输入 32JWT 接口密钥,在使用 JWT 接口时需要使用此密钥进行加密及签名!
@@ -83,7 +83,7 @@
diff --git a/app/admin/view/file/index.html b/app/admin/view/file/index.html index 23d4448c9..aadb9b5d3 100644 --- a/app/admin/view/file/index.html +++ b/app/admin/view/file/index.html @@ -33,7 +33,7 @@ { field: 'xurl', title: '查看文件', width: '7%', align: 'center', templet: function (d) { if (typeof d.mime === 'string' && /^image\//.test(d.mime)) { - return laytpl('
').render(d) + return laytpl('
').render(d) } else if (typeof d.mime === 'string' && /^(video|audio)\//.test(d.mime)) { return laytpl('
查看
').render(d); } else {