@jupyterlite/contents 0.1.0-beta.11 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/contents.js +4 -4
- package/lib/drivefs.d.ts +18 -1
- package/lib/drivefs.js +40 -19
- package/package.json +5 -5
package/lib/contents.js
CHANGED
|
@@ -159,7 +159,7 @@ export class Contents {
|
|
|
159
159
|
format: 'json',
|
|
160
160
|
mimetype: '',
|
|
161
161
|
content: null,
|
|
162
|
-
size:
|
|
162
|
+
size: 0,
|
|
163
163
|
writable: true,
|
|
164
164
|
type: 'directory',
|
|
165
165
|
};
|
|
@@ -275,7 +275,7 @@ export class Contents {
|
|
|
275
275
|
return {
|
|
276
276
|
...model,
|
|
277
277
|
content: null,
|
|
278
|
-
size:
|
|
278
|
+
size: 0,
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
// for directories, find all files with the path as the prefix
|
|
@@ -304,7 +304,7 @@ export class Contents {
|
|
|
304
304
|
format: 'json',
|
|
305
305
|
mimetype: MIME.JSON,
|
|
306
306
|
content,
|
|
307
|
-
size:
|
|
307
|
+
size: 0,
|
|
308
308
|
writable: true,
|
|
309
309
|
type: 'directory',
|
|
310
310
|
};
|
|
@@ -537,7 +537,7 @@ export class Contents {
|
|
|
537
537
|
format: 'json',
|
|
538
538
|
mimetype: MIME.JSON,
|
|
539
539
|
content: Array.from(content.values()),
|
|
540
|
-
size:
|
|
540
|
+
size: 0,
|
|
541
541
|
writable: true,
|
|
542
542
|
type: 'directory',
|
|
543
543
|
};
|
package/lib/drivefs.d.ts
CHANGED
|
@@ -3,6 +3,23 @@ export declare const FILE_MODE = 33206;
|
|
|
3
3
|
export declare const SEEK_CUR = 1;
|
|
4
4
|
export declare const SEEK_END = 2;
|
|
5
5
|
export declare const DRIVE_SEPARATOR = ":";
|
|
6
|
+
/**
|
|
7
|
+
* Interface of a request on the /api/drive endpoint
|
|
8
|
+
*/
|
|
9
|
+
export interface IDriveRequest {
|
|
10
|
+
/**
|
|
11
|
+
* The method of the request (rmdir, readdir etc)
|
|
12
|
+
*/
|
|
13
|
+
method: string;
|
|
14
|
+
/**
|
|
15
|
+
* The path to the file/directory for which the request was sent
|
|
16
|
+
*/
|
|
17
|
+
path: string;
|
|
18
|
+
/**
|
|
19
|
+
* Extra data on the request
|
|
20
|
+
*/
|
|
21
|
+
data?: any;
|
|
22
|
+
}
|
|
6
23
|
export interface IStats {
|
|
7
24
|
dev: number;
|
|
8
25
|
ino: number;
|
|
@@ -86,7 +103,7 @@ export declare class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {
|
|
|
86
103
|
*/
|
|
87
104
|
export declare class ContentsAPI {
|
|
88
105
|
constructor(baseUrl: string, driveName: string, mountpoint: string, FS: any, ERRNO_CODES: any);
|
|
89
|
-
request(
|
|
106
|
+
request(data: IDriveRequest): any;
|
|
90
107
|
lookup(path: string): DriveFS.ILookup;
|
|
91
108
|
getmode(path: string): number;
|
|
92
109
|
mknod(path: string, mode: number): any;
|
package/lib/drivefs.js
CHANGED
|
@@ -175,16 +175,11 @@ export class ContentsAPI {
|
|
|
175
175
|
this.FS = FS;
|
|
176
176
|
this.ERRNO_CODES = ERRNO_CODES;
|
|
177
177
|
}
|
|
178
|
-
request(
|
|
178
|
+
request(data) {
|
|
179
179
|
const xhr = new XMLHttpRequest();
|
|
180
|
-
xhr.open(
|
|
180
|
+
xhr.open('POST', encodeURI(this.endpoint), false);
|
|
181
181
|
try {
|
|
182
|
-
|
|
183
|
-
xhr.send();
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
xhr.send(data);
|
|
187
|
-
}
|
|
182
|
+
xhr.send(JSON.stringify(data));
|
|
188
183
|
}
|
|
189
184
|
catch (e) {
|
|
190
185
|
console.error(e);
|
|
@@ -195,28 +190,39 @@ export class ContentsAPI {
|
|
|
195
190
|
return JSON.parse(xhr.responseText);
|
|
196
191
|
}
|
|
197
192
|
lookup(path) {
|
|
198
|
-
return this.request('
|
|
193
|
+
return this.request({ method: 'lookup', path: this.normalizePath(path) });
|
|
199
194
|
}
|
|
200
195
|
getmode(path) {
|
|
201
|
-
return Number.parseInt(this.request('
|
|
196
|
+
return Number.parseInt(this.request({ method: 'getmode', path: this.normalizePath(path) }));
|
|
202
197
|
}
|
|
203
198
|
mknod(path, mode) {
|
|
204
|
-
return this.request(
|
|
199
|
+
return this.request({
|
|
200
|
+
method: 'mknod',
|
|
201
|
+
path: this.normalizePath(path),
|
|
202
|
+
data: { mode },
|
|
203
|
+
});
|
|
205
204
|
}
|
|
206
205
|
rename(oldPath, newPath) {
|
|
207
|
-
return this.request(
|
|
206
|
+
return this.request({
|
|
207
|
+
method: 'rename',
|
|
208
|
+
path: this.normalizePath(oldPath),
|
|
209
|
+
data: { newPath: this.normalizePath(newPath) },
|
|
210
|
+
});
|
|
208
211
|
}
|
|
209
212
|
readdir(path) {
|
|
210
|
-
const dirlist = this.request(
|
|
213
|
+
const dirlist = this.request({
|
|
214
|
+
method: 'readdir',
|
|
215
|
+
path: this.normalizePath(path),
|
|
216
|
+
});
|
|
211
217
|
dirlist.push('.');
|
|
212
218
|
dirlist.push('..');
|
|
213
219
|
return dirlist;
|
|
214
220
|
}
|
|
215
221
|
rmdir(path) {
|
|
216
|
-
return this.request('
|
|
222
|
+
return this.request({ method: 'rmdir', path: this.normalizePath(path) });
|
|
217
223
|
}
|
|
218
224
|
get(path) {
|
|
219
|
-
const response = this.request('
|
|
225
|
+
const response = this.request({ method: 'get', path: this.normalizePath(path) });
|
|
220
226
|
const serializedContent = response.content;
|
|
221
227
|
const format = response.format;
|
|
222
228
|
switch (format) {
|
|
@@ -246,22 +252,37 @@ export class ContentsAPI {
|
|
|
246
252
|
switch (value.format) {
|
|
247
253
|
case 'json':
|
|
248
254
|
case 'text':
|
|
249
|
-
return this.request(
|
|
255
|
+
return this.request({
|
|
256
|
+
method: 'put',
|
|
257
|
+
path: this.normalizePath(path),
|
|
258
|
+
data: {
|
|
259
|
+
format: value.format,
|
|
260
|
+
data: decoder.decode(value.data),
|
|
261
|
+
},
|
|
262
|
+
});
|
|
250
263
|
case 'base64': {
|
|
251
264
|
let binary = '';
|
|
252
265
|
for (let i = 0; i < value.data.byteLength; i++) {
|
|
253
266
|
binary += String.fromCharCode(value.data[i]);
|
|
254
267
|
}
|
|
255
|
-
return this.request(
|
|
268
|
+
return this.request({
|
|
269
|
+
method: 'put',
|
|
270
|
+
path: this.normalizePath(path),
|
|
271
|
+
data: {
|
|
272
|
+
format: value.format,
|
|
273
|
+
data: btoa(binary),
|
|
274
|
+
},
|
|
275
|
+
});
|
|
256
276
|
}
|
|
257
277
|
}
|
|
258
278
|
}
|
|
259
279
|
getattr(path) {
|
|
260
|
-
const stats = this.request('
|
|
280
|
+
const stats = this.request({ method: 'getattr', path: this.normalizePath(path) });
|
|
261
281
|
// Turn datetimes into proper objects
|
|
262
282
|
stats.atime = new Date(stats.atime);
|
|
263
283
|
stats.mtime = new Date(stats.mtime);
|
|
264
284
|
stats.ctime = new Date(stats.ctime);
|
|
285
|
+
stats.size = stats.size || 0;
|
|
265
286
|
return stats;
|
|
266
287
|
}
|
|
267
288
|
/**
|
|
@@ -284,7 +305,7 @@ export class ContentsAPI {
|
|
|
284
305
|
* Get the api/drive endpoint
|
|
285
306
|
*/
|
|
286
307
|
get endpoint() {
|
|
287
|
-
return `${this._baseUrl}api/drive
|
|
308
|
+
return `${this._baseUrl}api/drive`;
|
|
288
309
|
}
|
|
289
310
|
}
|
|
290
311
|
export class DriveFS {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/contents",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"description": "JupyterLite - Contents",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"watch": "tsc -b --watch"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@jupyterlab/nbformat": "~3.4.
|
|
46
|
-
"@jupyterlab/services": "~6.4.
|
|
47
|
-
"@jupyterlite/localforage": "^0.1.0-beta.
|
|
45
|
+
"@jupyterlab/nbformat": "~3.4.7",
|
|
46
|
+
"@jupyterlab/services": "~6.4.6",
|
|
47
|
+
"@jupyterlite/localforage": "^0.1.0-beta.13",
|
|
48
48
|
"@lumino/coreutils": "^1.12.0",
|
|
49
49
|
"localforage": "^1.9.0",
|
|
50
50
|
"mime": "^3.0.0"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/core": "^7.11.6",
|
|
54
54
|
"@babel/preset-env": "^7.12.1",
|
|
55
|
-
"@jupyterlab/testutils": "~3.4.
|
|
55
|
+
"@jupyterlab/testutils": "~3.4.7",
|
|
56
56
|
"@types/jest": "^26.0.10",
|
|
57
57
|
"@types/mime": "^2.0.3",
|
|
58
58
|
"jest": "^26.4.2",
|