77 deleteFile ,
88 UrlString ,
99} from "@inrupt/solid-client" ;
10- import { getDisplayNameFromMeta , updateMetaFile } from "./metaFileUtils" ;
1110
1211const INVALID_NAME_CHARS = / [ < > : " / \\ | ? * ] / g;
1312
@@ -52,9 +51,10 @@ export const getParentContainerUrl = (resourceUrl: string): string => {
5251} ;
5352
5453const shouldSkipResourceCopy = ( resourceUrl : string ) : boolean => {
55- return resourceUrl . endsWith ( ".meta" ) || resourceUrl . endsWith ( ". acl") ;
54+ return resourceUrl . endsWith ( ".acl" ) ;
5655} ;
5756
57+
5858const resourceExists = async ( url : string , fetchFn : typeof fetch ) : Promise < boolean > => {
5959 try {
6060 const response = await fetchFn ( url , { method : "HEAD" } ) ;
@@ -64,7 +64,7 @@ const resourceExists = async (url: string, fetchFn: typeof fetch): Promise<boole
6464 if ( response . status >= 200 && response . status < 300 ) {
6565 return true ;
6666 }
67- // For other statuses (401, 403, 405, etc.) assume the resource exists to avoid collisions
67+
6868 return true ;
6969 } catch {
7070 return false ;
@@ -108,10 +108,9 @@ const copyFileFromSource = async (
108108 fetch : fetchFn ,
109109 contentType,
110110 } ) ;
111- await updateMetaFile ( targetUrl as UrlString , displayName , fetchFn ) ;
112111} ;
113112
114- const copyFolderContents = async (
113+ export const copyFolderContents = async (
115114 sourceFolderUrl : string ,
116115 destinationFolderUrl : string ,
117116 fetchFn : typeof fetch
@@ -130,18 +129,13 @@ const copyFolderContents = async (
130129 const childDestination = `${ ensureTrailingSlash ( destinationFolderUrl ) } ${ encodedChildName } /` ;
131130
132131 await createContainerAt ( childDestination as UrlString , { fetch : fetchFn } ) ;
133- const childDisplayName =
134- ( await getDisplayNameFromMeta ( resourceUrl , fetchFn ) ) ?? childName ;
135- await updateMetaFile ( childDestination as UrlString , childDisplayName , fetchFn ) ;
136-
137132 await copyFolderContents ( resourceUrl , childDestination , fetchFn ) ;
133+
138134 } else {
139135 const childName = decodeResourceNameFromUrl ( resourceUrl ) ;
140136 const encodedChildName = encodeURIComponent ( childName ) ;
141137 const childDestination = `${ ensureTrailingSlash ( destinationFolderUrl ) } ${ encodedChildName } ` ;
142- const childDisplayName =
143- ( await getDisplayNameFromMeta ( resourceUrl , fetchFn ) ) ?? childName ;
144- await copyFileFromSource ( resourceUrl , childDestination , childDisplayName , fetchFn ) ;
138+ await copyFileFromSource ( resourceUrl , childDestination , childName , fetchFn ) ;
145139 }
146140 }
147141} ;
@@ -150,31 +144,25 @@ export const copyFileResource = async (
150144 file : { url : string ; name ?: string ; mimeType ?: string } ,
151145 fetchFn : typeof fetch
152146) : Promise < void > => {
153- const originalLabel =
154- ( await getDisplayNameFromMeta ( file . url , fetchFn ) ) ??
155- file . name ??
156- decodeResourceNameFromUrl ( file . url ) ;
147+ const originalLabel = file . name ?? decodeResourceNameFromUrl ( file . url ) ;
157148 const parentUrl = getParentContainerUrl ( file . url ) ;
158149 const desiredName = `Copy of ${ originalLabel } ` ;
159- const { targetUrl, displayName } = await generateCopyTarget ( parentUrl , desiredName , false , fetchFn ) ;
160- await copyFileFromSource ( file . url , targetUrl , displayName , fetchFn , file . mimeType ) ;
150+ const { targetUrl } = await generateCopyTarget ( parentUrl , desiredName , false , fetchFn ) ;
151+ await copyFileFromSource ( file . url , targetUrl , desiredName , fetchFn , file . mimeType ) ;
161152} ;
162153
163154export const copyFolderResource = async (
164155 folder : { url : string ; name ?: string } ,
165156 fetchFn : typeof fetch
166157) : Promise < void > => {
167- const originalLabel =
168- ( await getDisplayNameFromMeta ( folder . url , fetchFn ) ) ??
169- folder . name ??
170- decodeResourceNameFromUrl ( folder . url ) ;
158+ const originalLabel = folder . name ?? decodeResourceNameFromUrl ( folder . url ) ;
171159 const parentUrl = getParentContainerUrl ( folder . url ) ;
172160 const desiredName = `Copy of ${ originalLabel } ` ;
173- const { targetUrl, displayName } = await generateCopyTarget ( parentUrl , desiredName , true , fetchFn ) ;
161+ const { targetUrl } = await generateCopyTarget ( parentUrl , desiredName , true , fetchFn ) ;
174162
175163 await createContainerAt ( targetUrl as UrlString , { fetch : fetchFn } ) ;
176- await updateMetaFile ( targetUrl as UrlString , displayName , fetchFn ) ;
177164 await copyFolderContents ( folder . url , targetUrl , fetchFn ) ;
165+
178166} ;
179167
180168/**
@@ -187,10 +175,7 @@ export const moveFileResource = async (
187175 fetchFn : typeof fetch
188176) : Promise < void > => {
189177 // Get the original display name
190- const originalLabel =
191- ( await getDisplayNameFromMeta ( file . url , fetchFn ) ) ??
192- file . name ??
193- decodeResourceNameFromUrl ( file . url ) ;
178+ const originalLabel = file . name ?? decodeResourceNameFromUrl ( file . url ) ;
194179
195180 // Generate target URL in the destination folder
196181 const destinationWithSlash = ensureTrailingSlash ( destinationFolderUrl ) ;
@@ -214,18 +199,7 @@ export const moveFileResource = async (
214199 contentType,
215200 } ) ;
216201
217- // Step 3: Update .meta file with display name
218- await updateMetaFile ( targetUrl as UrlString , originalLabel , fetchFn ) ;
219-
220- // Step 4: Delete the old file
202+ // Step 3: Delete the old file
221203 await deleteFile ( file . url as UrlString , { fetch : fetchFn } ) ;
222-
223- // Also delete the old .meta file if it exists
224- try {
225- const oldMetaUrl = `${ file . url } .meta` as UrlString ;
226- await deleteFile ( oldMetaUrl , { fetch : fetchFn } ) ;
227- } catch ( error ) {
228- // Ignore if .meta file doesn't exist
229- }
230204} ;
231205
0 commit comments