77from fsspec_proxy import file_manager
88
99
10+ URL_SCHEMA = "{prefix}/{key}/{op}/{path}"
11+ # where op = bytes | list
12+
1013@asynccontextmanager
1114async def lifespan (app : fastapi .FastAPI ):
1215 # start instances in async context
@@ -24,18 +27,7 @@ async def lifespan(app: fastapi.FastAPI):
2427)
2528
2629
27- @app .get ("/api/list" )
28- async def list_root ():
29- keys = list (app .manager .filesystems )
30- return {
31- "status" : "ok" ,
32- "contents" : [
33- {"name" : k , "size" : 0 , "type" : "directory" } for k in keys
34- ]
35- }
36-
37-
38- @app .get ("/api/list/{key}/{path:path}" )
30+ @app .get ("/{key}/list/{path:path}" )
3931async def list_dir (key , path ):
4032 fs_info = app .manager .get_filesystem (key )
4133 if fs_info is None :
@@ -53,7 +45,7 @@ async def list_dir(key, path):
5345 return {"status" : "ok" , "contents" : out }
5446
5547
56- @app .delete ("/api/delete/ {key}/{path:path}" )
48+ @app .delete ("/{key}/delete /{path:path}" )
5749async def delete_file (key , path , response : fastapi .Response ):
5850 fs_info = app .manager .get_filesystem (key )
5951 path = f"{ fs_info ['path' ].rstrip ('/' )} /{ path .lstrip ('/' )} "
@@ -70,7 +62,7 @@ async def delete_file(key, path, response: fastapi.Response):
7062 response .status_code = 204
7163
7264
73- @app .get ("/api/bytes/ {key}/{path:path}" )
65+ @app .get ("/{key}/bytes /{path:path}" )
7466async def get_bytes (key , path , request : fastapi .Request ):
7567 start , end = _process_range (request .headers .get ("Range" ))
7668 fs_info = app .manager .get_filesystem (key )
@@ -84,7 +76,7 @@ async def get_bytes(key, path, request: fastapi.Request):
8476 return StreamingResponse (io .BytesIO (out ), media_type = "application/octet-stream" )
8577
8678
87- @app .post ("/api/bytes/ {key}/{path:path}" )
79+ @app .post ("/{key}/bytes /{path:path}" )
8880async def put_bytes (key , path , request : fastapi .Request , response : fastapi .Response ):
8981 fs_info = app .manager .get_filesystem (key )
9082 if fs_info is None :
@@ -101,14 +93,6 @@ async def put_bytes(key, path, request: fastapi.Request, response: fastapi.Respo
10193 return {"contents" : []}
10294
10395
104- @app .post ("/api/config" )
105- async def setup (request : fastapi .Request ):
106- if not app .manager .config .get ("allow_reload" , False ):
107- raise fastapi .HTTPException (status_code = 403 , detail = "Not Allowed" )
108- app .manager .config = await request .json ()
109- app .manager .initialize_filesystems ()
110-
111-
11296def _process_range (range ):
11397 if range and range .startswith ("bytes=" ) and range .count ("-" ) == 1 :
11498 sstart , sstop = range .split ("=" )[1 ].split ("-" )
0 commit comments