Compare commits
29 Commits
ejs
...
rfwfs-clas
Author | SHA1 | Date | |
---|---|---|---|
e612f5762f | |||
d4278d0d7f | |||
26a7d4c21c | |||
305c2bd2cd | |||
c66a0eb4a9 | |||
caedb7e8f0 | |||
050c0f1aca | |||
d7abe20d1a | |||
1d3b80515b | |||
3f48a19b22 | |||
74e3d5df60 | |||
9d0b12b47c | |||
e8645d4f64 | |||
fc0ef23bdb | |||
7a457e5205 | |||
6b129045e8 | |||
cec5642e70 | |||
5b74400a10 | |||
384e70e286 | |||
3aaedf1e8b | |||
17e89ef1c8 | |||
aa6f8b6f8e | |||
d80887d281 | |||
9eba512580 | |||
8469c015f8 | |||
b3fa561c76 | |||
b7babb665e | |||
9856b138df | |||
c2ac2ba28c |
@ -11,8 +11,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sass": "^1.85.1",
|
"sass": "^1.85.1",
|
||||||
"typescript": "^5.8.2",
|
"typescript": "^5.8.2",
|
||||||
"vite": "^6.2.0",
|
"vite": "^6.2.2",
|
||||||
"vite-plugin-html": "^3.2.2",
|
"vite-plugin-html": "^3.2.2"
|
||||||
"vite-plugin-ejs": "^1.7.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +0,0 @@
|
|||||||
<p class="raw-text" id="time">00:00:00</p>
|
|
||||||
<section>
|
|
||||||
<p class="raw-text" id="column-line">0, 0</p>
|
|
||||||
<button id="toggle-monospace">Monospace</button>
|
|
||||||
<button id="toggle-term-mode">UNIX</button>
|
|
||||||
</section>
|
|
||||||
<noscript>
|
|
||||||
<style>
|
|
||||||
#toggle-monospace, .raw-text { display: none }
|
|
||||||
</style>
|
|
||||||
</noscript>
|
|
@ -1,14 +0,0 @@
|
|||||||
<button class="header-left">
|
|
||||||
<a href="https://rhpidfyre.io/" class="header-button">[rhpidfyre.io]</a>
|
|
||||||
</button>
|
|
||||||
<section class="header-right">
|
|
||||||
<button>
|
|
||||||
<a href="https://git.rhpidfyre.io/" class="header-button">GIT</a>
|
|
||||||
</button>
|
|
||||||
<button>
|
|
||||||
<a href="https://files.rhpidfyre.io/" class="header-button">CLOUD</a>
|
|
||||||
</button>
|
|
||||||
<button>
|
|
||||||
<a href="https://gsm.rhpidfyre.io/" class="header-button">GSM</a>
|
|
||||||
</button>
|
|
||||||
</section>
|
|
@ -1,17 +0,0 @@
|
|||||||
<p>Welcome to rhpidfyre.io!</p>
|
|
||||||
<div class="return"></div>
|
|
||||||
<p>This is a personal website by rhpidfyre / Brandon.</p>
|
|
||||||
<p>You can find my services here or learn about me.</p>
|
|
||||||
<div class="return"></div>
|
|
||||||
<p>You can also contribute or view the source code of my website via the links:</p>
|
|
||||||
<p><<a href="https://git.rhpidfyre.io/rhpidfyre/rhpidfyre.io" target="_blank">https://git.rhpidfyre.io/rhpidfyre/rhpidfyre.io</a>>.</p>
|
|
||||||
<p><<a href="https://github.com/unixtensor/rhpidfyre.io" target="_blank">https://github.com/unixtensor/rhpidfyre.io</a>>.</p>
|
|
||||||
<div class="return"></div>
|
|
||||||
<p>You can get started with the command: <span class="bold">help</span></p>
|
|
||||||
<div class="return"></div>
|
|
||||||
<noscript>
|
|
||||||
<p><span class="red">=================================================</span></p>
|
|
||||||
<p><span class="red">JavaScript is disabled, functionality will be limited. :(</span></p>
|
|
||||||
<p><span class="red">But, you will not be limited at exploring my services which you can find by navigating towards the top-right.</span></p>
|
|
||||||
<p><span class="red">=================================================</span></p>
|
|
||||||
</noscript>
|
|
@ -1,22 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width"/>
|
|
||||||
<link rel="icon" type="image/png" href="/logo.png"/>
|
|
||||||
<link rel="stylesheet" href="./scss/global.scss"/>
|
|
||||||
<title>rhpidfyre.io</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<header>
|
|
||||||
<%- inlineHtml("header") %>
|
|
||||||
</header>
|
|
||||||
<main>
|
|
||||||
<%- inlineHtml("motd") %>
|
|
||||||
</main>
|
|
||||||
<footer>
|
|
||||||
<%- inlineHtml("footer") %>
|
|
||||||
</footer>
|
|
||||||
<script type="module" src="./rt/emulator/terminal.ts"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
61
src/index.html
Normal file
61
src/index.html
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<link rel="icon" type="image/png" href="/logo.png"/>
|
||||||
|
<link rel="stylesheet" href="./scss/global.scss"/>
|
||||||
|
<title>rhpidfyre.io</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<button class="header-left">
|
||||||
|
<a href="https://rhpidfyre.io/" class="header-button">[rhpidfyre.io]</a>
|
||||||
|
</button>
|
||||||
|
<section class="header-right">
|
||||||
|
<button>
|
||||||
|
<a href="https://git.rhpidfyre.io/" class="header-button">GIT</a>
|
||||||
|
</button>
|
||||||
|
<button>
|
||||||
|
<a href="https://files.rhpidfyre.io/" class="header-button">CLOUD</a>
|
||||||
|
</button>
|
||||||
|
<button>
|
||||||
|
<a href="https://gsm.rhpidfyre.io/" class="header-button">GSM</a>
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<p>Welcome to rhpidfyre.io!</p>
|
||||||
|
<div class="return"></div>
|
||||||
|
<p>This is a personal website by rhpidfyre / Brandon.</p>
|
||||||
|
<p>You can find my services here or learn about me.</p>
|
||||||
|
<div class="return"></div>
|
||||||
|
<p>You can also contribute or view the source code of my website via the links:</p>
|
||||||
|
<p><<a href="https://git.rhpidfyre.io/rhpidfyre/rhpidfyre.io" target="_blank">https://git.rhpidfyre.io/rhpidfyre/rhpidfyre.io</a>>.</p>
|
||||||
|
<p><<a href="https://github.com/unixtensor/rhpidfyre.io" target="_blank">https://github.com/unixtensor/rhpidfyre.io</a>>.</p>
|
||||||
|
<div class="return"></div>
|
||||||
|
<p>You can get started with the command: <span class="bold">help</span></p>
|
||||||
|
<div class="return"></div>
|
||||||
|
<noscript>
|
||||||
|
<p><span class="red">=================================================</span></p>
|
||||||
|
<p><span class="red">JavaScript is disabled, functionality will be limited. :(</span></p>
|
||||||
|
<p><span class="red">But, you will not be limited at exploring my services which you can find by navigating towards the top-right.</span></p>
|
||||||
|
<p><span class="red">=================================================</span></p>
|
||||||
|
</noscript>
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
<p class="raw-text" id="time">00:00:00</p>
|
||||||
|
<section>
|
||||||
|
<p class="raw-text" id="column-line">0, 0</p>
|
||||||
|
<button id="toggle-monospace">Monospace</button>
|
||||||
|
<button id="toggle-term-mode">UNIX</button>
|
||||||
|
</section>
|
||||||
|
<noscript>
|
||||||
|
<style>
|
||||||
|
#toggle-monospace, .raw-text { display: none }
|
||||||
|
</style>
|
||||||
|
</noscript>
|
||||||
|
</footer>
|
||||||
|
<script type="module" src="./rt/emulator/terminal.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,46 +0,0 @@
|
|||||||
import { type Entry } from "./main"
|
|
||||||
|
|
||||||
import entry_search from "./index"
|
|
||||||
|
|
||||||
type Files<T> = Entry<T>[]
|
|
||||||
|
|
||||||
interface EntryCollectionManipulate {
|
|
||||||
pop: <T extends Entry<T>>(file_name: string) => Entry<T> | undefined,
|
|
||||||
get: <T extends Entry<T>>(file_name: string) => Entry<T> | undefined
|
|
||||||
push: <T extends Entry<T>>(entry: Entry<T>) => boolean,
|
|
||||||
sort: () => void,
|
|
||||||
}
|
|
||||||
interface EntryCollection<T> extends EntryCollectionManipulate {
|
|
||||||
readonly inner: Files<T>
|
|
||||||
}
|
|
||||||
|
|
||||||
function entry_trait<T extends Entry<T>>() {
|
|
||||||
const trait = {} as EntryCollection<T>
|
|
||||||
trait.sort = function() {
|
|
||||||
this.inner.sort((a,z) => a.name.localeCompare(z.name))
|
|
||||||
}
|
|
||||||
trait.push = function(entry) {
|
|
||||||
const no_duplicates = entry_search(this.inner, entry.name)
|
|
||||||
if (!no_duplicates) {
|
|
||||||
this.push(entry)
|
|
||||||
this.sort()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
trait.pop = function(file_name) {
|
|
||||||
const file_search = entry_search(this.inner, file_name)
|
|
||||||
if (file_search) {
|
|
||||||
this.inner.splice(file_search.index, 1)
|
|
||||||
return file_search.result
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return trait
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
entry_trait,
|
|
||||||
type EntryCollection,
|
|
||||||
type Files,
|
|
||||||
}
|
|
47
src/rt/rfwfs/enum.ts
Normal file
47
src/rt/rfwfs/enum.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
type ConstEnum = number
|
||||||
|
|
||||||
|
const enum EntryType {
|
||||||
|
Directory,
|
||||||
|
Binary,
|
||||||
|
File,
|
||||||
|
}
|
||||||
|
const enum Permissions {
|
||||||
|
r,
|
||||||
|
w,
|
||||||
|
rw,
|
||||||
|
none,
|
||||||
|
}
|
||||||
|
const enum PermissionsBinary {
|
||||||
|
r,
|
||||||
|
w,
|
||||||
|
x,
|
||||||
|
rw,
|
||||||
|
rwx,
|
||||||
|
rx,
|
||||||
|
wx,
|
||||||
|
none,
|
||||||
|
}
|
||||||
|
const enum PushStatus {
|
||||||
|
Ok,
|
||||||
|
Duplicate,
|
||||||
|
Denied,
|
||||||
|
}
|
||||||
|
const enum ReadStatus {
|
||||||
|
Ok,
|
||||||
|
NotFound,
|
||||||
|
Denied,
|
||||||
|
}
|
||||||
|
const enum Result {
|
||||||
|
None,
|
||||||
|
Ok,
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
type ConstEnum,
|
||||||
|
PermissionsBinary,
|
||||||
|
Permissions,
|
||||||
|
PushStatus,
|
||||||
|
ReadStatus,
|
||||||
|
EntryType,
|
||||||
|
Result,
|
||||||
|
}
|
41
src/rt/rfwfs/fs/root.ts
Normal file
41
src/rt/rfwfs/fs/root.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { Permissions } from "../enum"
|
||||||
|
|
||||||
|
import rfwfs from "../main"
|
||||||
|
|
||||||
|
const time_now = (Date.now()/1000)|0
|
||||||
|
|
||||||
|
// ------------ Home ------------
|
||||||
|
const config = rfwfs.directory(".config", Permissions.rw, time_now)
|
||||||
|
const local = rfwfs.directory(".local", Permissions.rw, time_now)
|
||||||
|
const downloads = rfwfs.directory("Downloads", Permissions.rw, time_now)
|
||||||
|
const pictures = rfwfs.directory("Pictures", Permissions.rw, time_now)
|
||||||
|
const desktop = rfwfs.directory("Desktop", Permissions.rw, time_now)
|
||||||
|
const videos = rfwfs.directory("Videos", Permissions.rw, time_now)
|
||||||
|
const music = rfwfs.directory("Music", Permissions.rw, time_now)
|
||||||
|
|
||||||
|
const user = rfwfs.directory("user", Permissions.r, time_now, [
|
||||||
|
config,
|
||||||
|
local,
|
||||||
|
downloads,
|
||||||
|
pictures,
|
||||||
|
videos,
|
||||||
|
music,
|
||||||
|
desktop,
|
||||||
|
])
|
||||||
|
|
||||||
|
// /home/
|
||||||
|
const home = rfwfs.directory("home", Permissions.r, time_now, [user])
|
||||||
|
// ------------
|
||||||
|
|
||||||
|
// ------------ root ------------
|
||||||
|
const bin = rfwfs.directory("bin", Permissions.r, time_now)
|
||||||
|
const vard = rfwfs.directory("var", Permissions.r, time_now)
|
||||||
|
const etc = rfwfs.directory("etc", Permissions.r, time_now)
|
||||||
|
// ------------
|
||||||
|
|
||||||
|
export default rfwfs.directory("/", Permissions.r, time_now, [
|
||||||
|
bin,
|
||||||
|
home,
|
||||||
|
vard,
|
||||||
|
etc,
|
||||||
|
])
|
11
src/rt/rfwfs/hash.ts
Normal file
11
src/rt/rfwfs/hash.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
async function hash(inner_as_string: string) {
|
||||||
|
const encoder = new TextEncoder()
|
||||||
|
const hash = await crypto.subtle.digest("SHA-256", encoder.encode(inner_as_string))
|
||||||
|
const hash_as_uint8 = new Uint8Array(hash)
|
||||||
|
return Array.from(hash_as_uint8).map(byte => byte.toString(16).padStart(2, "0")).join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function generate_sha256(inner_as_string: string) {
|
||||||
|
const sha256 = await hash(inner_as_string)
|
||||||
|
return sha256
|
||||||
|
}
|
@ -1,23 +1,15 @@
|
|||||||
import { type Entry } from "./main"
|
import { type Entry } from "./main"
|
||||||
import { type Files } from "./collection"
|
import { wrap_bsearch, type WrapBSearch } from "./wrap"
|
||||||
|
|
||||||
interface SearchResult<T> {
|
export default function directory_search<T extends Entry>(entry_collection: T[], file_name: string): WrapBSearch<T> | undefined {
|
||||||
readonly result: T,
|
|
||||||
readonly index: number
|
|
||||||
}
|
|
||||||
function wrap_result<T>(result: T, index: number): SearchResult<T> {
|
|
||||||
return { result: result, index: index }
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function entry_search<T>(cloned_file_collection: Files<T>, file_name: string): SearchResult<Entry<T>> | undefined {
|
|
||||||
let start = 0
|
let start = 0
|
||||||
let end = cloned_file_collection.length-1
|
let end = entry_collection.length-1
|
||||||
while (start<=end) {
|
while (start<=end) {
|
||||||
const median = (start+end)>>1
|
const median = (start+end)>>1
|
||||||
const median_name = cloned_file_collection[median].name
|
const median_name = entry_collection[median].name
|
||||||
|
|
||||||
if (median_name == file_name) { //left == right && (T == U) is not necessary
|
if (median_name === file_name) {
|
||||||
return wrap_result(cloned_file_collection[median], median)
|
return wrap_bsearch(median, entry_collection[median])
|
||||||
} else if (median_name<file_name) {
|
} else if (median_name<file_name) {
|
||||||
start = median+1
|
start = median+1
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,47 +1,168 @@
|
|||||||
import { type EntryCollection } from "./collection"
|
import { EntryType, PushStatus, ReadStatus, Permissions, ConstEnum, PermissionsBinary } from "./enum"
|
||||||
|
import { wrap_entry, wrap_none, WrapResultEntry, WrapResultNone } from "./wrap"
|
||||||
|
|
||||||
const enum EntryType {
|
import directory_search from "./index"
|
||||||
Directory,
|
|
||||||
File
|
|
||||||
}
|
|
||||||
const enum Permissions {
|
|
||||||
r,
|
|
||||||
w,
|
|
||||||
rw,
|
|
||||||
none
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Entry<T> {
|
type FileInner = string | number
|
||||||
readonly name: string,
|
|
||||||
|
interface Entry {
|
||||||
|
permissions: Permissions,
|
||||||
|
timestamp: EntryValue<number>,
|
||||||
|
name: EntryValue<string>,
|
||||||
readonly type: EntryType,
|
readonly type: EntryType,
|
||||||
readonly inner: T,
|
|
||||||
readonly timestamp: number,
|
|
||||||
readonly collection?: EntryCollection<T>,
|
|
||||||
readonly permissions: Permissions,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EntryFile extends Entry {
|
||||||
|
inner: EntryValue<FileInner>,
|
||||||
|
hash: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EntryCollection<T extends Entry> extends Entry {
|
||||||
|
inner: RfwfsDirectory<T>,
|
||||||
|
}
|
||||||
|
|
||||||
interface Rfwfs {
|
interface Rfwfs {
|
||||||
new_entry: <T extends Entry<T>>(name: string, permissions: Permissions, timestamp: number, inner: T) => Entry<T>,
|
directory: <T extends Entry>(default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: T[]) => EntryCollection<T>,
|
||||||
entry_trait: <T extends Entry<T>>(inner: T) => EntryCollection<T>
|
file: (default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: FileInner) => EntryFile,
|
||||||
new_entry_tree: <T>(files: T) => T,
|
is_binary: <T extends Entry>(entry: T) => boolean,
|
||||||
|
is_file: <T extends Entry>(entry: T) => boolean,
|
||||||
|
is_dir: <T extends Entry>(entry: T) => boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute_access<P extends ConstEnum>(permissions: P): boolean {
|
||||||
|
return permissions === PermissionsBinary.rwx
|
||||||
|
|| permissions === PermissionsBinary.rx
|
||||||
|
|| permissions === PermissionsBinary.wx
|
||||||
|
|| permissions === PermissionsBinary.x
|
||||||
|
}
|
||||||
|
function read_write_access<P extends ConstEnum>(permissions: P): boolean {
|
||||||
|
return permissions === Permissions.rw
|
||||||
|
}
|
||||||
|
function read_access<P extends ConstEnum>(permissions: P): boolean {
|
||||||
|
return read_write_access(permissions) || permissions === Permissions.r
|
||||||
|
}
|
||||||
|
function write_access<P extends ConstEnum>(permissions: P): boolean {
|
||||||
|
return read_write_access(permissions) || permissions === Permissions.w
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntryValue<T> {
|
||||||
|
public inner: T;
|
||||||
|
protected entry: Entry
|
||||||
|
|
||||||
|
constructor(entry: Entry, inner_default: T) {
|
||||||
|
this.inner = inner_default
|
||||||
|
this.entry = entry
|
||||||
|
}
|
||||||
|
|
||||||
|
public write<I extends T>(item: I): boolean {
|
||||||
|
if (write_access(this.entry.permissions)) {
|
||||||
|
this.inner = item
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
public read(): T | undefined {
|
||||||
|
return read_access(this.entry.permissions) ? this.inner : undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RfwfsDirectory<T extends Entry> {
|
||||||
|
public inner: T[];
|
||||||
|
protected entry: Entry
|
||||||
|
|
||||||
|
constructor(entry: Entry, inner: T[]) {
|
||||||
|
this.inner = inner
|
||||||
|
this.entry = entry
|
||||||
|
}
|
||||||
|
|
||||||
|
public sort() {
|
||||||
|
this.inner.sort((a,z) => a.name.inner.localeCompare(z.name.inner))
|
||||||
|
}
|
||||||
|
|
||||||
|
public clone(file_name: string): WrapResultEntry<T, ReadStatus> {
|
||||||
|
if (read_write_access(this.entry.permissions)) {
|
||||||
|
const clone_find = directory_search(this.inner, file_name)
|
||||||
|
if (clone_find) {
|
||||||
|
return wrap_entry(ReadStatus.Ok, { ...clone_find.result })
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.NotFound)
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.Denied)
|
||||||
|
}
|
||||||
|
|
||||||
|
public find(file_name: string): WrapResultEntry<T, ReadStatus> {
|
||||||
|
if (read_write_access(this.entry.permissions)) {
|
||||||
|
const file_search = directory_search(this.inner, file_name)
|
||||||
|
if (file_search) {
|
||||||
|
return wrap_entry(ReadStatus.Ok, file_search.result)
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.NotFound)
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.Denied)
|
||||||
|
}
|
||||||
|
|
||||||
|
public push<E extends T>(entry: E): WrapResultNone<PushStatus> {
|
||||||
|
if (read_write_access(this.entry.permissions)) {
|
||||||
|
const no_duplicates = directory_search(this.inner, entry.name.inner)
|
||||||
|
if (!no_duplicates) {
|
||||||
|
this.inner.push(entry)
|
||||||
|
this.inner.sort()
|
||||||
|
return wrap_none(PushStatus.Ok)
|
||||||
|
}
|
||||||
|
return wrap_none(PushStatus.Duplicate)
|
||||||
|
}
|
||||||
|
return wrap_none(PushStatus.Denied)
|
||||||
|
}
|
||||||
|
|
||||||
|
public pop(file_name: string): WrapResultEntry<T, ReadStatus> {
|
||||||
|
if (read_write_access(this.entry.permissions)) {
|
||||||
|
const pop_find = directory_search(this.inner, file_name)
|
||||||
|
if (pop_find) {
|
||||||
|
this.inner.splice(pop_find.some, 1)
|
||||||
|
return wrap_entry(ReadStatus.Ok, pop_find.result)
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.NotFound)
|
||||||
|
}
|
||||||
|
return wrap_entry(ReadStatus.Denied)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rfwfs = {} as Rfwfs
|
const rfwfs = {} as Rfwfs
|
||||||
|
|
||||||
rfwfs.new_entry = function(name, permissions, timestamp, inner) {
|
rfwfs.is_dir = function(entry) {
|
||||||
const file_type = typeof inner == "object" ? EntryType.Directory : EntryType.File
|
return entry.type === EntryType.Directory
|
||||||
return {
|
|
||||||
name: name,
|
|
||||||
type: file_type,
|
|
||||||
inner: inner,
|
|
||||||
timestamp: timestamp ? timestamp : Math.floor(Date.now()/1000),
|
|
||||||
collection: file_type === EntryType.Directory ? this.entry_trait(inner) : undefined,
|
|
||||||
permissions: permissions,
|
|
||||||
}
|
}
|
||||||
|
rfwfs.is_file = function(entry) {
|
||||||
|
return entry.type === EntryType.File
|
||||||
|
}
|
||||||
|
rfwfs.is_binary = function(entry) {
|
||||||
|
return entry.type === EntryType.Binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rfwfs.file = function(default_name, default_permissions, default_timestamp, default_inner) {
|
||||||
|
const file = { type: EntryType.File } as EntryFile
|
||||||
|
file.hash = "0"
|
||||||
|
file.permissions = default_permissions
|
||||||
|
file.timestamp = new EntryValue(file, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
|
||||||
|
file.inner = new EntryValue(file, default_inner ? default_inner : "")
|
||||||
|
file.name = new EntryValue(file, default_name)
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
rfwfs.directory = function<T extends Entry>(default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: T[]): EntryCollection<T> {
|
||||||
|
const directory = { type: EntryType.Directory } as EntryCollection<T>
|
||||||
|
directory.permissions = default_permissions
|
||||||
|
directory.timestamp = new EntryValue(directory, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
|
||||||
|
directory.inner = new RfwfsDirectory(directory, default_inner ? default_inner : [])
|
||||||
|
directory.name = new EntryValue(directory, default_name)
|
||||||
|
return directory
|
||||||
|
}
|
||||||
|
|
||||||
|
export default rfwfs
|
||||||
export {
|
export {
|
||||||
EntryType,
|
|
||||||
Permissions,
|
|
||||||
type EntryCollection,
|
type EntryCollection,
|
||||||
|
type FileInner,
|
||||||
|
type EntryFile,
|
||||||
type Entry,
|
type Entry,
|
||||||
}
|
}
|
40
src/rt/rfwfs/wrap.ts
Normal file
40
src/rt/rfwfs/wrap.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Result, type ConstEnum } from "./enum"
|
||||||
|
import { type Entry } from "./main"
|
||||||
|
|
||||||
|
type WrapResultEntry<T extends Entry, U> = WrapResult<T | undefined, U>
|
||||||
|
type WrapBSearch<T extends Entry> = WrapResult<T, number>
|
||||||
|
type WrapResultNone<T> = WrapResult<Result.None, T>
|
||||||
|
|
||||||
|
interface WrapResult<T, U> {
|
||||||
|
/** The resulting value if `U` is a success */
|
||||||
|
readonly result: T,
|
||||||
|
/** Represents some arbitrary extra value, usually a success status */
|
||||||
|
readonly some: U
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrap<T, U>(result: T, some: U): WrapResult<T, U> {
|
||||||
|
return { result: result, some: some }
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrap_bsearch<T extends Entry>(index: number, result: T): WrapBSearch<T> {
|
||||||
|
return wrap(result, index)
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrap_entry<T extends ConstEnum, U extends Entry>(status: T, result?: U): WrapResultEntry<U, T> {
|
||||||
|
return wrap(result, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrap_none<T extends ConstEnum>(status: T): WrapResultNone<T> {
|
||||||
|
return wrap(Result.None, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default wrap
|
||||||
|
export {
|
||||||
|
wrap_bsearch,
|
||||||
|
wrap_entry,
|
||||||
|
wrap_none,
|
||||||
|
type WrapResultEntry,
|
||||||
|
type WrapResultNone,
|
||||||
|
type WrapBSearch,
|
||||||
|
type WrapResult,
|
||||||
|
}
|
@ -1,27 +1,9 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import { createHtmlPlugin } from 'vite-plugin-html'
|
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||||
import { ViteEjsPlugin } from 'vite-plugin-ejs'
|
|
||||||
|
|
||||||
import fs from "fs"
|
|
||||||
import path from "path"
|
|
||||||
|
|
||||||
const html_dir = path.join(__dirname, "src", "html")
|
|
||||||
|
|
||||||
function inlineHtml(html_file_name) {
|
|
||||||
try {
|
|
||||||
const html_path = path.resolve(path.join(html_dir, html_file_name+".html"))
|
|
||||||
return fs.readFileSync(html_path, "utf-8")
|
|
||||||
} catch(read_err) {
|
|
||||||
return "[INLINE-ERROR], "+read_err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
createHtmlPlugin({minify: true}),
|
createHtmlPlugin({minify: true}),
|
||||||
ViteEjsPlugin({
|
|
||||||
inlineHtml: inlineHtml
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
root: "src",
|
root: "src",
|
||||||
build: {
|
build: {
|
||||||
|
Reference in New Issue
Block a user