Skip to content

Commit 048aa47

Browse files
author
Al Manning
committed
Bug: Attachments with ./ relative to the current directly aren't working
1 parent e3dbf4e commit 048aa47

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,18 +636,19 @@ 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-
643639
let result = baseDirectory;
644640

645641
if (attachmentPath.length === 0 || filePath.length === 0) {
646642
return "";
647643
}
648644

649645
const filePathList = filePath.split("/");
650-
const attachmentPathList = attachmentPath.split("/");
646+
let attachmentPathList = attachmentPath.split("/");
647+
648+
//TODO navigate path with '..'
649+
if (attachmentPathList.length === 2 && attachmentPathList[0] === ".") {
650+
attachmentPathList = attachmentPathList.slice(1);
651+
}
651652

652653
const pathNoFileFromList = (pathList: string[]) =>
653654
pathList.slice(0, pathList.length - 1).join("/");
@@ -661,7 +662,7 @@ export const getAttachmentsDirectory = (
661662
}
662663

663664
const isRelative = attachmentPathList.length === 1;
664-
console.log("isRelative", isRelative);
665+
665666
if (isRelative && filePathList.length > 1) {
666667
const directoryPath = pathNoFileFromList(filePathList);
667668
result = `${result}/${directoryPath}`;

src/publish/confluence/confluence.ts

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

299-
console.log("uploadDirectory", uploadDirectory);
300-
301299
trace(
302300
"uploadAttachment",
303301
{
@@ -358,20 +356,12 @@ async function publish(
358356
): Promise<Content> => {
359357
const previousPage = await client.getContent(id);
360358

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-
367359
const attachmentsToUpload: string[] = findAttachments(
368360
body.storage.value,
369361
publishFiles.files,
370362
fileName
371363
);
372364

373-
console.log("attachmentsToUpload", attachmentsToUpload);
374-
375365
//FIXME expected elephant.png
376366

377367
const uniqueTitle = await uniquifyTitle(titleToUpdate, id);
@@ -405,8 +395,6 @@ async function publish(
405395
LogPrefix.ATTACHMENT
406396
);
407397

408-
console.log("attachmentsToUpload", attachmentsToUpload);
409-
410398
const uploadAttachmentsResult = await Promise.all(
411399
uploadAttachments(
412400
publishFiles.baseDir,

tests/unit/confluence.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,16 @@ const runGetAttachmentsDirectory = () => {
31313131
check(expected, baseDirectory, attachmentPath, fileName);
31323132
});
31333133

3134+
otest(suiteLabel("site_nested_relative_dotslash"), async () => {
3135+
const expected = "/Users/fake-base/fake-parent";
3136+
3137+
const baseDirectory = "/Users/fake-base/_site";
3138+
const attachmentPath = "./file1.png";
3139+
const fileName = "fake-parent/fake-file.xml";
3140+
3141+
check(expected, baseDirectory, attachmentPath, fileName);
3142+
});
3143+
31343144
test(suiteLabel("site_nested_absolute"), async () => {
31353145
const expected = "/Users/fake-base";
31363146

@@ -3150,12 +3160,6 @@ const runGetAttachmentsDirectory = () => {
31503160

31513161
check(expected, baseDirectory, attachmentPath, fileName);
31523162
});
3153-
3154-
//TODO test
3155-
// [
3156-
// "images/elephant.png",
3157-
// "parent/inner-parent/elephant.png",
3158-
// ];
31593163
};
31603164

31613165
const runUpdateImagePathsForContentBody = () => {
@@ -3226,5 +3230,5 @@ if (RUN_ALL_TESTS) {
32263230
runGetAttachmentsDirectory();
32273231
runUpdateImagePathsForContentBody();
32283232
} else {
3229-
runFindAttachments();
3233+
runGetAttachmentsDirectory();
32303234
}

0 commit comments

Comments
 (0)