11import { ApiError , PublishRecord } from "../types.ts" ;
22import { ensureTrailingSlash } from "../../core/path.ts" ;
3+ import {
4+ join ,
5+ basename ,
6+ parse ,
7+ dirname ,
8+ toFileUrl ,
9+ resolve ,
10+ } from "path/mod.ts" ;
311import { isHttpUrl } from "../../core/url.ts" ;
12+ import { pathWithForwardSlashes } from "../../core/path.ts" ;
413import { AccountToken , InputMetadata } from "../provider.ts" ;
514import {
615 ConfluenceParent ,
@@ -614,8 +623,10 @@ export const updateImagePaths = (body: ContentBody): ContentBody => {
614623export 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- } ;
0 commit comments