Discuz 拦截修改上传附件/图片

目标是通过js代码创建出一张图片,上传。不需要人手动点击和选择。

 

 

/misc.php?mod=swfupload&action=swfupload&operation=upload&fid=123

通过这个接口上传 POST

fid就是帖子的id,href url里边有

Content-Type:
multipart/form-data; boundary=----WebKitFormBoundary......
 
传参是form data
 
uid:
61868 这个没找着怎么来的
hash:
693604c2fea703f29cd1cdca7b39d8be 这个也没
id:
WU_FILE_0
type:
image/jpeg
size:
347535
filetype:
jpg
Filedata:
(binary)
 
返回一个aid 4xxxxx
form data里边的几个参数,我看着应该是在/source/plugin/boan_h5upload/js/webuploader.min.js 这个文件里弄出来的,但是我暂时没空细看这个逻辑了
 
大致就是一个input type="file"的change事件开始,然后后边一系列处理。用了jQuery
 
addFile _addFile fileQueued _prepareNextFile _startSend 最终用xhr的send
 
目前我的想法是模拟一个change事件,不研究后续的参数处理了
 
BoanH5upload.prototype.fileQueued = function(prefix, file, Obj) {
    var upObj = prefix ? imgUpload : upload;
    if (upObj.customSettings.uploadSource == 'forum' && prefix == 'poll') {
        var preObj = $(Obj.progressTarget);
        preObj.style.display = 'none';
        preObj.innerHTML = '';
        return;
    }
    var progress = new FileProgress(file,upObj.customSettings.progressTarget);
    progress.setStatus(boan_h5upload_lang['wait_up']);
    progress.toggleCancel = function(show, swfUploadInstance) {
        this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
        if (swfUploadInstance) {
            var fileID = this.fileProgressID;
            that = this;
            this.fileProgressElement.childNodes[0].onclick = function() {
                swfUploadInstance.removeFile(fileID);
                that.setCancelled();
                return false;
            }
            ;
        }
    }
    ;
    progress.toggleCancel(true, Obj);
    if (upObj.customSettings.uploadType == 'attach') {
        try {
            $('attach_tblheader').style.display = '';
            $('attach_notice').style.display = '';
        } catch (ex) {}
    } else if (upObj.customSettings.uploadType == 'image') {
        try {
            $('imgattach_notice').style.display = '';
        } catch (ex) {}
    }
    var objId = upObj.customSettings.uploadType == 'attach' ? 'attachlist' : 'imgattachlist';
    var listObj = $(objId);
    var tableObj = listObj.getElementsByTagName("table");
    if (!tableObj.length) {
        listObj.innerHTML = "";
    }
    var rFilter = /^(image\/jpeg|image\/png|image\/jpg|image\/gif|image\/jpe)$/i;
    if ((rFilter.test(file.type) && file.source.source !== undefined) && !(($(editorid + '_image_menu').style.display == 'none' || $(editorid + '_image_menu').style.visibility == 'hidden')) && file.name != 'image.png') {
        new Boan_EXIF(Obj,file);
    } else {
        Obj.upload(file);
    }
}
 
 
 
 
 
            beforeSendFile: function(b) {
                var d, f, g = this.options.compress || this.options.resize, h = g && g.compressSize || 0, i = g && g.noCompressIfLarger || !1;
                return b = this.request("get-file", b),
                !g || !~"image/jpeg,image/jpg".indexOf(b.type) || b.size < h || b._compressed ? void 0 : (g = e.extend({}, g),
                f = a.Deferred(),
                d = new c(g),
                f.always(function() {
                    d.destroy(),
                    d = null
                }),
                d.once("error", f.reject),
                d.once("load", function() {
                    var a = g.width
                      , c = g.height;
                    b._info = b._info || d.info(),
                    b._meta = b._meta || d.meta(),
                    1 >= a && a > 0 && (a = b._info.width * a),
                    1 >= c && c > 0 && (c = b._info.height * c),
                    d.resize(a, c)
                }),
                d.once("complete", function() {
                    var a, c;
                    try {
                        a = d.getAsBlob(g.type),
                        c = b.size,
                        (!i || a.size < c) && (b.source = a,
                        b.size = a.size,
                        b.trigger("resize", a.size, c)),
                        b._compressed = !0,
                        f.resolve()
                    } catch (e) {
                        f.resolve()
                    }
                }),
                b._info && d.info(b._info),
                b._meta && d.meta(b._meta),
                d.loadFromBlob(b.source),
                f.promise())
            }
 
 
 
posted @ 2024-07-18 13:39  hrdom  阅读(1)  评论(0编辑  收藏  举报