Skip to content

Commit 5b2b7d0

Browse files
Fix also remove file extension in web
1 parent 5b4f182 commit 5b2b7d0

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

frontend/src/state-providers/portfolio.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,17 @@ export function createPortfolioState(editor: Editor) {
4646
return state;
4747
});
4848
});
49-
editor.subscriptions.subscribeJsMessage(TriggerFetchAndOpenDocument, async (triggerFetchAndOpenDocument) => {
50-
try {
51-
const { name, filename } = triggerFetchAndOpenDocument;
52-
const url = new URL(filename, document.location.href);
53-
const data = await fetch(url);
54-
const content = await data.text();
49+
editor.subscriptions.subscribeJsMessage(TriggerOpenDocument, async () => {
50+
const suffix = "." + editor.handle.fileExtension();
51+
const data = await upload(suffix, "text");
5552

56-
editor.handle.openDocumentFile(name, content);
57-
} catch {
58-
// Needs to be delayed until the end of the current call stack so the existing demo artwork dialog can be closed first, otherwise this dialog won't show
59-
setTimeout(() => {
60-
editor.handle.errorDialog("Failed to open document", "The file could not be reached over the internet. You may be offline, or it may be missing.");
61-
}, 0);
53+
// Use filename as document name, removing the extension if it exists
54+
var document_name = data.filename;
55+
if (document_name.endsWith(suffix)) {
56+
document_name = document_name.slice(0, -suffix.length);
6257
}
63-
});
64-
editor.subscriptions.subscribeJsMessage(TriggerOpenDocument, async () => {
65-
const extension = editor.handle.fileExtension();
66-
const data = await upload("." + extension, "text");
67-
editor.handle.openDocumentFile(data.filename, data.content);
58+
59+
editor.handle.openDocumentFile(document_name, data.content);
6860
});
6961
editor.subscriptions.subscribeJsMessage(TriggerImport, async () => {
7062
const data = await upload("image/*", "both");

0 commit comments

Comments
 (0)