mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-03 19:30:16 +01:00
This commit is contained in:
parent
251e73b845
commit
338c359013
9 changed files with 183 additions and 153 deletions
|
|
@ -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
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue