mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 00:20:05 +01:00
This commit is contained in:
parent
2141ea7781
commit
66b7a509e8
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,6 +9,7 @@ test-results
|
|||
playwright-report
|
||||
playwright/.cache
|
||||
|
||||
public/private
|
||||
public/robots.txt
|
||||
public/rss.xml
|
||||
public/sitemap.xml
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ const useCommandInterpreter = (
|
|||
lstat,
|
||||
mapFs,
|
||||
mkdirRecursive,
|
||||
mountHttpRequestFs,
|
||||
readdir,
|
||||
readFile,
|
||||
rename,
|
||||
|
|
@ -680,8 +681,27 @@ const useCommandInterpreter = (
|
|||
}
|
||||
}
|
||||
break;
|
||||
case "mount":
|
||||
if (isFileSystemMappingSupported()) {
|
||||
case "mount": {
|
||||
const [mountPoint, url, baseUrl] = commandArgs;
|
||||
|
||||
if (mountPoint && url) {
|
||||
try {
|
||||
await mountHttpRequestFs(
|
||||
mountPoint,
|
||||
url,
|
||||
baseUrl === "/" ? undefined : baseUrl || mountPoint
|
||||
);
|
||||
|
||||
const basePath = dirname(mountPoint);
|
||||
|
||||
updateFolder(
|
||||
basePath === "." ? "/" : basePath,
|
||||
basename(mountPoint)
|
||||
);
|
||||
} catch (error) {
|
||||
printLn(error);
|
||||
}
|
||||
} else if (isFileSystemMappingSupported()) {
|
||||
try {
|
||||
const mappedFolder = await mapFs(cd.current);
|
||||
|
||||
|
|
@ -700,6 +720,7 @@ const useCommandInterpreter = (
|
|||
printLn(COMMAND_NOT_SUPPORTED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "move":
|
||||
case "mv":
|
||||
case "ren":
|
||||
|
|
@ -1255,6 +1276,7 @@ const useCommandInterpreter = (
|
|||
lstat,
|
||||
mapFs,
|
||||
mkdirRecursive,
|
||||
mountHttpRequestFs,
|
||||
open,
|
||||
processesRef,
|
||||
readFile,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import index from "public/.index/fs.9p.json";
|
|||
import {
|
||||
FS_HANDLES,
|
||||
MOUNTABLE_EXTENSIONS,
|
||||
MOUNTABLE_FS_TYPES,
|
||||
ONE_TIME_PASSIVE_EVENT,
|
||||
} from "utils/constants";
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ type FS9PV3 = [
|
|||
number,
|
||||
FS9PV3[] | string,
|
||||
];
|
||||
type FS9PV4 = [string, number, number, FS9PV4[] | undefined];
|
||||
export type FS9PV4 = [string, number, number, FS9PV4[] | undefined];
|
||||
type FS9P = {
|
||||
fsroot: FS9PV3[];
|
||||
size: number;
|
||||
|
|
@ -76,7 +77,7 @@ export const get9pModifiedTime = (path: string): number =>
|
|||
|
||||
export const get9pSize = (path: string): number => get9pData(path, IDX_SIZE);
|
||||
|
||||
const parseDirectory = (array: FS9PV4[]): BFSFS => {
|
||||
export const parseDirectory = (array: FS9PV4[]): BFSFS => {
|
||||
const directory: BFSFS = {};
|
||||
|
||||
// eslint-disable-next-line unicorn/no-unreadable-array-destructuring
|
||||
|
|
@ -201,7 +202,7 @@ export const getFileSystemHandles = async (): Promise<FileSystemHandles> => {
|
|||
|
||||
export const isMountedFolder = (mount?: Mount): boolean =>
|
||||
typeof mount === "object" &&
|
||||
(mount.getName() === "FileSystemAccess" ||
|
||||
(MOUNTABLE_FS_TYPES.has(mount.getName()) ||
|
||||
(mount as ExtendedEmscriptenFileSystem)._FS?.DB_STORE_NAME === "FILE_DATA");
|
||||
|
||||
export const getMountUrl = (
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ import {
|
|||
getFileSystemHandles,
|
||||
hasIndexedDB,
|
||||
isMountedFolder,
|
||||
parseDirectory,
|
||||
KEYVAL_DB,
|
||||
type FS9PV4,
|
||||
} from "contexts/fileSystem/core";
|
||||
import useAsyncFs, {
|
||||
type AsyncFS,
|
||||
|
|
@ -103,6 +105,11 @@ type FileSystemContextState = AsyncFS & {
|
|||
mkdirRecursive: (path: string) => Promise<void>;
|
||||
mountEmscriptenFs: (FS: EmscriptenFS, fsName?: string) => Promise<string>;
|
||||
mountFs: (url: string) => Promise<void>;
|
||||
mountHttpRequestFs: (
|
||||
mountPoint: string,
|
||||
url: string,
|
||||
baseUrl?: string
|
||||
) => Promise<void>;
|
||||
moveEntries: (entries: string[]) => void;
|
||||
pasteList: FilePasteOperations;
|
||||
removeFsWatcher: (folder: string, updateFiles: UpdateFiles) => void;
|
||||
|
|
@ -293,6 +300,40 @@ const useFileSystemContextState = (): FileSystemContextState => {
|
|||
}),
|
||||
[rootFs]
|
||||
);
|
||||
const mountHttpRequestFs = useCallback(
|
||||
async (
|
||||
mountPoint: string,
|
||||
url: string,
|
||||
baseUrl?: string
|
||||
): Promise<void> => {
|
||||
const index = (await (await fetch(url)).json()) as object;
|
||||
|
||||
if (!(typeof index === "object" && "fsroot" in index)) {
|
||||
throw new Error("Invalid HTTPRequest FS object.");
|
||||
}
|
||||
|
||||
const {
|
||||
FileSystem: { HTTPRequest },
|
||||
} = (await import(
|
||||
"public/System/BrowserFS/browserfs.min.js"
|
||||
)) as typeof IBrowserFS;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
HTTPRequest?.Create(
|
||||
{ baseUrl, index: parseDirectory(index.fsroot as FS9PV4[]) },
|
||||
(error, newFs) => {
|
||||
if (error || !newFs) {
|
||||
reject(new Error("Error while mounting HTTPRequest FS."));
|
||||
} else {
|
||||
rootFs?.mount?.(mountPoint, newFs);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
[rootFs]
|
||||
);
|
||||
const mapFs = useCallback(
|
||||
async (
|
||||
directory: string,
|
||||
|
|
@ -658,6 +699,7 @@ const useFileSystemContextState = (): FileSystemContextState => {
|
|||
mkdirRecursive,
|
||||
mountEmscriptenFs,
|
||||
mountFs,
|
||||
mountHttpRequestFs,
|
||||
moveEntries,
|
||||
pasteList,
|
||||
removeFsWatcher,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@
|
|||
"scripts": {
|
||||
"build": "yarn build:prebuild && next build",
|
||||
"build:bundle-analyzer": "yarn build",
|
||||
"build:fs": "node scripts/fs2json.js --exclude .index --out public/.index/fs.9p.json ./public",
|
||||
"build:fs:private": "node scripts/fs2json.js --out public/.index/fs.private.9p.json ./public/private",
|
||||
"build:fs:public": "node scripts/fs2json.js --exclude .index,private --out public/.index/fs.9p.json ./public",
|
||||
"build:minify": "node scripts/minifyHtml.js && node scripts/minifyJs.js",
|
||||
"build:prebuild": "node scripts/robots.js && node scripts/rssBuilder.js && node scripts/searchIndex.js && node scripts/preloadIcons.js && node scripts/cacheShortcuts.js && yarn build:fs",
|
||||
"build:prebuild": "node scripts/robots.js && node scripts/rssBuilder.js && node scripts/searchIndex.js && node scripts/preloadIcons.js && node scripts/cacheShortcuts.js && yarn build:fs:public",
|
||||
"docker:build": "docker build -t daedalos .",
|
||||
"docker:run": "docker run -dp 3000:3000 --rm --name daedalos daedalos",
|
||||
"dev": "next dev",
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ const IDX_TARGET = 3;
|
|||
|
||||
const args = process.argv.slice(2);
|
||||
const argPath = resolvePath(args[args.length - 1]);
|
||||
const excludedPaths = [];
|
||||
let excludedPaths = [];
|
||||
let outputPath = "";
|
||||
|
||||
args.forEach((arg, index) => {
|
||||
if (arg === "--exclude") excludedPaths.push(args[index + 1]);
|
||||
if (arg === "--exclude") excludedPaths = args[index + 1].split(",");
|
||||
if (arg === "--out") outputPath = resolvePath(args[index + 1]);
|
||||
});
|
||||
|
||||
|
|
@ -43,9 +43,10 @@ const fs2json = (dir) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const includedFiles = files.filter(
|
||||
(file) => !excludedPaths.includes(file)
|
||||
);
|
||||
const includedFiles =
|
||||
dir === walkDir
|
||||
? files.filter((file) => !excludedPaths.includes(file))
|
||||
: files;
|
||||
|
||||
const recur = () => {
|
||||
const file = includedFiles.shift();
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ export const ZIP_EXTENSIONS = new Set([".jsdos", ".pk3", ".wsz", ".zip"]);
|
|||
|
||||
export const MOUNTABLE_EXTENSIONS = new Set([".iso", ...ZIP_EXTENSIONS]);
|
||||
|
||||
export const MOUNTABLE_FS_TYPES = new Set(["FileSystemAccess", "HTTPRequest"]);
|
||||
|
||||
export const SPREADSHEET_FORMATS = [
|
||||
".csv",
|
||||
".numbers",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user