diff --git a/app/admin/controller/api/Upload.php b/app/admin/controller/api/Upload.php index 354b7496f..4a6c7dc9a 100644 --- a/app/admin/controller/api/Upload.php +++ b/app/admin/controller/api/Upload.php @@ -49,6 +49,7 @@ class Upload extends Controller } $template = realpath(__DIR__ . '/../../view/api/upload.js'); $data['exts'] = json_encode($data['exts'], JSON_UNESCAPED_UNICODE); + $data['nameType'] = sysconf('storage.name_type') ?: 'xmd5'; return view($template, $data)->contentType('application/x-javascript'); } diff --git a/app/admin/view/api/upload.js b/app/admin/view/api/upload.js index 991204f0b..f80a5f8f8 100644 --- a/app/admin/view/api/upload.js +++ b/app/admin/view/api/upload.js @@ -106,12 +106,11 @@ define(['md5'], function (SparkMD5, allowMime) { file.xext = file.name.indexOf('.') > -1 ? file.name.split('.').pop() : 'tmp'; /*! 兼容不能计算文件 HASH 的情况 */ - if (!window.FileReader) return jQuery.when((function (date, chars) { - date = new Date(), chars = 'abcdefhijkmnprstwxyz0123456789'; - this.xmd5 = '' + date.getFullYear() + (date.getMonth() + 1) + date.getDay() + date.getHours() + date.getMinutes() + date.getSeconds(); - while (this.xmd5.length < 32) this.xmd5 += chars.charAt(Math.floor(Math.random() * chars.length)); - return setFileXdata(file, this.xmd5), deferred.resolve(file, file.xmd5, file.xkey), deferred; - }).call(this)); + var IsDate = '{$nameType|default=""}'.indexOf('date') > -1; + if (!window.FileReader || IsDate) return jQuery.when((function (xmd5, chars) { + while (xmd5.length < 32) xmd5 += chars.charAt(Math.floor(Math.random() * chars.length)); + return setFileXdata(file, xmd5, 6), deferred.resolve(file, file.xmd5, file.xkey), deferred; + })(layui.util.toDateString(Date.now(), 'yyyyMMddHHmmss-'), '0123456789')); /*! 读取文件并计算 HASH 值 */ var spark = new SparkMD5.ArrayBuffer(); @@ -119,8 +118,8 @@ define(['md5'], function (SparkMD5, allowMime) { file.chunkIdx = 0, file.chunkSize = 2097152, file.chunkTotal = Math.ceil(this.size / this.chunkSize); return jQuery.when(loadNextChunk(file)); - function setFileXdata(file, xmd5) { - file.xmd5 = xmd5, file.xkey = file.xmd5.substr(0, 2) + '/' + file.xmd5.substr(2, 30) + '.' + file.xext; + function setFileXdata(file, xmd5, slice) { + file.xmd5 = xmd5, file.xkey = file.xmd5.substr(0, slice || 2) + '/' + file.xmd5.substr(slice || 2, 30) + '.' + file.xext; return delete file.chunkIdx, delete file.chunkSize, delete file.chunkTotal, file; } diff --git a/app/admin/view/config/storage-0.html b/app/admin/view/config/storage-0.html index 87838fabd..b5120e202 100644 --- a/app/admin/view/config/storage-0.html +++ b/app/admin/view/config/storage-0.html @@ -1,3 +1,21 @@ +
类型为“文件哈希”时可以实时文件秒传功能,同一个文件只需上传一次节省存储空间,推荐使用。
+设置系统允许上传文件的后缀,多个以英文逗号隔开如:png,jpg,rar,doc
+设置系统允许上传文件的后缀,多个以英文逗号隔开如:png,jpg,rar,doc,未设置允许上传的后缀
填写阿里云OSS存储空间名称,如:think-admin-oss
+填写阿里云OSS存储空间名称,如:think-admin-oss(需要是全区唯一的值,不存在时会自动创建)