diff --git a/src/fileCollectionFromFileArray.ts b/src/fileCollectionFromFileArray.ts index 17050ed..28059de 100644 --- a/src/fileCollectionFromFileArray.ts +++ b/src/fileCollectionFromFileArray.ts @@ -25,9 +25,10 @@ export async function fileCollectionFromFileArray( lastModified: number; size: number; }[], - baseURL?: string | URL, - options: ExpandOptions & FilterOptions = {}, + + options: { baseURL?: string | URL } & ExpandOptions & FilterOptions = {}, ): Promise { + const { baseURL } = options; let fileCollectionItems: FileCollectionItem[] = []; /* Answer should contain: @@ -47,14 +48,24 @@ export async function fileCollectionFromFileArray( relativePath: entry.relativePath, lastModified: entry.lastModified, text: async (): Promise => { - const fileURL = new URL(entry.relativePath, baseURL).href; - const response = await fetch(fileURL); - return response.text(); + if (baseURL) { + const fileURL = new URL(entry.relativePath, baseURL); + const response = await fetch(fileURL); + return response.text(); + } else { + const response = await fetch(entry.relativePath); + return response.text(); + } }, arrayBuffer: async (): Promise => { - const fileURL = new URL(entry.relativePath, baseURL).href; - const response = await fetch(fileURL); - return response.arrayBuffer(); + if (baseURL) { + const fileURL = new URL(entry.relativePath, baseURL); + const response = await fetch(fileURL); + return response.arrayBuffer(); + } else { + const response = await fetch(entry.relativePath); + return response.arrayBuffer(); + } }, stream: (): ReadableStream => { throw new Error('stream not yet implemented'); diff --git a/src/fileCollectionFromWebservice.ts b/src/fileCollectionFromWebservice.ts index dbfe00f..7678cf2 100644 --- a/src/fileCollectionFromWebservice.ts +++ b/src/fileCollectionFromWebservice.ts @@ -24,5 +24,5 @@ export async function fileCollectionFromWebservice( const entries = await response.json(); const baseURL = url; - return fileCollectionFromFileArray(entries, baseURL, options); + return fileCollectionFromFileArray(entries, { baseURL, ...options }); }