Skip to content

Commit 1df42a9

Browse files
committed
I'm crushing your head!
1 parent a07ae61 commit 1df42a9

3 files changed

Lines changed: 189 additions & 40 deletions

File tree

coms/net/fs.js

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,27 @@ MOST RECENT:
123123
124124
Also: Let's await on update.
125125
»*/
126-
/*10/16/25: Put 'status' back into the db.
126+
127+
/*10/17/25: Need to export a try_get_kid sort of function so that path_to_node in sys/fs.js
128+
can do the same type of path resolution mechanism as for FS_TYPE nodes.
129+
130+
- getUsersNodeByNameAndPar
131+
132+
So now we should be able to resolve multi-path paths (e.g. /users/guyhar123/dir1/dir2/dir3/dir4/file.txt)
133+
by querying only for the nodes of the constituent directories in the path (dir1, dir2, dir3, dir4),
134+
rather than for their full listings.
135+
136+
We might eventually do a lookup map that associates paths with their node ids.
137+
138+
*/
139+
/*10/16/25: Put 'status' back into the db.«
127140
128141
Now we should integrate everything from 2 days ago with:
129142
- the github login name fetching/storing (use this in the constructor of NetFsDB)
130143
- Set the initial status update along with setting everything else (msg: "hi", time: serverTimestamp())
131144
- Mount the users directory with the same logic as before (query for most recent status updates)
132145
133-
*/
146+
»*/
134147
/*10/15/25: How to discover other user's home directories?«
135148
136149
- Reimplement the (~100 char) status thing, like before?
@@ -699,7 +712,7 @@ await UPDATE(UBASE(), obj);
699712
return sz;
700713

701714
}//»
702-
async getDirList(ghid, parId){
715+
async getDirList(ghid, parId){/*«*/
703716
let ref = REF(`LOTW/${ghid}/nodes`);
704717
let c1 = orderByChild('parId');
705718
let c2 = equalTo(parId);
@@ -715,7 +728,8 @@ return [];
715728
}
716729
return snap.val();
717730

718-
}
731+
}/*»*/
732+
719733
}//»
720734

721735
//Funcs«
@@ -745,11 +759,15 @@ const REF = (path)=> {//«
745759
// if (path) return ref(fbase_db, path);
746760
// return ref(db);
747761
};//»
748-
const GET = async(ref_or_path)=>{//«
749-
750-
if (isStr(ref_or_path)) ref_or_path = ref(fbase_db, ref_or_path);
762+
const GET = async(arg)=>{//«
763+
/*arg might be:
764+
- a string (implicitly means convert it to a ref)
765+
- a ref
766+
- a query (which is a reference together with a list of constraints)
767+
*/
768+
if (isStr(arg)) arg = ref(fbase_db, arg);
751769
try {
752-
return await get(ref_or_path);
770+
return await get(arg);
753771
}
754772
catch(e){
755773
return e;
@@ -832,10 +850,11 @@ const get_statuses=async(opts={minsAgo: DEF_STATS_MINS_AGO, numRecent: DEF_STATS
832850

833851
let start_time = new Date().getTime() - (mins_ago * 60000);
834852
let c1 = orderByChild('time');
835-
let c2 = startAt(start_time);
853+
// let c2 = startAt(start_time);
836854
let c3 = limitToLast(num_recent_stats);
837855
let ref = REF("LOTW/status");
838-
let q = query(ref, c1, c2, c3);
856+
let q = query(ref, c1, c3);
857+
// let q = query(ref, c1, c2, c3);
839858
let snap = await GET(q);
840859
if (isErr(snap)){
841860
return snap;
@@ -883,24 +902,44 @@ let rv = await db.getDirList(ghid, parseInt(parId));
883902
let keys = Object.keys(rv);
884903
let names = [];
885904
let vals = [];
886-
905+
let blobIds = [];
887906
for (let k of keys){
888907
let obj = rv[k];
889908
let name = obj.path.split("/")[1];
890909
let val;
891910
if (obj.type==="d") val = -1;
892911
else val = 0;
912+
blobIds.push(obj.blobId);
893913
names.push(name);
894914
vals.push(val);
895915
}
896916
return {
897917
names: names,
898918
vals: vals,
899-
ids: keys
919+
ids: keys,
920+
blobIds
900921
};
901922

902923
};//»
903924
globals.funcs["netfs.getUserDirList"] = get_user_dir_list;
925+
926+
//const fb_read = async(ghid, parid, name, opts={}) => {
927+
const fb_read = async(ghid, blobId, opts={}) => {
928+
//cwarn(`READ(${ghid}): ${parid}/${name}`);
929+
//log("OPTS", opts);
930+
//log(`GET: /LOTW/${ghid}/blobs/${blobId}`);
931+
932+
let rv = await GET(`LOTW/${ghid}/blobs/${blobId}`);
933+
if (isErr(rv)) return;
934+
let bytes = FROMB64(rv.val().contents);
935+
if (opts.forceText) {
936+
return new TextDecoder().decode(bytes);
937+
}
938+
return bytes;
939+
940+
};
941+
942+
globals.funcs["netfs.fbRead"] = fb_read;
904943
const fb_write = async(path, val, opts={})=> {//«
905944
//This must be a fullpath
906945
cwarn(`WRITE(${path})`);
@@ -1109,9 +1148,53 @@ cwarn(`MKDIR: <${parpath}> <${name}>`);
11091148
return await db.createDirNode(parseInt(parId), name);
11101149

11111150

1112-
};/*»*/
1151+
};/
11131152
globals.funcs["netfs.fbMkdir"] = fb_mkdir;
11141153

1154+
const fb_get_users_node_by_name_and_par = async (name, parnode) => {//«
1155+
// parnode.appData was undefined after mkDir
1156+
//cwarn('PARNODE');
1157+
//log(parnode);
1158+
let ghid = parnode.appData.id;
1159+
let pathname = `${parnode.id}/${name}`;
1160+
log(`GET USER(${ghid}): ${pathname}`);
1161+
let q = query(REF(`/LOTW/${ghid}/nodes`), orderByChild('path'), equalTo(pathname), limitToFirst(1));
1162+
let rv = await GET(q);
1163+
if (isErr(rv)){
1164+
cerr(rv);
1165+
return;
1166+
}
1167+
if (!rv.exists()){
1168+
cwarn("NOT FOUND");
1169+
return;
1170+
}
1171+
let val = rv.val();
1172+
let keys = Object.keys(val);
1173+
if (keys.length !== 1){
1174+
cerr(`HOW MANY KEYS, wanted 1, but got: ${keys.length}! Here is the object:`);
1175+
log(val);
1176+
return;
1177+
}
1178+
let id = keys[0];
1179+
let node = val[id];
1180+
//log();
1181+
//let name = node.path.split("/")[1];
1182+
let typ;
1183+
if (node.type==="d") typ = -1;
1184+
else typ = 0;
1185+
return {
1186+
blobId: node.blobId,
1187+
id,
1188+
name,
1189+
val: typ
1190+
};
1191+
1192+
};//»
1193+
globals.funcs["netfs.getUsersNodeByNameAndPar"] = fb_get_users_node_by_name_and_par;
1194+
1195+
1196+
1197+
11151198
//»
11161199

11171200
//Commands«

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/28820","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44068","net",["fs.js/66230"],"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/11784"],"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/9942","desk.js/219761","fs.js/73016","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/28820","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44068","net",["fs.js/68363"],"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/11784"],"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/9942","desk.js/219761","fs.js/74143","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)