feat: 直接粘贴视频上传功能

This commit is contained in:
zhanzhenping 2024-07-05 09:57:03 +08:00
parent f78b65424a
commit a7eccd2a83
6 changed files with 18 additions and 11 deletions

View File

@ -79,7 +79,7 @@ avatar=/static/images/headimgurl.jpg
token_size=12
#上传文件的后缀,如果不限制后缀可以设置为 *
upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif
upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif|mp4|webm|avi
#上传的文件大小限制
# - 如果不填写, 则默认1GB如果希望超过1GB必须带单位

View File

@ -488,7 +488,6 @@ func (c *DocumentController) Upload() {
}
names := []string{"editormd-file-file", "editormd-image-file", "file", "editormd-resource-file"}
currentName := ""
var files []*multipart.FileHeader
for _, name := range names {
file, err := c.GetFiles(name)
@ -496,7 +495,6 @@ func (c *DocumentController) Upload() {
continue
}
if len(file) > 0 && err == nil {
currentName = name
files = append(files, file...)
}
}
@ -667,8 +665,8 @@ func (c *DocumentController) Upload() {
}
result2 = append(result2, result)
}
if currentName == "file" {
// froala单图片上传
if len(files) == 1 {
// froala单文件上传
c.Ctx.Output.JSON(result, true, false)
} else {
c.Ctx.Output.JSON(result2, true, false)

View File

@ -476,6 +476,9 @@ function uploadResource($id, $callback) {
case "video/mp4":
fileName += ".mp4";
break;
case "video/webm":
fileName += ".webm";
break;
default :
layer.msg(locales[lang].unsupportType);
return;

View File

@ -251,14 +251,16 @@ $(function () {
shade: [0.1, '#fff'] // 0.1 透明度的白色背景
});
} else if ($state === "success") {
if ($res[0].errcode === 0) {
if ($res[0].resource_type === 'video') {
let value = `<video controls><source src="${$res[0].url}" type="video/mp4"></video>`;
if ($res.errcode === 0) {
if ($res.resource_type === 'video') {
let value = `<video controls><source src="${$res.url}" type="video/mp4"></video>`;
window.editor.insertValue(value);
} else {
let value = '![](' + $res[0].url + ')';
let value = '![](' + $res.url + ')';
window.editor.insertValue(value);
}
} else {
layer.msg("上传失败:" + $res.message);
}
}
});

View File

@ -263,7 +263,12 @@ func IsImageExt(filename string) bool {
func IsVideoExt(filename string) bool {
ext := filepath.Ext(filename)
return strings.EqualFold(ext, ".mp4")
return strings.EqualFold(ext, ".mp4") ||
strings.EqualFold(ext, ".webm") ||
strings.EqualFold(ext, ".ogg") ||
strings.EqualFold(ext, ".avi") ||
strings.EqualFold(ext, ".flv") ||
strings.EqualFold(ext, ".mov")
}
// 忽略字符串中的BOM头

View File

@ -508,7 +508,6 @@
}
}).on("uploadSuccess",function (file, res) {
for(var index in window.vueApp.lists){
var item = window.vueApp.lists[index];
if(item.attachment_id === file.id){