@@ -22,7 +22,9 @@ import {
2222 getFileSystemHandles ,
2323 hasIndexedDB ,
2424 isMountedFolder ,
25+ parseDirectory ,
2526 KEYVAL_DB ,
27+ type FS9PV4 ,
2628} from "contexts/fileSystem/core" ;
2729import useAsyncFs , {
2830 type AsyncFS ,
@@ -103,6 +105,11 @@ type FileSystemContextState = AsyncFS & {
103105 mkdirRecursive : ( path : string ) => Promise < void > ;
104106 mountEmscriptenFs : ( FS : EmscriptenFS , fsName ?: string ) => Promise < string > ;
105107 mountFs : ( url : string ) => Promise < void > ;
108+ mountHttpRequestFs : (
109+ mountPoint : string ,
110+ url : string ,
111+ baseUrl ?: string
112+ ) => Promise < void > ;
106113 moveEntries : ( entries : string [ ] ) => void ;
107114 pasteList : FilePasteOperations ;
108115 removeFsWatcher : ( folder : string , updateFiles : UpdateFiles ) => void ;
@@ -293,6 +300,40 @@ const useFileSystemContextState = (): FileSystemContextState => {
293300 } ) ,
294301 [ rootFs ]
295302 ) ;
303+ const mountHttpRequestFs = useCallback (
304+ async (
305+ mountPoint : string ,
306+ url : string ,
307+ baseUrl ?: string
308+ ) : Promise < void > => {
309+ const index = ( await ( await fetch ( url ) ) . json ( ) ) as object ;
310+
311+ if ( ! ( typeof index === "object" && "fsroot" in index ) ) {
312+ throw new Error ( "Invalid HTTPRequest FS object." ) ;
313+ }
314+
315+ const {
316+ FileSystem : { HTTPRequest } ,
317+ } = ( await import (
318+ "public/System/BrowserFS/browserfs.min.js"
319+ ) ) as typeof IBrowserFS ;
320+
321+ return new Promise ( ( resolve , reject ) => {
322+ HTTPRequest ?. Create (
323+ { baseUrl, index : parseDirectory ( index . fsroot as FS9PV4 [ ] ) } ,
324+ ( error , newFs ) => {
325+ if ( error || ! newFs ) {
326+ reject ( new Error ( "Error while mounting HTTPRequest FS." ) ) ;
327+ } else {
328+ rootFs ?. mount ?.( mountPoint , newFs ) ;
329+ resolve ( ) ;
330+ }
331+ }
332+ ) ;
333+ } ) ;
334+ } ,
335+ [ rootFs ]
336+ ) ;
296337 const mapFs = useCallback (
297338 async (
298339 directory : string ,
@@ -658,6 +699,7 @@ const useFileSystemContextState = (): FileSystemContextState => {
658699 mkdirRecursive,
659700 mountEmscriptenFs,
660701 mountFs,
702+ mountHttpRequestFs,
661703 moveEntries,
662704 pasteList,
663705 removeFsWatcher,
0 commit comments