Skip to content

Commit

Permalink
iterate on path configuration for contents listing
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisaCG committed Nov 20, 2024
1 parent 28c2edd commit 0388781
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
25 changes: 16 additions & 9 deletions src/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ export class Drive implements Contents.IDrive {
localPath: string,
options?: Contents.IFetchOptions
): Promise<Contents.IModel> {
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 {
Expand All @@ -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({
Expand Down
40 changes: 23 additions & 17 deletions src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 0388781

Please sign in to comment.