This commit is contained in:
Vanessa 2022-07-16 11:14:21 +08:00
parent 7c4cff3790
commit 24eb93a752
4 changed files with 14 additions and 15 deletions

View file

@ -6,7 +6,7 @@ import {removeEmbed} from "../protyle/wysiwyg/removeEmbed";
import {insertHTML} from "../protyle/util/insertHTML";
import {genEmptyBlock} from "../block/util";
import {isMobile} from "../util/functions";
import {getDisplayName, pathPosix, setNotebookName} from "../util/pathName";
import {getAssetName, getDisplayName, pathPosix, setNotebookName} from "../util/pathName";
import {fetchPost} from "../util/fetch";
import {escapeHtml} from "../util/escape";
@ -100,7 +100,7 @@ export const renameAsset = (assetPath: string) => {
dialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
const oldName = assetPath.substring(7, assetPath.length - pathPosix().extname(assetPath).length - 23);
const oldName = getAssetName(assetPath);
inputElement.value = oldName;
inputElement.focus();
inputElement.select();

View file

@ -11,7 +11,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {getContenteditableElement, getTopAloneElement} from "../wysiwyg/getBlock";
import {replaceFileName} from "../../editor/rename";
import {transaction} from "../wysiwyg/transaction";
import {getDisplayName} from "../../util/pathName";
import {getAssetName, getDisplayName, pathPosix} from "../../util/pathName";
import {genEmptyElement} from "../../block/util";
import {updateListOrder} from "../wysiwyg/list";
import {escapeHtml} from "../../util/escape";
@ -425,8 +425,8 @@ export const hintRenderWidget = (value: string, protyle: IProtyle) => {
export const hintRenderAssets = (value: string, protyle: IProtyle) => {
focusByRange(protyle.toolbar.range);
const type = value.substring(value.lastIndexOf("."));
const filename = value.replace("assets/", "");
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>`;
@ -435,7 +435,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => {
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) {
fileMD += `<video controls="controls" src="${value}"></video>`;
} else {
fileMD += `[${filename}](${value})`;
fileMD += `[${value.startsWith("assets/") ? filename + type : value}](${value})`;
}
insertHTML(protyle.lute.SpinBlockDOM(fileMD), protyle);
protyle.toolbar.subElement.classList.add("fn__none");

View file

@ -4,6 +4,7 @@ import {Constants} from "../../constants";
import {destroy} from "../util/destroy";
import {fetchPost} from "../../util/fetch";
import {getEditorRange} from "../util/selection";
import {pathPosix} from "../../util/pathName";
export class Upload {
public element: HTMLElement;
@ -99,18 +100,12 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
const keys = Object.keys(response.data.succMap);
keys.forEach((key, index) => {
const path = response.data.succMap[key];
const lastIndex = key.lastIndexOf(".");
let type = key.substr(lastIndex);
let filename = protyle.options.upload.filename(key.substr(0, lastIndex)) + type;
if (-1 === lastIndex) {
type = "";
filename = protyle.options.upload.filename(key);
}
type = type.toLowerCase();
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}](${path})`;
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 {

View file

@ -28,6 +28,10 @@ export const getDisplayName = (filePath: string, basename = true, removeSY = fal
return name;
};
export const getAssetName = (assetPath: string) => {
return assetPath.substring(7, assetPath.length - pathPosix().extname(assetPath).length - 23)
}
export const isLocalPath = (link: string) => {
if (!link) {
return false;