Vanessa 2026-01-08 23:47:09 +08:00
parent 251e73b845
commit 338c359013
9 changed files with 183 additions and 153 deletions

View file

@ -22,6 +22,8 @@ import * as dayjs from "dayjs";
import {getColId} from "./col";
import {getFieldIdByCellElement} from "./row";
import {getCompressURL, removeCompressURL} from "../../../util/image";
import {confirmDialog} from "../../../dialog/confirmDialog";
import prettyBytes from "pretty-bytes";
export const bindAssetEvent = (options: {
protyle: IProtyle,
@ -420,40 +422,51 @@ ${window.siyuan.languages.title}
menu.element.querySelector("textarea").focus();
};
export const dragUpload = (files: string[], protyle: IProtyle, cellElement: HTMLElement) => {
const msgId = showMessage(window.siyuan.languages.uploading, 0);
fetchPost("/api/asset/insertLocalAssets", {
assetPaths: files,
isUpload: true,
id: protyle.block.rootID
}, (response) => {
const blockElement = hasClosestBlock(cellElement);
if (blockElement) {
hideMessage(msgId);
const addValue: IAVCellAssetValue[] = [];
Object.keys(response.data.succMap).forEach(key => {
const type = pathPosix().extname(key).toLowerCase();
const name = key.substring(0, key.length - type.length);
if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
addValue.push({
type: "image",
name,
content: response.data.succMap[key],
});
} else {
addValue.push({
type: "file",
name,
content: response.data.succMap[key],
});
}
});
updateAssetCell({
protyle,
blockElement,
cellElements: [cellElement],
addValue
});
export const dragUpload = (files: ILocalFiles[], protyle: IProtyle, cellElement: HTMLElement) => {
let msg = "";
const assetPaths: string[] = [];
files.forEach(item => {
if (item.size && Constants.SIZE_UPLOAD_TIP_SIZE <= item.size) {
msg += window.siyuan.languages.uploadFileTooLarge.replace("${x}", item.path).replace("${y}", prettyBytes(item.size, {binary: true})) + "<br>";
}
assetPaths.push(item.path);
});
confirmDialog(msg ? window.siyuan.languages.upload : "", msg, () => {
const msgId = showMessage(window.siyuan.languages.uploading, 0);
fetchPost("/api/asset/insertLocalAssets", {
assetPaths,
isUpload: true,
id: protyle.block.rootID
}, (response) => {
const blockElement = hasClosestBlock(cellElement);
if (blockElement) {
hideMessage(msgId);
const addValue: IAVCellAssetValue[] = [];
Object.keys(response.data.succMap).forEach(key => {
const type = pathPosix().extname(key).toLowerCase();
const name = key.substring(0, key.length - type.length);
if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
addValue.push({
type: "image",
name,
content: response.data.succMap[key],
});
} else {
addValue.push({
type: "file",
name,
content: response.data.succMap[key],
});
}
});
updateAssetCell({
protyle,
blockElement,
cellElements: [cellElement],
addValue
});
}
});
});
};

View file

@ -275,9 +275,12 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
const cellElement = element.querySelector(".custom-attr__avvalue--active") as HTMLElement;
if (cellElement) {
if (event.dataTransfer.types[0] === "Files" && !isBrowser()) {
const files: string[] = [];
const files: ILocalFiles[] = [];
for (let i = 0; i < event.dataTransfer.files.length; i++) {
files.push(webUtils.getPathForFile(event.dataTransfer.files[i]));
files.push({
path: webUtils.getPathForFile(event.dataTransfer.files[i]),
size: event.dataTransfer.files[i].size
});
}
dragUpload(files, protyle, cellElement);
}