move library into rfwfs and rename root.ts to fs.ts, also place it outside of rfwfs

This commit is contained in:
2025-03-17 17:46:55 -04:00
parent 332e90d023
commit 929b267f23
3 changed files with 49 additions and 32 deletions

View File

@ -1,6 +1,6 @@
import { Permissions } from "../enum" import { Permissions } from "./rfwfs/enum"
import rfwfs from "../main" import rfwfs from "./rfwfs/main"
const time_now = (Date.now()/1000)|0 const time_now = (Date.now()/1000)|0

View File

@ -1,30 +0,0 @@
import { ReadStatus } from "../enum"
import rfwfs, { type EntryCollection, type Entry } from "../main"
import fs from "./root"
let username: string = "user"
const libhome = {} as LibHome
interface WorkingDir<T extends Entry> {
entry?: EntryCollection<T>,
path: string[]
}
interface LibHome {
path: () => string[],
get: <T extends Entry>() => EntryCollection<T>,
}
function traverse_to_goal(path: string[]) {
if (working_dir.entry) {
}
}
libhome.path = function() {
return ["home", username]
}
libhome.get = function() {
}

47
src/rt/rfwfs/library.ts Normal file
View File

@ -0,0 +1,47 @@
import { ReadStatus } from "./enum"
import { wrap_entry, type WrapResultEntry } from "./wrap"
import rfwfs, { type DirectoryDepth, type Directory } from "./main"
import fs from "../fs"
type Path = string[]
interface LibHome {
goal: (path: Path) => WrapResultEntry<Directory, ReadStatus>
path: () => Path,
get: () => Directory | undefined,
}
let username: string = "user"
const libhome = {} as LibHome
libhome.goal = function(path) {
let traverse = fs
for (const path_name of path) {
const find = traverse.inner.find(path_name)
if (find.status === ReadStatus.Ok) {
if (find.result && rfwfs.is_dir(find.result)) {
traverse = find.result as DirectoryDepth
} else {
return wrap_entry(ReadStatus.Denied)
}
} else {
return wrap_entry(find.status)
}
}
return wrap_entry(ReadStatus.Ok, traverse)
}
libhome.path = function() {
return ["home", username]
}
libhome.get = function() {
const traverse = this.goal(this.path())
return traverse.status === ReadStatus.Ok ? traverse.result : undefined
}
export default libhome