@@ -81,6 +81,7 @@ import {
8181import { DELETE_DISABLED } from "./constants.ts" ;
8282import { logError , trace } from "./confluence-logger.ts" ;
8383import { md5Hash } from "../../core/hash.ts" ;
84+ import { sleep } from "../../core/async.ts" ;
8485
8586export const CONFLUENCE_ID = "confluence" ;
8687
@@ -246,10 +247,14 @@ async function publish(
246247 trace ( "publish" , { parent, server, space } ) ;
247248
248249 const uniquifyTitle = async ( title : string ) => {
250+ console . log ( "uniquifyTitle" , title ) ;
249251 const titleAlreadyExistsInSpace : boolean = await client . isTitleInSpace (
250252 title ,
251253 space
252254 ) ;
255+
256+ console . log ( "titleAlreadyExistsInSpace" , titleAlreadyExistsInSpace ) ;
257+
253258 const uuid = globalThis . crypto . randomUUID ( ) ;
254259 const shortUUID = uuid . split ( "-" ) [ 0 ] ?? uuid ;
255260 const createTitle = titleAlreadyExistsInSpace
@@ -262,7 +267,6 @@ async function publish(
262267 const descendants : any [ ] =
263268 ( await client . getDescendants ( parentId ) ) ?. results ?? [ ] ;
264269
265- console . log ( "descendants" , descendants ) ;
266270 const contentProperties : ContentProperty [ ] [ ] = await Promise . all (
267271 descendants . map ( ( page : ContentSummary ) =>
268272 client . getContentProperty ( page . id ?? "" )
@@ -464,8 +468,13 @@ async function publish(
464468 createParent : ConfluenceParent = parent ,
465469 fileName : string = ""
466470 ) : Promise < Content > => {
471+ //TODO check why files are always being uniquified
472+ console . log ( "create Content" ) ;
473+ console . log ( "titleToCreate" ) ;
467474 const createTitle = await uniquifyTitle ( titleToCreate ) ;
468475
476+ console . log ( "createTitle" , createTitle ) ;
477+
469478 const attachmentsToUpload : string [ ] = findAttachments (
470479 body . storage . value ,
471480 publishFiles . files ,
@@ -554,11 +563,12 @@ async function publish(
554563
555564 trace ( "publishSite" , {
556565 parentId,
557- existingSite,
558566 publishFiles,
559567 metadataByInput,
560568 } ) ;
561569
570+ trace ( "existingSite" , existingSite ) ;
571+
562572 const filteredFiles : string [ ] = filterFilesForUpdate ( publishFiles . files ) ;
563573
564574 trace ( "filteredFiles" , filteredFiles ) ;
@@ -573,7 +583,7 @@ async function publish(
573583 } ;
574584
575585 const originalTitle = getTitle ( fileName , metadataByInput ) ;
576- const title = await uniquifyTitle ( originalTitle ) ;
586+ const title = originalTitle ;
577587
578588 const matchingPages = await client . fetchMatchingTitlePages (
579589 originalTitle ,
@@ -620,9 +630,11 @@ async function publish(
620630
621631 const doChange = async ( change : ConfluenceSpaceChange ) => {
622632 if ( isContentCreate ( change ) ) {
633+ console . log ( "DO CREATE" ) ;
623634 let ancestorId =
624635 ( change ?. ancestors && change ?. ancestors [ 0 ] ?. id ) ?? null ;
625-
636+ console . log ( "ancestorId" , ancestorId ) ;
637+ console . log ( "pathsToId" , pathsToId ) ;
626638 if ( ancestorId && pathsToId [ ancestorId ] ) {
627639 ancestorId = pathsToId [ ancestorId ] ;
628640 }
@@ -652,6 +664,7 @@ async function publish(
652664
653665 return result ;
654666 } else if ( isContentUpdate ( change ) ) {
667+ console . log ( "DO UPDATE" ) ;
655668 const update = change as ContentUpdate ;
656669 return await updateContent (
657670 publishFiles ,
@@ -660,11 +673,13 @@ async function publish(
660673 update . title ?? ""
661674 ) ;
662675 } else if ( isContentDelete ( change ) ) {
676+ console . log ( "DO DELETE" , change ) ;
663677 if ( DELETE_DISABLED ) {
664678 console . warn ( "DELETE DISABELD" ) ;
665679 return null ;
666680 }
667681 const result = await client . deleteContent ( change ) ;
682+ await sleep ( 2000 ) ; // Consider polling on delete to support uniqify rather than sleep
668683 return result ;
669684 } else {
670685 console . error ( "Space Change not defined" ) ;
0 commit comments