@@ -1423,10 +1423,12 @@ async def htmx_root_list(
1423
1423
1424
1424
1425
1425
def _get_rootdir (user , root ):
1426
- if user and root == "@personal" :
1427
- return settings .personal / str (user .id )
1428
- elif user and root == "@shared" :
1429
- return settings .shared
1426
+ if root == "@personal" :
1427
+ if user :
1428
+ return settings .personal / str (user .id )
1429
+ elif root == "@shared" :
1430
+ if user :
1431
+ return settings .shared
1430
1432
elif root == "@public" :
1431
1433
return settings .public
1432
1434
else :
@@ -2156,55 +2158,79 @@ def jupyterlite_contents(
2156
2158
2157
2159
content = []
2158
2160
2159
- def directory (path ):
2161
+ def directory (abspath , relpath ):
2162
+ stat = abspath .stat ()
2160
2163
return {
2161
- "name" : pathlib .Path (path ).name ,
2162
- "path" : path ,
2164
+ "created" : utils .epoch_to_iso (stat .st_ctime ),
2165
+ "format" : "json" ,
2166
+ "hash" : None ,
2167
+ "hash_algorithm" : None ,
2168
+ "last_modified" : utils .epoch_to_iso (stat .st_mtime ),
2169
+ "mimetype" : None ,
2170
+ "name" : pathlib .Path (relpath ).name ,
2171
+ "path" : relpath ,
2163
2172
"size" : None ,
2164
2173
"type" : "directory" ,
2174
+ "writable" : True ,
2165
2175
}
2166
2176
2167
2177
parts = parts [:- 1 ]
2168
2178
if len (parts ) == 0 :
2169
- # TODO pub/sub roots: settings.database.roots.values()
2170
- if user :
2171
- content .append (directory ("@personal" ))
2172
- content .append (directory ("@shared" ))
2179
+ rootdir = _get_rootdir (user , "@personal" )
2180
+ if rootdir is not None :
2181
+ content .append (directory (rootdir , "@personal" ))
2182
+
2183
+ rootdir = _get_rootdir (user , "@shared" )
2184
+ if rootdir is not None :
2185
+ content .append (directory (rootdir , "@shared" ))
2186
+
2187
+ rootdir = _get_rootdir (user , "@public" )
2188
+ if rootdir is not None :
2189
+ content .append (directory (rootdir , "@public" ))
2173
2190
2174
- content .append (directory ("@public" ))
2191
+ # TODO pub/sub roots: settings.database.roots.values()
2192
+ response = directory (rootdir .parent , "" )
2175
2193
else :
2176
2194
root = parts [0 ]
2177
2195
rootdir = _get_rootdir (user , root )
2178
2196
if rootdir is None :
2179
2197
raise fastapi .HTTPException (status_code = 404 ) # NotFound
2180
2198
2199
+ response = directory (rootdir , root )
2181
2200
for abspath , relpath in utils .iterdir (rootdir ):
2182
2201
if abspath .is_file ():
2183
2202
if relpath .suffix == ".b2" :
2184
2203
relpath = relpath .with_suffix ("" )
2185
2204
2186
2205
if relpath .suffix == ".ipynb" :
2187
- type = "notebook"
2206
+ content_type = "notebook"
2207
+ writable = True
2188
2208
else :
2189
- type = "file" # XXX Is this the correct type?
2209
+ content_type = "file"
2210
+ writable = False
2190
2211
2191
2212
stat = abspath .stat ()
2192
2213
content .append (
2193
2214
{
2215
+ "content" : None ,
2194
2216
"created" : utils .epoch_to_iso (stat .st_ctime ),
2217
+ "format" : None ,
2218
+ "hash" : None ,
2219
+ "hash_algorithm" : None ,
2195
2220
"last_modified" : utils .epoch_to_iso (stat .st_mtime ),
2221
+ "mimetype" : None ,
2196
2222
"name" : relpath .name ,
2197
- "path" : relpath ,
2223
+ "path" : f" { root } / { relpath } " ,
2198
2224
"size" : stat .st_size , # XXX Return the uncompressed size?
2199
- "type" : type ,
2225
+ "type" : content_type ,
2226
+ "writable" : writable ,
2200
2227
}
2201
2228
)
2202
2229
else :
2203
- content .append (directory (relpath ))
2230
+ content .append (directory (relpath )) # FIXME
2204
2231
2205
- return {
2206
- "content" : content ,
2207
- }
2232
+ response ["content" ] = content
2233
+ return response
2208
2234
2209
2235
2210
2236
@app .get ("/static/jupyterlite/files/{path:path}" )
@@ -2217,11 +2243,20 @@ def jupyterlite_files(
2217
2243
async def downloader ():
2218
2244
yield await get_file_content (path , user )
2219
2245
2220
- mimetype = guess_type (path )
2221
- # mimetype = ' application/json'
2246
+ # mimetype = guess_type(path)
2247
+ mimetype = " application/json"
2222
2248
return responses .StreamingResponse (downloader (), media_type = mimetype )
2223
2249
2224
2250
2251
+ @app .get ("/service-worker.js" )
2252
+ def jupyterlite_worker (
2253
+ # Query parameters
2254
+ enableCache : bool | None = None ,
2255
+ ):
2256
+ abspath = BASE_DIR / "static/jupyterlite/service-worker.js"
2257
+ return FileResponse (abspath , filename = abspath .name , media_type = "application/javascript" )
2258
+
2259
+
2225
2260
#
2226
2261
# Static
2227
2262
#
0 commit comments