Use IDrive instead of file browser#29
Conversation
|
@brichet How do I update the lockfile? |
|
Running |
|
Also, for consistency (and , if may worth bumping all the And running |
| const newFile = await this._drive.newUntitled({ | ||
| type: (ext === '.ipynb' ? 'notebook' : 'file') as Contents.ContentType, | ||
| path: PathExt.dirname(filePath), | ||
| ext: ext | ||
| }); | ||
| await this._drive.save(newFile.path, { | ||
| content: | ||
| newFile.format === 'json' | ||
| ? JSON.parse(await blob.text()) | ||
| : newFile.format === 'text' | ||
| ? await blob.text() | ||
| : await blobToBase64(blob), | ||
| size: blob.size | ||
| }); | ||
| await this._drive.rename(newFile.path, filePath); |
There was a problem hiding this comment.
There was a problem hiding this comment.
I wonder if we need to use a newUntilted, can't we directly use the save method ?
And maybe we can guess if it is a text or bytes mimetype using something like the following (suggestion from chatGPT, not sure if it misses some case):
function isTextMimeType(mime: string): boolean {
const textTypes = [
"application/json",
"application/xml",
"application/javascript",
"application/x-www-form-urlencoded",
"image/svg+xml"
];
return (
mime.startsWith("text/") ||
textTypes.includes(mime) ||
mime.endsWith("+json") || // e.g. application/ld+json
mime.endsWith("+xml")
);
}I tested successfully the following implementation, with the example from RTD (which contains only notebook, image and text files).
const isText = isTextMimeType(type);
const content = isText ? await blob.text() : await blobToBase64(blob);
await this._drive.save(filePath, {
content: content,
type: 'file',
mimetype: type,
format: isText ? 'text' : 'base64'
});There was a problem hiding this comment.
This is the logic that the JupyterLite browser storage drive uses: https://github.com/jupyterlite/jupyterlite/blob/b0f84a44894e3edc554bb0e03f193c44d05f20ff/packages/services/src/contents/drive.ts#L398-L431
I fear that we'd have to duplicate this logic exactly, and the current approach circumvents this code duplication
|
The RTD build now fails to load the extension, so something is broken :( |
|
The RTD build fails to load the extension with Do you have any idea about what might be wrong? |
Maybe this helps with #28?