From ddcaf0c270861f4f852f09044fe9da1d3021b23f Mon Sep 17 00:00:00 2001 From: Renji-xD Date: Wed, 10 Jul 2024 12:57:14 +0200 Subject: [PATCH] fix: file filter not supported anymore on onedrive (#349) --- .../data/storage/handler/onedrive-handler.ts | 31 ++++++++++++++++--- apps/web/src/routes/auth/+page.svelte | 4 +-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/apps/web/src/lib/data/storage/handler/onedrive-handler.ts b/apps/web/src/lib/data/storage/handler/onedrive-handler.ts index 8838ff11..e2bb458b 100644 --- a/apps/web/src/lib/data/storage/handler/onedrive-handler.ts +++ b/apps/web/src/lib/data/storage/handler/onedrive-handler.ts @@ -14,6 +14,8 @@ import pLimit from 'p-limit'; interface OneDriveFile extends ExternalFile { thumbnails?: ExternalThumbnail[]; + file: Record; + folder: Record; } interface BatchRequest { @@ -302,7 +304,7 @@ export class OneDriveStorageHandler extends ApiStorageHandler { params.append('select', `id,name`); if (body) { - const { uploadUrl } = await this.request( + const { uploadUrl: uploadUrlResponse } = await this.request( `${this.baseEndpoint}/${ remoteFile ? `${remoteFile.id}` : `${folderId}:/${encodeURIComponent(name)}:` }/createUploadSession`, @@ -317,6 +319,20 @@ export class OneDriveStorageHandler extends ApiStorageHandler { } ); + const url = new URL(uploadUrlResponse); + const searchParams = [...url.searchParams]; + const uploadUrl = `${url.origin}${url.pathname}`; + + params.delete('select'); + + for (let index = 0, { length } = searchParams; index < length; index += 1) { + const [paramName, paramValue] = searchParams[index]; + + params.append(paramName, paramValue); + } + + params.append('select', `id,name`); + if (!uploadUrl) { throw new Error('Upload url was not returned'); } @@ -389,8 +405,11 @@ export class OneDriveStorageHandler extends ApiStorageHandler { } else { const params = new URLSearchParams(); - params.append('filter', listFiles ? 'file ne null' : 'folder ne null'); - params.append('select', `id,name`); + params.append('select', `id,name,file,folder`); + + if (!listFiles) { + params.append('filter', 'folder ne null'); + } if (withThumbnail) { params.append('expand', `thumbnails`); @@ -400,7 +419,11 @@ export class OneDriveStorageHandler extends ApiStorageHandler { } if (response) { - files.push(...(response.value || [])); + files.push( + ...(response.value || []).filter( + (item: OneDriveFile) => (listFiles && !!item.file) || (!listFiles && !!item.folder) + ) + ); if (response['@odata.nextLink']) { await this.list(parent, withThumbnail, listFiles, files, response?.['@odata.nextLink']); diff --git a/apps/web/src/routes/auth/+page.svelte b/apps/web/src/routes/auth/+page.svelte index df4240c7..a1632128 100644 --- a/apps/web/src/routes/auth/+page.svelte +++ b/apps/web/src/routes/auth/+page.svelte @@ -126,7 +126,7 @@ return; } - window.opener.postMessage( + /* window.opener.postMessage( { type: 'failure', payload: { @@ -135,7 +135,7 @@ } }, origin - ); + ); */ } function checkAuthResponse(