Compare commits

...

1 Commits

Author SHA1 Message Date
b6c80af059 http api actually works 2025-11-01 09:58:06 -04:00
2 changed files with 42 additions and 22 deletions

View File

@ -1,5 +1,4 @@
/** @import * as TYPES from "./types.ts" */
import * as FSAccess from "../store-directory-handle.js";
/** @type {TYPES.GraphBuilder} */
export function Room({user, role, part, desk, pass})
@ -103,22 +102,13 @@ export function Room({user, role, part, desk, pass})
{
this.time = Date.now();
const handle = await FSAccess.getDirectoryHandle();
const path = ["store", context.Path, passID, user.id+".json"];
let text = await FSAccess.Read(handle, path) || "{}";
/** @type {TYPES.UserPassFile} */
const json = JSON.parse(text);
const body = JSON.stringify({
[partObj.id]:[this.time, data]
})
const http = await fetch(`./store/${context.Path}/${passID}/${user.id}.json`, {method:"PUT", body});
console.log(http);
let field = json[partObj.id];
if(!field)
{
field = [];
json[partObj.id] = field;
}
field.push([this.time, data]);
text = JSON.stringify(json, null, 2);
await FSAccess.Write(handle, path, text);
this.work.push(/** @type {TYPES.Work}*/([this.time, data, user]));
partObj.make.forEach((arg)=>{Scan(arg, passObj)});
partObj.need.forEach((arg)=>{Scan(arg, passObj)});
@ -137,11 +127,10 @@ export function Room({user, role, part, desk, pass})
const [userID, userObject] = userData[i];
try
{
const handle = await FSAccess.getDirectoryHandle();
const text = await FSAccess.Read(handle, ["store", context.Path, passID, userID+".json"]);
const http = await fetch(`./store/${context.Path}/${passID}/${userID}.json`);
/** @type {TYPES.UserPassFile} */
const json = JSON.parse(text);
const json = await http.json();
Object.entries(json).forEach(([partID, payload])=>{
let latest = 0;

View File

@ -21,15 +21,46 @@ async function Interceptor(event)
const pathname = url.pathname.substring(1);
let parts = pathname.split("/");
if(parts[0] == "graph")
if(parts[0] == "graph" || parts[0] == "store")
{
console.log("intercept:", pathname);
const handle = await FSAccess.getDirectoryHandle();
if(event.request.method == "PUT")
{
console.log("put operation");
const payloadJSON = await event.request.clone().json();
let text = await FSAccess.Read(handle, parts) || "{}";
const fileJSON = JSON.parse(text);
for(const key in payloadJSON)
{
const value = payloadJSON[key];
let field = fileJSON[key];
if(!field)
{
field = [];
fileJSON[key] = field;
}
field.push(value);
}
console.log(`incoming:`, payloadJSON);
console.log(`outgoing:`, fileJSON);
text = JSON.stringify(fileJSON, null, 2);
const result = await FSAccess.Write(handle, parts, text);
return new Response(result+"", options);
}
const text = await FSAccess.Read(handle, parts);
if(text)
{
return new Response(text, options);
return new Response(text, options);
}
}