Skip to content

Commit 924a3f0

Browse files
committed
I'm crushing your head!
1 parent 3d5db86 commit 924a3f0

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

coms/net/fs.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ LOTW_FS: {
4343
cur_session_id: {
4444
'.validate": "newData.isString() && newData.val().length >= 4"
4545
},
46+
next_node_id: {
47+
},
4648
nodes: {
4749
".indexOn" = ["parId", "path"],
4850
"$nodeId": {
@@ -103,20 +105,14 @@ OTHER_NS: {
103105
Also: Let's await on update.
104106
»*/
105107

106-
/*10/6/25: Persistent session ids«
108+
/*10/6/25: Persistent session ids, create_new_file() example«
107109
108110
Let's do persistent 24 bit session ids (4 chars, ~16M possible). This is instead of
109111
jumping through all the hoops of constantly changing them. Only upon the first
110112
usage of the database in a client instance (local database initialization) do
111113
we need to secure a unique id. We just need to keep a little bit of local
112114
state, such as an object in e.g. APPDATA_PATH/netfs/sid.
113115
114-
Now we can do these 2 operations in a row, wrapped in a Promise:
115-
1) get_next_id
116-
2) increment_next_id
117-
118-
We know that if another session id is set between these 2 steps, then
119-
increment_next_id won't work, and we won't have any gaps in the ids.
120116
121117
const SESS_ID_BYTE_LEN = 3; // 4 ascii chars long
122118
const get_sess_id = () => {
@@ -127,6 +123,44 @@ let sess_id = (crypto.getRandomValues(new Uint8Array(SESS_ID_BYTE_LEN))).toBase6
127123
return sess_id;
128124
};
129125
126+
127+
Now we can do these 2 operations in a row, wrapped in a Promise:
128+
1) get_next_id
129+
2) increment_next_id
130+
131+
We know that if another session id is set between these 2 steps, then
132+
increment_next_id won't work, and we won't have any gaps in the ids.
133+
134+
Or increment_next_id rather gets put into an update operation, which creates a new
135+
node:
136+
137+
const create_new_file = async (par_id, name, bytes) => {
138+
139+
let node_id = await get_next_node_id(); // Use this as the blob_id: they're in different "tables"
140+
let update_obj = {
141+
nodes: {
142+
[node_id]: {
143+
type: "f",
144+
parId: par_id,
145+
blobId: node_id,
146+
path: `${par_id}/${name}`
147+
}
148+
},
149+
blobs: {
150+
[node_id]: {
151+
contents: bytes.toBase64(),
152+
meta: {
153+
//...
154+
}
155+
}
156+
},
157+
next_node_id: increment(1)
158+
};
159+
await update("/$ghid", update_obj); // If this fails, no incrementing is done
160+
161+
};
162+
163+
130164
»*/
131165
/*10/5/25: Session ids«
132166
Let's get a crypto-secure 24bit value as Base64 (4 ascii characters), and call set_session

list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["README.md/2181","app",["3d",["index.html/1098"]],"apps",["Audio.js/4093","BinView.js/9814","Folder.js/11255","Help.js/979","MediaPlayer.js/2074","Music.js/4844","Terminal.js/100824","TextEdit.js/5301","WorkMan.js/3808","YourApp.js/418","dev",["GetPoint.js/551","Grok.js/14796","Poker.js/36551","Three.js/5119"],"games",["Arcade.js/12602"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/61912"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["HTML.js/1428","ImageView.js/2703","Unicoder.js/16896"]],"coms",["audio.js/1766","esprima.js/171872","extra.js/11295","fs.js/28722","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44068","net",["fs.js/45041"],"shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/2026","yt.js/66863","zhold",["mail.js/22724"]],"desk",["index.html/1436"],"index.html/486","login",["index.html/11711"],"mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9655","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"lang",["shell.js/185316"],"term",["email.js/10406","less.js/19318","log.js/13292","vim.js/162926"],"util",["libwabt.js/1299054","math.js/12125","pretty.js/93856","showdown.js/87205","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7969","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"shell",["index.html/1211"],"sys",["config.js/9931","desk.js/219678","fs.js/72746","terminal.js/4307","three.js/3443","util.js/33015"],"www",["blog.css/181","desk.css/1831","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]]]
1+
["README.md/2181","app",["3d",["index.html/1098"]],"apps",["Audio.js/4093","BinView.js/9814","Folder.js/11255","Help.js/979","MediaPlayer.js/2074","Music.js/4844","Terminal.js/100824","TextEdit.js/5301","WorkMan.js/3808","YourApp.js/418","dev",["GetPoint.js/551","Grok.js/14796","Poker.js/36551","Three.js/5119"],"games",["Arcade.js/12602"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/61912"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["HTML.js/1428","ImageView.js/2703","Unicoder.js/16896"]],"coms",["audio.js/1766","esprima.js/171872","extra.js/11295","fs.js/28722","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44068","net",["fs.js/45698"],"shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/2026","yt.js/66863","zhold",["mail.js/22724"]],"desk",["index.html/1436"],"index.html/486","login",["index.html/11711"],"mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9655","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"lang",["shell.js/185316"],"term",["email.js/10406","less.js/19318","log.js/13292","vim.js/162926"],"util",["libwabt.js/1299054","math.js/12125","pretty.js/93856","showdown.js/87205","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7969","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"shell",["index.html/1211"],"sys",["config.js/9931","desk.js/219678","fs.js/72746","terminal.js/4307","three.js/3443","util.js/33015"],"www",["blog.css/181","desk.css/1831","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]]]

0 commit comments

Comments
 (0)