Skip to content

Commit 0388781

Browse files
committed
iterate on path configuration for contents listing
1 parent 28c2edd commit 0388781

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

src/contents.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,18 @@ export class Drive implements Contents.IDrive {
194194
localPath: string,
195195
options?: Contents.IFetchOptions
196196
): Promise<Contents.IModel> {
197-
const relativePath = '';
197+
let relativePath = '';
198198
console.log('GET localpath: ', localPath);
199199
if (localPath !== '') {
200-
// if (localPath.includes(this.name)) {
201-
// relativePath = localPath.split(this.name + '/')[1];
202-
// } else {
203-
// relativePath = localPath;
204-
// }
205-
206200
// extract current drive name
207201
const currentDrive = this._drivesList.filter(
208-
x => x.name === localPath
202+
x =>
203+
x.name ===
204+
(localPath.indexOf('/') !== -1
205+
? localPath.substring(0, localPath.indexOf('/'))
206+
: localPath)
209207
)[0];
208+
210209
// when accessed the first time, mount drive
211210
if (currentDrive.mounted === false) {
212211
try {
@@ -220,11 +219,19 @@ export class Drive implements Contents.IDrive {
220219
}
221220
}
222221

222+
// eliminate drive name from path
223+
relativePath =
224+
localPath.indexOf('/') !== -1
225+
? localPath.substring(localPath.indexOf('/') + 1)
226+
: '';
227+
223228
data = await getContents(currentDrive.name, {
224-
path: '',
229+
path: relativePath,
225230
registeredFileTypes: this._registeredFileTypes
226231
});
227232
} else {
233+
// retriving list of contents from root
234+
// in our case: list available drives
228235
const drivesList: Contents.IModel[] = [];
229236
for (const drive of this._drivesList) {
230237
drivesList.push({

src/requests.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,31 @@ export async function getContents(
6969
const fileList: IContentsList = {};
7070

7171
response.data.forEach((row: any) => {
72-
const fileName = PathExt.basename(row.path);
72+
// check if we are dealing with files inside a subfolder
73+
if (row.path !== options.path && row.path !== options.path + '/') {
74+
// extract object name from path
75+
const fileName = row.path
76+
.replace(options.path ? options.path + '/' : '', '')
77+
.split('/')[0];
7378

74-
const [fileType, fileMimeType, fileFormat] = getFileType(
75-
PathExt.extname(PathExt.basename(fileName)),
76-
options.registeredFileTypes
77-
);
79+
const [fileType, fileMimeType, fileFormat] = getFileType(
80+
PathExt.extname(PathExt.basename(fileName)),
81+
options.registeredFileTypes
82+
);
7883

79-
fileList[fileName] = fileList[fileName] ?? {
80-
name: fileName,
81-
path: driveName + '/' + row.path,
82-
last_modified: row.last_modified,
83-
created: '',
84-
content: !fileName.split('.')[1] ? [] : null,
85-
format: fileFormat as Contents.FileFormat,
86-
mimetype: fileMimeType,
87-
size: row.size,
88-
writable: true,
89-
type: fileType
90-
};
84+
fileList[fileName] = fileList[fileName] ?? {
85+
name: fileName,
86+
path: driveName + '/' + row.path,
87+
last_modified: row.last_modified,
88+
created: '',
89+
content: !fileName.split('.')[1] ? [] : null,
90+
format: fileFormat as Contents.FileFormat,
91+
mimetype: fileMimeType,
92+
size: row.size,
93+
writable: true,
94+
type: fileType
95+
};
96+
}
9197
});
9298

9399
data = {

0 commit comments

Comments
 (0)