|
1 | 1 | import { ReadonlyJSONObject } from '@lumino/coreutils'; |
| 2 | +import { Contents } from '@jupyterlab/services'; |
| 3 | +import { PathExt } from '@jupyterlab/coreutils'; |
2 | 4 |
|
3 | 5 | import { requestAPI } from './handler'; |
4 | 6 |
|
| 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 | + |
5 | 24 | /** |
6 | 25 | * Fetch the list of available drives. |
7 | 26 | * @returns list of drives |
@@ -30,8 +49,44 @@ export async function getContents( |
30 | 49 | driveName: string, |
31 | 50 | options: { path: string } |
32 | 51 | ) { |
33 | | - return await requestAPI<any>( |
| 52 | + const response = await requestAPI<any>( |
34 | 53 | 'drives/' + driveName + '/' + options.path, |
35 | 54 | 'GET' |
36 | 55 | ); |
| 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; |
37 | 92 | } |
0 commit comments