From 03887818e87a0f89f60f551085bdd66c5caf766a Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 20 Nov 2024 14:13:14 +0100 Subject: [PATCH] iterate on path configuration for contents listing --- src/contents.ts | 25 ++++++++++++++++--------- src/requests.ts | 40 +++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/contents.ts b/src/contents.ts index 872dd42..61633c8 100644 --- a/src/contents.ts +++ b/src/contents.ts @@ -194,19 +194,18 @@ export class Drive implements Contents.IDrive { localPath: string, options?: Contents.IFetchOptions ): Promise { - const relativePath = ''; + let relativePath = ''; console.log('GET localpath: ', localPath); if (localPath !== '') { - // if (localPath.includes(this.name)) { - // relativePath = localPath.split(this.name + '/')[1]; - // } else { - // relativePath = localPath; - // } - // extract current drive name const currentDrive = this._drivesList.filter( - x => x.name === localPath + x => + x.name === + (localPath.indexOf('/') !== -1 + ? localPath.substring(0, localPath.indexOf('/')) + : localPath) )[0]; + // when accessed the first time, mount drive if (currentDrive.mounted === false) { try { @@ -220,11 +219,19 @@ export class Drive implements Contents.IDrive { } } + // eliminate drive name from path + relativePath = + localPath.indexOf('/') !== -1 + ? localPath.substring(localPath.indexOf('/') + 1) + : ''; + data = await getContents(currentDrive.name, { - path: '', + path: relativePath, registeredFileTypes: this._registeredFileTypes }); } else { + // retriving list of contents from root + // in our case: list available drives const drivesList: Contents.IModel[] = []; for (const drive of this._drivesList) { drivesList.push({ diff --git a/src/requests.ts b/src/requests.ts index d9fa5b0..4956804 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -69,25 +69,31 @@ export async function getContents( const fileList: IContentsList = {}; response.data.forEach((row: any) => { - const fileName = PathExt.basename(row.path); + // check if we are dealing with files inside a subfolder + if (row.path !== options.path && row.path !== options.path + '/') { + // extract object name from path + const fileName = row.path + .replace(options.path ? options.path + '/' : '', '') + .split('/')[0]; - const [fileType, fileMimeType, fileFormat] = getFileType( - PathExt.extname(PathExt.basename(fileName)), - options.registeredFileTypes - ); + const [fileType, fileMimeType, fileFormat] = getFileType( + PathExt.extname(PathExt.basename(fileName)), + options.registeredFileTypes + ); - fileList[fileName] = fileList[fileName] ?? { - name: fileName, - path: driveName + '/' + row.path, - last_modified: row.last_modified, - created: '', - content: !fileName.split('.')[1] ? [] : null, - format: fileFormat as Contents.FileFormat, - mimetype: fileMimeType, - size: row.size, - writable: true, - type: fileType - }; + fileList[fileName] = fileList[fileName] ?? { + name: fileName, + path: driveName + '/' + row.path, + last_modified: row.last_modified, + created: '', + content: !fileName.split('.')[1] ? [] : null, + format: fileFormat as Contents.FileFormat, + mimetype: fileMimeType, + size: row.size, + writable: true, + type: fileType + }; + } }); data = {