From f2528a40b631dd4165484b9fce6b5c2708aae5c7 Mon Sep 17 00:00:00 2001
From: heyuntao <heyuntao@LAPTOP-MP4HD5NS>
Date: 星期六, 07 十月 2023 10:49:30 +0800
Subject: [PATCH] no message

---
 public/assets/js/addons.js |  438 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 281 insertions(+), 157 deletions(-)

diff --git a/public/assets/js/addons.js b/public/assets/js/addons.js
index 291d404..67a272f 100644
--- a/public/assets/js/addons.js
+++ b/public/assets/js/addons.js
@@ -1,5 +1,285 @@
 define([], function () {
-    require.config({
+    if (typeof Config.upload.storage !== 'undefined' && Config.upload.storage === 'hwobs') {
+    require(['upload'], function (Upload) {
+        //鑾峰彇鏂囦欢MD5鍊�
+        var getFileMd5 = function (file, cb) {
+            //濡傛灉savekey涓湭妫�娴嬪埌md5锛屽垯鏃犻渶鑾峰彇鏂囦欢md5锛岀洿鎺ヨ繑鍥瀠pload鐨剈uid
+            if (!Config.upload.savekey.match(/\{(file)?md5\}/)) {
+                cb && cb(file.upload.uuid);
+                return;
+            }
+            require(['../addons/hwobs/js/spark'], function (SparkMD5) {
+                var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
+                    chunkSize = 10 * 1024 * 1024,
+                    chunks = Math.ceil(file.size / chunkSize),
+                    currentChunk = 0,
+                    spark = new SparkMD5.ArrayBuffer(),
+                    fileReader = new FileReader();
+
+                fileReader.onload = function (e) {
+                    spark.append(e.target.result);
+                    currentChunk++;
+                    if (currentChunk < chunks) {
+                        loadNext();
+                    } else {
+                        cb && cb(spark.end());
+                    }
+                };
+
+                fileReader.onerror = function () {
+                    console.warn('鏂囦欢璇诲彇閿欒');
+                };
+
+                function loadNext() {
+                    var start = currentChunk * chunkSize,
+                        end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
+
+                    fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
+                }
+
+                loadNext();
+            });
+        };
+
+        var _onInit = Upload.events.onInit;
+        //鍒濆鍖栦腑瀹屾垚鍒ゆ柇
+        Upload.events.onInit = function () {
+            _onInit.apply(this, Array.prototype.slice.apply(arguments));
+            //濡傛灉涓婁紶鎺ュ彛涓嶆槸hwobs锛屽垯涓嶅鐞�
+            if (this.options.url !== Config.upload.uploadurl) {
+                return;
+            }
+            $.extend(this.options, {
+                //鍏抽棴鑷姩澶勭悊闃熷垪鍔熻兘
+                autoQueue: false,
+                params: function (files, xhr, chunk) {
+                    var params = $.extend({}, Config.upload.multipart);
+                    if (chunk) {
+                        return $.extend({}, params, {
+                            filesize: chunk.file.size,
+                            filename: chunk.file.name,
+                            chunkid: chunk.file.upload.uuid,
+                            chunkindex: chunk.index,
+                            chunkcount: chunk.file.upload.totalChunkCount,
+                            chunkfilesize: chunk.dataBlock.data.size,
+                            chunksize: this.options.chunkSize,
+                            width: chunk.file.width || 0,
+                            height: chunk.file.height || 0,
+                            type: chunk.file.type,
+                            uploadId: chunk.file.uploadId,
+                            key: chunk.file.key,
+                        });
+                    }
+                    return params;
+                },
+                chunkSuccess: function (chunk, file, response) {
+                    var etag = chunk.xhr.getResponseHeader("ETag").replace(/(^")|("$)/g, '');
+                    this.etags = this.etags ? this.etags : [];
+                    this.etags[chunk.index] = etag;
+                },
+                chunksUploaded: function (file, done) {
+                    var that = this;
+
+                    Fast.api.ajax({
+                        url: "/addons/hwobs/index/upload",
+                        data: {
+                            action: 'merge',
+                            filesize: file.size,
+                            filename: file.name,
+                            chunkid: file.upload.uuid,
+                            chunkcount: file.upload.totalChunkCount,
+                            md5: file.md5,
+                            key: file.key,
+                            uploadId: file.uploadId,
+                            etags: this.etags,
+                            category: file.category || '',
+                            hwobstoken: Config.upload.multipart.hwobstoken,
+                        },
+                    }, function (data, ret) {
+                        done(JSON.stringify(ret));
+                        return false;
+                    }, function (data, ret) {
+                        file.accepted = false;
+                        that._errorProcessing([file], ret.msg);
+                        return false;
+                    });
+
+                },
+            });
+
+            var _success = this.options.success;
+            //鍏堢Щ闄ゅ凡鏈夌殑浜嬩欢
+            this.off("success", _success).on("success", function (file, response) {
+                var ret = {code: 0, msg: response};
+                try {
+                    if (response) {
+                        ret = typeof response === 'string' ? JSON.parse(response) : response;
+                    }
+                    if (file.xhr.status === 200 || file.xhr.status === 204) {
+
+                        if (Config.upload.uploadmode === 'client') {
+                            ret = {code: 1, data: {url: '/' + file.key}};
+                        }
+
+                        if (ret.code == 1) {
+                            var url = ret.data.url || '';
+                            Fast.api.ajax({
+                                url: "/addons/hwobs/index/notify",
+                                data: {name: file.name, url: url, md5: file.md5, size: file.size, width: file.width || 0, height: file.height || 0, type: file.type, category: file.category || '', hwobstoken: Config.upload.multipart.hwobstoken}
+                            }, function () {
+                                return false;
+                            }, function () {
+                                return false;
+                            });
+                        } else {
+                            console.error(ret);
+                        }
+                    } else {
+                        console.error(file.xhr);
+                    }
+                } catch (e) {
+                    console.error(e);
+                }
+                _success.call(this, file, ret);
+            });
+
+            this.on("addedfile", function (file) {
+                var that = this;
+                setTimeout(function () {
+                    if (file.status === 'error') {
+                        return;
+                    }
+                    getFileMd5(file, function (md5) {
+                        var chunk = that.options.chunking && file.size > that.options.chunkSize ? 1 : 0;
+                        var params = $(that.element).data("params") || {};
+                        var category = typeof params.category !== 'undefined' ? params.category : ($(that.element).data("category") || '');
+                        category = typeof category === 'function' ? category.call(that, file) : category;
+                        Fast.api.ajax({
+                            url: "/addons/hwobs/index/params",
+                            data: {method: 'POST', category: category, md5: md5, name: file.name, type: file.type, size: file.size, chunk: chunk, chunksize: that.options.chunkSize, hwobstoken: Config.upload.multipart.hwobstoken},
+                        }, function (data) {
+                            file.md5 = md5;
+                            file.id = data.id;
+                            file.key = data.key;
+                            file.date = data.date;
+                            file.uploadId = data.uploadId;
+                            file.policy = data.policy;
+                            file.signature = data.signature;
+                            file.partsAuthorization = data.partsAuthorization;
+                            file.headers = data.headers;
+                            delete data.headers;
+                            file.params = data;
+                            file.category = category;
+
+                            if (file.status != 'error') {
+                                //寮�濮嬩笂浼�
+                                that.enqueueFile(file);
+                            } else {
+                                that.removeFile(file);
+                            }
+                            return false;
+                        }, function () {
+                            that.removeFile(file);
+                        });
+                    });
+                }, 0);
+            });
+
+            if (Config.upload.uploadmode === 'client') {
+                var _method = this.options.method;
+                var _url = this.options.url;
+                this.options.method = function (files) {
+                    if (files[0].upload.chunked) {
+                        var chunk = null;
+                        files[0].upload.chunks.forEach(function (item) {
+                            if (item.status === 'uploading') {
+                                chunk = item;
+                            }
+                        });
+                        if (!chunk) {
+                            return "POST";
+                        } else {
+                            return "PUT";
+                        }
+                    } else {
+                        return "POST";
+                    }
+                    return _method;
+                };
+                this.options.url = function (files) {
+                    if (files[0].upload.chunked) {
+                        var chunk = null;
+                        files[0].upload.chunks.forEach(function (item) {
+                            if (item.status === 'uploading') {
+                                chunk = item;
+                            }
+                        });
+                        var index = chunk.dataBlock.chunkIndex;
+                        this.options.headers = {"Authorization": files[0]['partsAuthorization'][index], "x-amz-date": files[0]['date']};
+                        if (!chunk) {
+                            return Config.upload.uploadurl + "/" + files[0].key + "?uploadId=" + files[0].uploadId;
+                        } else {
+                            return Config.upload.uploadurl + "/" + files[0].key + "?partNumber=" + (index + 1) + "&uploadId=" + files[0].uploadId;
+                        }
+                    }
+                    return _url;
+                };
+                this.options.params = function (files, xhr, chunk) {
+                    var params = Config.upload.multipart;
+                    delete params.category;
+                    if (chunk) {
+                        return $.extend({}, params, {
+                            filesize: chunk.file.size,
+                            filename: chunk.file.name,
+                            chunkid: chunk.file.upload.uuid,
+                            chunkindex: chunk.index,
+                            chunkcount: chunk.file.upload.totalChunkCount,
+                            chunkfilesize: chunk.dataBlock.data.size,
+                            width: chunk.file.width || 0,
+                            height: chunk.file.height || 0,
+                            type: chunk.file.type,
+                        });
+                    } else {
+                        var retParams = $.extend({}, params, files[0].params || {});
+                        delete retParams.hwobstoken;
+                        delete retParams.date;
+                        delete retParams.md5;
+                        if (Config.upload.uploadmode !== 'client') {
+                            params.category = files[0].category || '';
+                        }
+                        return retParams;
+                    }
+                };
+                this.on("sending", function (file, xhr, formData) {
+                    var that = this;
+                    var _send = xhr.send;
+                    //浠呭厑璁搁儴鍒嗗瓧娈�
+                    var allowFields = ['partNumber', 'uploadId', 'key', 'AccessKeyId', 'policy', 'signature', 'file'];
+                    formData.forEach(function (value, key) {
+                        if (allowFields.indexOf(key) < 0) {
+                            formData.delete(key);
+                        }
+                    });
+                    if (file.upload.chunked) {
+                        xhr.send = function () {
+                            if (file.upload.chunked) {
+                                var chunk = null;
+                                file.upload.chunks.forEach(function (item) {
+                                    if (item.status == 'uploading') {
+                                        chunk = item;
+                                    }
+                                });
+                                _send.call(xhr, chunk.dataBlock.data);
+                            }
+                        };
+                    }
+                });
+            }
+        };
+    });
+}
+
+require.config({
     paths: {
         'nkeditor': '../addons/nkeditor/js/customplugin',
         'nkeditor-core': '../addons/nkeditor/nkeditor',
@@ -180,162 +460,6 @@
             });
         }
     }
-});
-
-//淇敼涓婁紶鐨勬帴鍙h皟鐢�
-require(['upload'], function (Upload) {
-
-    var _onInit = Upload.events.onInit;
-    //鍒濆鍖栦腑瀹屾垚鍒ゆ柇
-    Upload.events.onInit = function () {
-        _onInit.apply(this, Array.prototype.slice.apply(arguments));
-        //濡傛灉涓婁紶鎺ュ彛涓嶆槸涓冪墰浜戯紝鍒欎笉澶勭悊
-        if (this.options.url !== Config.upload.uploadurl) {
-            return;
-        }
-        var _success = this.options.success;
-
-        $.extend(this.options, {
-            chunkSuccess: function (chunk, file, response) {
-                this.contexts = this.contexts ? this.contexts : [];
-                this.contexts.push(typeof response.ctx !== 'undefined' ? response.ctx : response.data.ctx);
-            },
-            chunksUploaded: function (file, done) {
-                var that = this;
-                var params = $(that.element).data("params") || {};
-                var category = typeof params.category !== 'undefined' ? params.category : ($(that.element).data("category") || '');
-                category = typeof category === 'function' ? category.call(this, file) : category;
-                Fast.api.ajax({
-                    url: "/addons/qiniu/index/upload",
-                    data: {
-                        action: 'merge',
-                        filesize: file.size,
-                        filename: file.name,
-                        chunkid: file.upload.uuid,
-                        chunkcount: file.upload.totalChunkCount,
-                        width: file.width || 0,
-                        height: file.height || 0,
-                        type: file.type,
-                        category: category,
-                        qiniutoken: Config.upload.multipart.qiniutoken,
-                        contexts: this.contexts
-                    },
-                }, function (data, ret) {
-                    done(JSON.stringify(ret));
-                    return false;
-                }, function (data, ret) {
-                    file.accepted = false;
-                    that._errorProcessing([file], ret.msg);
-                    return false;
-                });
-
-            },
-        });
-
-        //鍏堢Щ闄ゅ凡鏈夌殑浜嬩欢
-        this.off("success", _success).on("success", function (file, response) {
-            var that = this;
-            var ret = {code: 0, msg: response};
-            try {
-                ret = typeof response === 'string' ? JSON.parse(response) : response;
-                if (file.xhr.status === 200) {
-                    if (Config.upload.uploadmode === 'client') {
-                        if (typeof ret.key !== 'undefined') {
-                            ret = {code: 1, msg: "", data: {url: '/' + ret.key, hash: ret.hash}};
-                        }
-                    }
-
-                    if (ret.code == 1) {
-                        var url = ret.data.url || '';
-                        var params = $(that.element).data("params") || {};
-                        var category = typeof params.category !== 'undefined' ? params.category : ($(that.element).data("category") || '');
-                        category = typeof category === 'function' ? category.call(that, file) : category;
-                        Fast.api.ajax({
-                            url: "/addons/qiniu/index/notify",
-                            data: {name: file.name, url: ret.data.url, hash: ret.data.hash, size: file.size, width: file.width || 0, height: file.height || 0, type: file.type, category: category, qiniutoken: Config.upload.multipart.qiniutoken}
-                        }, function () {
-                            return false;
-                        }, function () {
-                            return false;
-                        });
-                    } else {
-                        console.error(ret);
-                    }
-                } else {
-                    console.error(file.xhr);
-                }
-            } catch (e) {
-                console.error(e);
-            }
-            _success.call(this, file, ret);
-        });
-
-        //濡傛灉鏄洿浼犳ā寮�
-        if (Config.upload.uploadmode === 'client') {
-            var _url = this.options.url;
-
-            //鍒嗙墖涓婁紶鏃禪RL閾炬帴涓嶅悓
-            this.options.url = function (files) {
-                this.options.headers = {"Authorization": "UpToken " + Config.upload.multipart.qiniutoken};
-                if (files[0].upload.chunked) {
-                    var chunk = null;
-                    files[0].upload.chunks.forEach(function (item) {
-                        if (item.status === 'uploading') {
-                            chunk = item;
-                        }
-                    });
-                    if (!chunk) {
-                        return Config.upload.uploadurl + '/mkfile/' + files[0].size;
-                    } else {
-                        return Config.upload.uploadurl + '/mkblk/' + chunk.dataBlock.data.size;
-                    }
-                }
-                return _url;
-            };
-
-            this.options.params = function (files, xhr, chunk) {
-                var params = Config.upload.multipart;
-                if (chunk) {
-                    return $.extend({}, params, {
-                        filesize: chunk.file.size,
-                        filename: chunk.file.name,
-                        chunkid: chunk.file.upload.uuid,
-                        chunkindex: chunk.index,
-                        chunkcount: chunk.file.upload.totalChunkCount,
-                        chunkfilesize: chunk.dataBlock.data.size,
-                        width: chunk.file.width || 0,
-                        height: chunk.file.height || 0,
-                        type: chunk.file.type,
-                    });
-                } else {
-                    var retParams = $.extend({}, params);
-                    //涓冪墰浜戠洿浼犱娇鐢ㄧ殑鏄痶oken鍙傛暟
-                    retParams.token = retParams.qiniutoken;
-                    delete retParams.qiniutoken;
-                    return retParams;
-                }
-            };
-
-            //鍒嗙墖涓婁紶鏃堕渶瑕佸彉鏇存彁浜ょ殑鍐呭
-            this.on("sending", function (file, xhr, formData) {
-                if (file.upload.chunked) {
-                    var _send = xhr.send;
-                    xhr.send = function () {
-                        var chunk = null;
-                        file.upload.chunks.forEach(function (item) {
-                            if (item.status == 'uploading') {
-                                chunk = item;
-                            }
-                        });
-                        if (chunk) {
-                            _send.call(xhr, chunk.dataBlock.data);
-                        }
-                    };
-                }
-            });
-        }
-    };
-
 });
 
 });
\ No newline at end of file

--
Gitblit v1.9.3