Skip to content

Commit 25c97b9

Browse files
authored
Merge pull request #59 from JJ-8/0-add-discord-integration-downstream
Subtask export: cyclic references and uploads exclusion
2 parents a7b1d39 + 1b0e922 commit 25c97b9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

front/src/components/Dialogs/TaskExportDialog.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ export default defineComponent({
7676
this.onDialogCancel();
7777
},
7878
79-
async downloadTaskMarkdown(task: Task) {
79+
async downloadTaskMarkdown(task: Task, visitedUrls: string[] = []) {
8080
const result = await fetch(task.padUrl + '/download/markdown');
81+
if (result.status != 200) {
82+
return `Error fetching markdown for exporting task ${task.title}`;
83+
}
8184
let markdown = await result.text();
8285
if (markdown.trimStart().substring(0, 1) != '#') {
8386
//does not start with a title, manually adding...
@@ -87,22 +90,28 @@ export default defineComponent({
8790
}
8891
markdown = withTitle + '\n' + markdown;
8992
}
93+
visitedUrls.push(task.padUrl);
9094
9195
// fetch subtasks recursively
9296
const subTasks = [
9397
...markdown.matchAll(
9498
new RegExp(
95-
`(https?://${window.location.host}(/pad/[a-zA-Z0-9_-]*))`,
99+
`(https?://${window.location.host}(/pad/(?!uploads)[a-zA-Z0-9_-]*))`,
96100
'g'
97101
)
98102
),
99103
];
100104
101105
for (const subTask of subTasks) {
102-
const subTaskMarkdown = await this.downloadTaskMarkdown({
103-
...task,
104-
padUrl: subTask[1],
105-
});
106+
if (visitedUrls.includes(subTask[1])) continue;
107+
108+
const subTaskMarkdown = await this.downloadTaskMarkdown(
109+
{
110+
...task,
111+
padUrl: subTask[1],
112+
},
113+
visitedUrls.concat([subTask[1]])
114+
);
106115
107116
markdown += `\n\n---\nContent of ${subTask[0]}\n\n${subTaskMarkdown}`;
108117
}

0 commit comments

Comments
 (0)