@@ -72,11 +72,11 @@ export class FileSystemDrive implements Contents.IDrive {
72
72
path : '' ,
73
73
created : new Date ( ) . toISOString ( ) ,
74
74
last_modified : new Date ( ) . toISOString ( ) ,
75
- format : 'json' ,
75
+ format : null ,
76
+ mimetype : '' ,
76
77
content : null ,
77
78
writable : true ,
78
79
type : 'directory' ,
79
- mimetype : 'application/json'
80
80
} ;
81
81
}
82
82
@@ -109,11 +109,11 @@ export class FileSystemDrive implements Contents.IDrive {
109
109
path : PathExt . join ( parentPath , localPath , value . name ) ,
110
110
created : '' ,
111
111
last_modified : '' ,
112
- format : 'json' ,
112
+ format : null ,
113
+ mimetype : '' ,
113
114
content : null ,
114
115
writable : true ,
115
116
type : 'directory' ,
116
- mimetype : 'application/json'
117
117
} ) ;
118
118
}
119
119
}
@@ -123,8 +123,8 @@ export class FileSystemDrive implements Contents.IDrive {
123
123
path : PathExt . join ( parentPath , localPath ) ,
124
124
last_modified : '' ,
125
125
created : '' ,
126
- format : 'json' ,
127
- mimetype : 'application/json ' ,
126
+ format : null ,
127
+ mimetype : '' ,
128
128
content,
129
129
size : undefined ,
130
130
writable : true ,
@@ -197,8 +197,26 @@ export class FileSystemDrive implements Contents.IDrive {
197
197
} ) ;
198
198
}
199
199
200
- rename ( oldPath : string , newPath : string ) : Promise < Contents . IModel > {
201
- throw new Error ( 'Method not implemented.' ) ;
200
+ async rename ( oldPath : string , newPath : string ) : Promise < Contents . IModel > {
201
+ // Best effort, we are lacking proper APIs for renaming
202
+ const toCopy = await this . get ( oldPath ) ;
203
+ const newName = PathExt . basename ( newPath ) ;
204
+
205
+ const copy : Partial < Contents . IModel > = {
206
+ name : newName ,
207
+ path : newPath ,
208
+ content : toCopy . content ,
209
+ format : toCopy . format ,
210
+ mimetype : toCopy . mimetype ,
211
+ type : toCopy . type ,
212
+ writable : toCopy . writable ,
213
+ } ;
214
+
215
+ await this . save ( newPath , copy ) ;
216
+
217
+ await this . delete ( oldPath ) ;
218
+
219
+ return this . get ( newPath ) ;
202
220
}
203
221
204
222
async save (
@@ -207,7 +225,13 @@ export class FileSystemDrive implements Contents.IDrive {
207
225
) : Promise < Contents . IModel > {
208
226
const parentHandle = await this . getParentHandle ( path ) ;
209
227
210
- const handle = await parentHandle . getFileHandle ( PathExt . basename ( path ) ) ;
228
+ if ( options ?. type === 'directory' ) {
229
+ await parentHandle . getDirectoryHandle ( PathExt . basename ( path ) , { create : true } ) ;
230
+
231
+ return this . get ( path ) ;
232
+ }
233
+
234
+ const handle = await parentHandle . getFileHandle ( PathExt . basename ( path ) , { create : true } ) ;
211
235
const writable = await handle . createWritable ( { } ) ;
212
236
213
237
const format = options ?. format ;
@@ -223,8 +247,37 @@ export class FileSystemDrive implements Contents.IDrive {
223
247
return this . get ( path ) ;
224
248
}
225
249
226
- copy ( path : string , toLocalDir : string ) : Promise < Contents . IModel > {
227
- throw new Error ( 'Method not implemented.' ) ;
250
+ async copy ( path : string , toLocalDir : string ) : Promise < Contents . IModel > {
251
+ // Best effort, we are lacking proper APIs for copying
252
+ const toCopy = await this . get ( path ) ;
253
+ const parentPath = PathExt . dirname ( path ) ;
254
+
255
+ let newName = toCopy . name ;
256
+ if ( parentPath === toLocalDir ) {
257
+ const ext = PathExt . extname ( toCopy . name ) ;
258
+
259
+ if ( ext ) {
260
+ newName = `${ newName . slice ( 0 , newName . length - ext . length ) } (Copy)${ ext } ` ;
261
+ } else {
262
+ newName = `${ newName } (Copy)` ;
263
+ }
264
+ }
265
+
266
+ const newPath = PathExt . join ( toLocalDir , newName ) ;
267
+
268
+ const copy : Partial < Contents . IModel > = {
269
+ name : newName ,
270
+ path : newPath ,
271
+ content : toCopy . content ,
272
+ format : toCopy . format ,
273
+ mimetype : toCopy . mimetype ,
274
+ type : toCopy . type ,
275
+ writable : toCopy . writable ,
276
+ } ;
277
+
278
+ await this . save ( newPath , copy ) ;
279
+
280
+ return this . get ( newPath ) ;
228
281
}
229
282
230
283
async createCheckpoint ( path : string ) : Promise < Contents . ICheckpointModel > {
0 commit comments