Vanessa 2022-11-11 14:48:45 +08:00
parent 6a31ab85aa
commit 2cc66e21df
4 changed files with 28 additions and 24 deletions

View file

@ -17,6 +17,7 @@ import {updateListOrder} from "../wysiwyg/list";
import {escapeHtml} from "../../util/escape";
import {zoomOut} from "../../menus/protyle";
import {hideElements} from "../ui/hideElements";
import {genAssetHTML} from "../../asset/renderAssets";
export const hintSlash = (key: string, protyle: IProtyle) => {
const allList: IHintData[] = [{
@ -428,17 +429,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => {
focusByRange(protyle.toolbar.range);
const type = pathPosix().extname(value).toLowerCase();
const filename = value.startsWith("assets/") ? getAssetName(value) : value;
let fileMD = "";
if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) {
fileMD += `<audio controls="controls" src="${value}"></audio>`;
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
fileMD += `![${filename}](${value})`;
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) {
fileMD += `<video controls="controls" src="${value}"></video>`;
} else {
fileMD += `[${value.startsWith("assets/") ? filename + type : value}](${value})`;
}
insertHTML(protyle.lute.SpinBlockDOM(fileMD), protyle);
insertHTML(genAssetHTML(type, value, filename, value.startsWith("assets/") ? filename + type : value), protyle);
hideElements(["util"], protyle);
};

View file

@ -5,6 +5,7 @@ import {destroy} from "../util/destroy";
import {fetchPost} from "../../util/fetch";
import {getEditorRange} from "../util/selection";
import {pathPosix} from "../../util/pathName";
import {genAssetHTML} from "../../asset/renderAssets";
export class Upload {
public element: HTMLElement;
@ -102,16 +103,9 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
const path = response.data.succMap[key];
const type = pathPosix().extname(key).toLowerCase();
const filename = protyle.options.upload.filename(key);
if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) {
succFileText += `<audio controls="controls" src="${path}"></audio>`;
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
succFileText += `![${filename.substring(0, filename.length - type.length)}](${path})`;
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) {
succFileText += `<video controls="controls" src="${path}"></video>`;
} else {
succFileText += `[${filename}](${path})`;
}
if (keys.length - 1 !== index) {
succFileText += genAssetHTML(type, path, filename.substring(0, filename.length - type.length), filename)
if (!Constants.SIYUAN_ASSETS_AUDIO.includes(type) && !Constants.SIYUAN_ASSETS_VIDEO.includes(type) &&
keys.length - 1 !== index) {
succFileText += "\n";
}
});
@ -121,10 +115,10 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
range.setEndAfter(range.startContainer.parentElement);
range.collapse(false);
}
insertHTML(protyle.lute.SpinBlockDOM(succFileText), protyle);
insertHTML(succFileText, protyle);
};
export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload:boolean) => {
export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload: boolean) => {
const msgId = showMessage(window.siyuan.languages.uploading, 0);
fetchPost("/api/asset/insertLocalAssets", {
assetPaths: files,