@@ -281,21 +281,34 @@ async function publish(
281281
282282 const uploadAttachments = (
283283 baseDirectory : string ,
284- pathList : string [ ] ,
284+ attachmentsToUpload : string [ ] ,
285285 parentId : string ,
286+ filePath : string ,
286287 existingAttachments : AttachmentSummary [ ] = [ ]
287288 ) : Promise < AttachmentSummary | null > [ ] => {
288289 const uploadAttachment = async (
289- pathToUpload : string
290+ attachmentPath : string
290291 ) : Promise < AttachmentSummary | null > => {
292+ const uploadDirectory = getAttachmentsDirectory (
293+ baseDirectory ,
294+ filePath ,
295+ attachmentPath
296+ ) ;
297+
291298 trace (
292299 "uploadAttachment" ,
293- { baseDirectory, pathList, parentId, existingAttachments } ,
300+ {
301+ baseDirectory,
302+ pathList : attachmentsToUpload ,
303+ parentId,
304+ existingAttachments,
305+ } ,
294306 LogPrefix . ATTACHMENT
295307 ) ;
296308 let fileBuffer : Uint8Array ;
297309 let fileHash : string ;
298- const path = join ( baseDirectory , pathToUpload ) ;
310+ const path = join ( uploadDirectory , attachmentPath ) ;
311+
299312 try {
300313 fileBuffer = await Deno . readFile ( path ) ;
301314 fileHash = md5Hash ( fileBuffer . toString ( ) ) ;
@@ -304,7 +317,7 @@ async function publish(
304317 return null ;
305318 }
306319
307- const fileName = pathToUpload ;
320+ const fileName = attachmentPath ;
308321
309322 const existingDuplicateAttachment = existingAttachments . find (
310323 ( attachment : AttachmentSummary ) => {
@@ -330,7 +343,7 @@ async function publish(
330343 return attachment ;
331344 } ;
332345
333- return pathList . map ( uploadAttachment ) ;
346+ return attachmentsToUpload . map ( uploadAttachment ) ;
334347 } ;
335348
336349 const updateContent = async (
@@ -342,7 +355,10 @@ async function publish(
342355 ) : Promise < Content > => {
343356 const previousPage = await client . getContent ( id ) ;
344357
345- const attachmentsToUpload : string [ ] = findAttachments ( body . storage . value ) ;
358+ const attachmentsToUpload : string [ ] = findAttachments (
359+ body . storage . value ,
360+ publishFiles . files
361+ ) ;
346362
347363 trace ( "attachmentsToUpload" , attachmentsToUpload , LogPrefix . ATTACHMENT ) ;
348364
@@ -367,23 +383,18 @@ async function publish(
367383 const existingAttachments : AttachmentSummary [ ] =
368384 await client . getAttachments ( toUpdate . id ) ;
369385
370- const baseDirectory = getAttachmentsDirectory (
371- publishFiles . baseDir ,
372- fileName ,
373- attachmentsToUpload
374- ) ;
375-
376386 trace (
377387 "attachments" ,
378- { existingAttachments, attachmentsToUpload, baseDirectory } ,
388+ { existingAttachments, attachmentsToUpload } ,
379389 LogPrefix . ATTACHMENT
380390 ) ;
381391
382392 const uploadAttachmentsResult = await Promise . all (
383393 uploadAttachments (
384- baseDirectory ,
394+ publishFiles . baseDir ,
385395 attachmentsToUpload ,
386396 toUpdate . id ,
397+ fileName ,
387398 existingAttachments
388399 )
389400 ) ;
@@ -474,8 +485,6 @@ async function publish(
474485 createParent : ConfluenceParent = parent ,
475486 fileName : string = ""
476487 ) : Promise < Content > => {
477- //TODO check why files are always being uniquified
478-
479488 const createTitle = await uniquifyTitle ( titleToCreate ) ;
480489
481490 const attachmentsToUpload : string [ ] = findAttachments (
@@ -505,7 +514,8 @@ async function publish(
505514 uploadAttachments (
506515 publishFiles . baseDir ,
507516 attachmentsToUpload ,
508- createdContent . id
517+ createdContent . id ,
518+ fileName
509519 )
510520 ) ;
511521 trace (
0 commit comments