Skip to content

Commit e3dbf4e

Browse files
author
Al Manning
committed
Bug: Same-named attachments not resolving correctly for nested pages.
1 parent c15d020 commit e3dbf4e

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ export const getAttachmentsDirectory = (
636636
filePath: string = "",
637637
attachmentPath: string = ""
638638
): string => {
639+
console.log("baseDirectory", baseDirectory);
640+
console.log("filePath", filePath);
641+
console.log("attachmentPath", attachmentPath);
642+
639643
let result = baseDirectory;
640644

641645
if (attachmentPath.length === 0 || filePath.length === 0) {
@@ -657,7 +661,7 @@ export const getAttachmentsDirectory = (
657661
}
658662

659663
const isRelative = attachmentPathList.length === 1;
660-
664+
console.log("isRelative", isRelative);
661665
if (isRelative && filePathList.length > 1) {
662666
const directoryPath = pathNoFileFromList(filePathList);
663667
result = `${result}/${directoryPath}`;

src/publish/confluence/confluence.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ async function publish(
296296
attachmentPath
297297
);
298298

299+
console.log("uploadDirectory", uploadDirectory);
300+
299301
trace(
300302
"uploadAttachment",
301303
{
@@ -356,11 +358,22 @@ async function publish(
356358
): Promise<Content> => {
357359
const previousPage = await client.getContent(id);
358360

361+
console.log("updateContent");
362+
console.log("titleToUpdate", titleToUpdate);
363+
console.log("body.storage.value", body.storage.value);
364+
console.log("publishFiles.files", publishFiles.files);
365+
console.log("fileName", fileName);
366+
359367
const attachmentsToUpload: string[] = findAttachments(
360368
body.storage.value,
361-
publishFiles.files
369+
publishFiles.files,
370+
fileName
362371
);
363372

373+
console.log("attachmentsToUpload", attachmentsToUpload);
374+
375+
//FIXME expected elephant.png
376+
364377
const uniqueTitle = await uniquifyTitle(titleToUpdate, id);
365378

366379
trace("attachmentsToUpload", attachmentsToUpload, LogPrefix.ATTACHMENT);
@@ -392,6 +405,8 @@ async function publish(
392405
LogPrefix.ATTACHMENT
393406
);
394407

408+
console.log("attachmentsToUpload", attachmentsToUpload);
409+
395410
const uploadAttachmentsResult = await Promise.all(
396411
uploadAttachments(
397412
publishFiles.baseDir,

tests/unit/confluence.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,6 +2975,18 @@ const runFindAttachments = () => {
29752975
check(expected, bodyValue, filePaths);
29762976
});
29772977

2978+
test(suiteLabel("single_image_lookup_relative_path"), async () => {
2979+
const bodyValue: string =
2980+
'<ri:attachment ri:filename="elephant.png" ri:version-at-save="1" />';
2981+
const filePaths: string[] = [
2982+
"images/elephant.png",
2983+
"parent/inner-parent/elephant.png",
2984+
];
2985+
const path = "parent/inner-parent/hello-world3.xml";
2986+
const expected: string[] = ["parent/inner-parent/elephant.png"];
2987+
check(expected, bodyValue, filePaths, path);
2988+
});
2989+
29782990
test(suiteLabel("single_image_lookup_dupe_name"), async () => {
29792991
const bodyValue: string =
29802992
'<ri:attachment ri:filename="elephant.png" ri:version-at-save="1" />';
@@ -3138,6 +3150,12 @@ const runGetAttachmentsDirectory = () => {
31383150

31393151
check(expected, baseDirectory, attachmentPath, fileName);
31403152
});
3153+
3154+
//TODO test
3155+
// [
3156+
// "images/elephant.png",
3157+
// "parent/inner-parent/elephant.png",
3158+
// ];
31413159
};
31423160

31433161
const runUpdateImagePathsForContentBody = () => {
@@ -3208,5 +3226,5 @@ if (RUN_ALL_TESTS) {
32083226
runGetAttachmentsDirectory();
32093227
runUpdateImagePathsForContentBody();
32103228
} else {
3211-
runUpdateLinks();
3229+
runFindAttachments();
32123230
}

0 commit comments

Comments
 (0)