Skip to content

Commit 6650d80

Browse files
author
Allen Manning
authored
Merge pull request #4021 from quarto-dev/bug/find-attachment-windows
Confluence: Windows support for finding attachments to upload
2 parents 8c5553e + dc2b7db commit 6650d80

File tree

3 files changed

+124
-175
lines changed

3 files changed

+124
-175
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { ApiError, PublishRecord } from "../types.ts";
22
import { ensureTrailingSlash } from "../../core/path.ts";
3+
import {
4+
join,
5+
basename,
6+
parse,
7+
dirname,
8+
toFileUrl,
9+
resolve,
10+
} from "path/mod.ts";
311
import { isHttpUrl } from "../../core/url.ts";
12+
import { pathWithForwardSlashes } from "../../core/path.ts";
413
import { AccountToken, InputMetadata } from "../provider.ts";
514
import {
615
ConfluenceParent,
@@ -614,8 +623,10 @@ export const updateImagePaths = (body: ContentBody): ContentBody => {
614623
export const findAttachments = (
615624
bodyValue: string,
616625
publishFiles: string[] = [],
617-
filePath: string = ""
626+
filePathParam: string = ""
618627
): string[] => {
628+
const filePath = pathWithForwardSlashes(filePathParam);
629+
619630
const pathList = filePath.split("/");
620631
const parentPath = pathList.slice(0, pathList.length - 1).join("/");
621632

@@ -624,52 +635,17 @@ export const findAttachments = (
624635

625636
if (publishFiles.length > 0) {
626637
uniqueResult = uniqueResult.map((assetFileName: string) => {
627-
const assetInPublishFiles = publishFiles.find((assetPath) => {
628-
return assetPath.endsWith(`${parentPath}/${assetFileName}`);
638+
const assetInPublishFiles = publishFiles.find((assetPathParam) => {
639+
const assetPath = pathWithForwardSlashes(assetPathParam);
640+
641+
const toCheck = join(parentPath, assetFileName);
642+
643+
return assetPath === toCheck;
629644
});
645+
630646
return assetInPublishFiles ?? assetFileName;
631647
});
632648
}
633649

634650
return uniqueResult ?? [];
635651
};
636-
637-
export const getAttachmentsDirectory = (
638-
baseDirectory: string,
639-
filePath: string = "",
640-
attachmentPath: string = ""
641-
): string => {
642-
let result = baseDirectory;
643-
644-
if (attachmentPath.length === 0 || filePath.length === 0) {
645-
return "";
646-
}
647-
648-
const filePathList = filePath.split("/");
649-
let attachmentPathList = attachmentPath.split("/");
650-
651-
//TODO navigate path with '..'
652-
if (attachmentPathList.length === 2 && attachmentPathList[0] === ".") {
653-
attachmentPathList = attachmentPathList.slice(1);
654-
}
655-
656-
const pathNoFileFromList = (pathList: string[]) =>
657-
pathList.slice(0, pathList.length - 1).join("/");
658-
659-
if (attachmentPathList.some((path) => path.endsWith("_files"))) {
660-
return baseDirectory;
661-
}
662-
663-
if (result.endsWith("/_site")) {
664-
result = result.slice(0, -6);
665-
}
666-
667-
const isRelative = attachmentPathList.length === 1;
668-
669-
if (isRelative && filePathList.length > 1) {
670-
const directoryPath = pathNoFileFromList(filePathList);
671-
result = `${result}/${directoryPath}`;
672-
}
673-
674-
return result;
675-
};

src/publish/confluence/confluence.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
doWithSpinner,
5454
filterFilesForUpdate,
5555
findAttachments,
56-
getAttachmentsDirectory,
5756
getNextVersion,
5857
getTitle,
5958
isContentCreate,
@@ -290,25 +289,22 @@ async function publish(
290289
const uploadAttachment = async (
291290
attachmentPath: string
292291
): Promise<AttachmentSummary | null> => {
293-
const uploadDirectory = getAttachmentsDirectory(
294-
baseDirectory,
295-
filePath,
296-
attachmentPath
297-
);
292+
let fileBuffer: Uint8Array;
293+
let fileHash: string;
294+
const path = join(baseDirectory, attachmentPath);
298295

299296
trace(
300297
"uploadAttachment",
301298
{
302299
baseDirectory,
303-
pathList: attachmentsToUpload,
300+
attachmentPath,
301+
attachmentsToUpload,
304302
parentId,
305303
existingAttachments,
304+
path,
306305
},
307306
LogPrefix.ATTACHMENT
308307
);
309-
let fileBuffer: Uint8Array;
310-
let fileHash: string;
311-
const path = join(uploadDirectory, attachmentPath);
312308

313309
try {
314310
fileBuffer = await Deno.readFile(path);
@@ -362,8 +358,6 @@ async function publish(
362358
fileName
363359
);
364360

365-
//FIXME expected elephant.png
366-
367361
const uniqueTitle = await uniquifyTitle(titleToUpdate, id);
368362

369363
trace("attachmentsToUpload", attachmentsToUpload, LogPrefix.ATTACHMENT);

0 commit comments

Comments
 (0)