mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-08 22:20:38 -06:00
Support a few more incoming and global objects in workers (#1401)
* no more global puter object in workers * also support my as a global in workers * support incoming user object in workers * also support myself in puter workers
This commit is contained in:
@@ -64,11 +64,14 @@ function inits2w() {
|
||||
* @returns
|
||||
*/
|
||||
async route(event) {
|
||||
if (!globalThis.puter) {
|
||||
const success = init_puter_portable(globalThis.puter_auth, globalThis.puter_endpoint || "https://api.puter.com");
|
||||
if (!globalThis.me) {
|
||||
globalThis.me = { puter: init_puter_portable(globalThis.puter_auth, globalThis.puter_endpoint || "https://api.puter.com", "userPuter") }
|
||||
globalThis.my = me;
|
||||
globalThis.myself = me;
|
||||
}
|
||||
if (event.request.headers.has("puter-auth")) {
|
||||
event.puter = init_puter_portable(event.request.headers.get("puter-auth"), globalThis.puter_endpoint || "https://api.puter.com", "userPuter");
|
||||
event.requestor = { puter: init_puter_portable(event.request.headers.get("puter-auth"), globalThis.puter_endpoint || "https://api.puter.com", "userPuter") };
|
||||
event.user = event.requestor;
|
||||
}
|
||||
|
||||
const mappings = this.map.get(event.request.method);
|
||||
|
||||
@@ -27,6 +27,9 @@ globalThis.init_puter_portable = (auth, apiOrigin, type) => {
|
||||
const goodContext = {}
|
||||
Object.getOwnPropertyNames(globalThis).forEach(name => { try { goodContext[name] = globalThis[name]; } catch {} })
|
||||
goodContext.globalThis = goodContext;
|
||||
goodContext.WorkerGlobalScope = WorkerGlobalScope;
|
||||
goodContext.ServiceWorkerGlobalScope = ServiceWorkerGlobalScope;
|
||||
goodContext.location = new URL("https://puter.work");
|
||||
goodContext.addEventListener = ()=>{};
|
||||
// @ts-ignore
|
||||
with (goodContext) {
|
||||
@@ -37,9 +40,10 @@ globalThis.init_puter_portable = (auth, apiOrigin, type) => {
|
||||
return goodContext.puter;
|
||||
} else {
|
||||
#include "../../../../../puter-js/dist/puter.js"
|
||||
|
||||
puter.setAPIOrigin(apiOrigin);
|
||||
puter.setAuthToken(auth);
|
||||
}
|
||||
puter.setAPIOrigin(apiOrigin);
|
||||
puter.setAuthToken(auth);
|
||||
}
|
||||
#include "../dist/webpackPreamplePart.js"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user