This commit is contained in:
Philipinho
2025-06-08 20:26:24 -07:00
parent 7d7eaf07d6
commit 5ebf5c6319
3 changed files with 46 additions and 12 deletions

View File

@ -96,7 +96,8 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
notifications.show({
id: "import",
message: t("Uploading import file"),
title: t("Uploading import file"),
message: t("Please don't close this tab."),
loading: true,
withCloseButton: false,
autoClose: false,
@ -106,14 +107,15 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
notifications.update({
id: "import",
title: t("Importing pages"),
message: t("Page import is in progress."),
message: t(
"Page import is in progress. You can check back later if this takes longer.",
),
loading: true,
withCloseButton: false,
withCloseButton: true,
autoClose: false,
});
setFileTaskId(importTask.id);
onClose();
} catch (err) {
console.log("Failed to upload import file", err);
notifications.update({
@ -124,7 +126,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
icon: <IconX size={18} />,
loading: false,
withCloseButton: true,
autoClose: 5000,
autoClose: false,
});
}
};
@ -146,7 +148,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
icon: <IconCheck size={18} />,
loading: false,
withCloseButton: true,
autoClose: 5000,
autoClose: false,
});
clearInterval(intervalId);
setFileTaskId(null);
@ -177,7 +179,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
icon: <IconX size={18} />,
loading: false,
withCloseButton: true,
autoClose: 5000,
autoClose: false,
});
clearInterval(intervalId);
setFileTaskId(null);
@ -197,7 +199,7 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
icon: <IconX size={18} />,
loading: false,
withCloseButton: true,
autoClose: 5000,
autoClose: false,
});
clearInterval(intervalId);
setFileTaskId(null);

View File

@ -130,7 +130,7 @@ export class PersistenceExtension implements Extension {
);
this.contributors.delete(documentName);
} catch (err) {
this.logger.debug('Contributors error:' + err?.['message']);
//this.logger.debug('Contributors error:' + err?.['message']);
}
await this.pageRepo.updatePage(

View File

@ -43,7 +43,23 @@ export class ImportAttachmentService {
const attachmentTasks: Promise<void>[] = [];
const processFile = (relPath: string) => {
/**
* Cache keyed by the *relative* path that appears in the HTML.
* Ensures we upload (and DB-insert) each attachment at most once,
* even if its referenced multiple times on the page.
*/
const processed = new Map<
string,
{
attachmentId: string;
storageFilePath: string;
apiFilePath: string;
fileNameWithExt: string;
abs: string;
}
>();
const uploadOnce = (relPath: string) => {
const abs = attachmentCandidates.get(relPath)!;
const attachmentId = v7();
const ext = path.extname(abs);
@ -51,7 +67,10 @@ export class ImportAttachmentService {
const fileNameWithExt =
sanitizeFileName(path.basename(abs, ext)) + ext.toLowerCase();
const storageFilePath = `${getAttachmentFolderPath(AttachmentType.File, fileTask.workspaceId)}/${attachmentId}/${fileNameWithExt}`;
const storageFilePath = `${getAttachmentFolderPath(
AttachmentType.File,
fileTask.workspaceId,
)}/${attachmentId}/${fileNameWithExt}`;
const apiFilePath = `/api/files/${attachmentId}/${fileNameWithExt}`;
@ -89,6 +108,19 @@ export class ImportAttachmentService {
};
};
/**
* Returns cached data if weve already processed this path.
* Otherwise calls `uploadOnce`, stores the result, and returns it.
*/
const processFile = (relPath: string) => {
const cached = processed.get(relPath);
if (cached) return cached;
const fresh = uploadOnce(relPath);
processed.set(relPath, fresh);
return fresh;
};
const pageDir = path.dirname(pageRelativePath);
const $ = load(html);
@ -150,6 +182,7 @@ export class ImportAttachmentService {
unwrapFromParagraph($, $vid);
}
// <div data-type="attachment">
for (const el of $('div[data-type="attachment"]').toArray()) {
const $oldDiv = $(el);
const rawUrl = cleanUrlString($oldDiv.attr('data-attachment-url') ?? '')!;
@ -206,7 +239,6 @@ export class ImportAttachmentService {
$a.replaceWith($video);
unwrapFromParagraph($, $video);
} else {
// build attachment <div>
const confAliasName = $a.attr('data-linked-resource-default-alias');
let attachmentName = path.basename(abs);
if (confAliasName) attachmentName = confAliasName;