From 3c07e2932244581a2d355196d9c4b6058b7fabc5 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Mon, 17 Jul 2023 14:56:17 +0200 Subject: [PATCH 1/2] Handle cyclic referencing of subtask exporting --- .../components/Dialogs/TaskExportDialog.vue | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/front/src/components/Dialogs/TaskExportDialog.vue b/front/src/components/Dialogs/TaskExportDialog.vue index 558ae4666..765afc5e6 100644 --- a/front/src/components/Dialogs/TaskExportDialog.vue +++ b/front/src/components/Dialogs/TaskExportDialog.vue @@ -76,8 +76,11 @@ export default defineComponent({ this.onDialogCancel(); }, - async downloadTaskMarkdown(task: Task) { + async downloadTaskMarkdown(task: Task, visitedUrls: string[] = []) { const result = await fetch(task.padUrl + '/download/markdown'); + if (result.status != 200) { + return `Error fetching markdown for exporting task ${task.title}`; + } let markdown = await result.text(); if (markdown.trimStart().substring(0, 1) != '#') { //does not start with a title, manually adding... @@ -87,6 +90,7 @@ export default defineComponent({ } markdown = withTitle + '\n' + markdown; } + visitedUrls.push(task.padUrl); // fetch subtasks recursively const subTasks = [ @@ -99,10 +103,15 @@ export default defineComponent({ ]; for (const subTask of subTasks) { - const subTaskMarkdown = await this.downloadTaskMarkdown({ - ...task, - padUrl: subTask[1], - }); + if (visitedUrls.includes(subTask[1])) continue; + + const subTaskMarkdown = await this.downloadTaskMarkdown( + { + ...task, + padUrl: subTask[1], + }, + visitedUrls.concat([subTask[1]]) + ); markdown += `\n\n---\nContent of ${subTask[0]}\n\n${subTaskMarkdown}`; } From 1b0e9220125156b3459aa788c9825bcf2e716647 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Mon, 17 Jul 2023 14:57:00 +0200 Subject: [PATCH 2/2] Exclude image upload from subtask discovery Otherwise this will result in errors. --- front/src/components/Dialogs/TaskExportDialog.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/components/Dialogs/TaskExportDialog.vue b/front/src/components/Dialogs/TaskExportDialog.vue index 765afc5e6..7fefcfaad 100644 --- a/front/src/components/Dialogs/TaskExportDialog.vue +++ b/front/src/components/Dialogs/TaskExportDialog.vue @@ -96,7 +96,7 @@ export default defineComponent({ const subTasks = [ ...markdown.matchAll( new RegExp( - `(https?://${window.location.host}(/pad/[a-zA-Z0-9_-]*))`, + `(https?://${window.location.host}(/pad/(?!uploads)[a-zA-Z0-9_-]*))`, 'g' ) ),