Skip to content

Commit 09d0f60

Browse files
committed
iterate on contents listing
1 parent 6a078b4 commit 09d0f60

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

jupyter_drives/manager.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,12 @@ async def get_contents(self, drive_name, path):
162162
drive_name: name of drive to get the contents of
163163
path: path to file or directory (empty string for root listing)
164164
"""
165-
print('!!!!!!!!!!!!!!!!!!!', drive_name, 'path: ', path)
166165
if path == '/':
167166
path = ''
168-
drive_name = 'jupyter-drives-test-bucket-1'
169167
try :
170168
currentObject = os.path.basename(path) if os.path.basename(path) is not None else ''
171-
print('currentObject: ', currentObject)
172169
# check if we are listing contents of a directory
173170
if currentObject.find('.') == -1:
174-
print('in if')
175-
print('store: ', self._content_managers)
176171
data = []
177172
# using Arrow lists as they are recommended for large results
178173
# sream will be an async iterable of RecordBatch
@@ -201,7 +196,6 @@ async def get_contents(self, drive_name, path):
201196
"last_modified": metadata["last_modified"].isoformat(),
202197
"size": metadata["size"]
203198
}
204-
print(data)
205199
response = {
206200
"data": data
207201
}

src/contents.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import { Signal, ISignal } from '@lumino/signaling';
55
import { Contents, ServerConnection } from '@jupyterlab/services';
6-
import { PathExt } from '@jupyterlab/coreutils';
76
import { IDriveInfo } from './token';
87
import { getContents, mountDrive } from './requests';
98

@@ -208,21 +207,7 @@ export class Drive implements Contents.IDrive {
208207
}
209208
}
210209

211-
const resp = await getContents(currentDrive.name, { path: '' });
212-
console.log('resp: ', resp);
213-
214-
data = {
215-
name: PathExt.basename(localPath),
216-
path: PathExt.basename(localPath),
217-
last_modified: '',
218-
created: '',
219-
content: [],
220-
format: 'json',
221-
mimetype: '',
222-
size: undefined,
223-
writable: true,
224-
type: 'directory'
225-
};
210+
data = await getContents(currentDrive.name, { path: '' });
226211
} else {
227212
const drivesList: Contents.IModel[] = [];
228213
for (const drive of this._drivesList) {

src/requests.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import { ReadonlyJSONObject } from '@lumino/coreutils';
2+
import { Contents } from '@jupyterlab/services';
3+
import { PathExt } from '@jupyterlab/coreutils';
24

35
import { requestAPI } from './handler';
46

7+
let data: Contents.IModel = {
8+
name: '',
9+
path: '',
10+
last_modified: '',
11+
created: '',
12+
content: null,
13+
format: null,
14+
mimetype: '',
15+
size: 0,
16+
writable: true,
17+
type: ''
18+
};
19+
20+
interface IContentsList {
21+
[fileName: string]: Contents.IModel;
22+
}
23+
524
/**
625
* Fetch the list of available drives.
726
* @returns list of drives
@@ -30,8 +49,44 @@ export async function getContents(
3049
driveName: string,
3150
options: { path: string }
3251
) {
33-
return await requestAPI<any>(
52+
const response = await requestAPI<any>(
3453
'drives/' + driveName + '/' + options.path,
3554
'GET'
3655
);
56+
57+
if (response.data) {
58+
const fileList: IContentsList = {};
59+
60+
response.data.forEach((row: any) => {
61+
const fileName = PathExt.basename(row.path);
62+
63+
fileList[fileName] = fileList[fileName] ?? {
64+
name: fileName,
65+
path: driveName + '/' + row.path,
66+
last_modified: row.last_modified,
67+
created: '',
68+
content: !fileName.split('.')[1] ? [] : null,
69+
format: null, //fileFormat as Contents.FileFormat,
70+
mimetype: 'null', //fileMimeType,
71+
size: row.size,
72+
writable: true,
73+
type: 'directory' //fileType
74+
};
75+
});
76+
77+
data = {
78+
name: options.path ? PathExt.basename(options.path) : '',
79+
path: options.path ? options.path + '/' : '',
80+
last_modified: '',
81+
created: '',
82+
content: Object.values(fileList),
83+
format: 'json',
84+
mimetype: '',
85+
size: undefined,
86+
writable: true,
87+
type: 'directory'
88+
};
89+
}
90+
91+
return data;
3792
}

0 commit comments

Comments
 (0)