Experiment to rebuild Diffuse using web applets.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: first worker channel

+70 -12
+1 -1
package-lock.json
··· 2230 2230 "node_modules/@web-applets/sdk": { 2231 2231 "version": "0.2.6", 2232 2232 "resolved": "https://gitpkg.vercel.app/unternet-co/web-applets/sdk?tokono.ma/experiment&scripts.postinstall=npm%20i%20%40types%2Fnode%20%26%26%20npx%20tsc", 2233 - "integrity": "sha512-AL1T69Yr2yA0MV+JaCWj+SufF83aSBfwLe3iPVh5WB7qH1nH4vu2cC7JJK1FYNBs8wEYmyh2SNHGQjKQyoFy4w==", 2233 + "integrity": "sha512-6fDpl977RqV7zMfKDPrGEaJs2nX2cpLERFv6mC4pdpw2PwdBb1rqADitBRlEIquLUakga0pCfqJFSHqfRRJMOw==", 2234 2234 "hasInstallScript": true, 2235 2235 "license": "MIT" 2236 2236 },
+1
src/pages/constituent/blur/artwork-controller/_applet.astro
··· 510 510 }, 511 511 { 512 512 timeoutDuration: 60000 * 5, 513 + worker: true, 513 514 }, 514 515 ); 515 516
+9 -5
src/pages/orchestrator/input-cache/_applet.astro
··· 24 24 }; 25 25 26 26 // Start processing once settled and tracks are loaded 27 - context 28 - .settled() 29 - .then(() => configurator.output) 30 - .then((output) => wait(output, (d) => d?.tracks.state === "loaded")) 31 - .then(() => (context.isMainInstance() ? process() : undefined)); 27 + // context 28 + // .settled() 29 + // .then(() => configurator.output) 30 + // .then((output) => wait(output, (d) => d?.tracks.state === "loaded")) 31 + // .then(() => (context.isMainInstance() ? process() : undefined)); 32 32 33 33 //////////////////////////////////////////// 34 34 // ACTIONS ··· 49 49 timeoutDuration: 60000 * 5, 50 50 }); 51 51 52 + console.log("CONTEXTUALIZED"); 53 + 52 54 const tracks = await input.sendAction<Track[]>("list", cachedTracks, { 53 55 timeoutDuration: 60000 * 60 * 24, 54 56 }); 57 + 58 + console.log("LISTED", tracks); 55 59 56 60 // Process 57 61 const tracksWithMetadata = await tracks.reduce(
+8 -2
src/pages/processor/artwork/_applet.astro
··· 19 19 // Register 20 20 const context = register(); 21 21 22 + context.scope.onworkerport = (event) => { 23 + if (!event.port) return; 24 + worker.connect(transfer(event.port)); 25 + }; 26 + 22 27 //////////////////////////////////////////// 23 28 // ACTIONS 24 29 //////////////////////////////////////////// 25 30 function artwork(request: ArtworkRequest) { 26 - return worker.artwork(transfer(request)); 31 + // return worker.artwork(transfer(request)); 32 + return []; 27 33 } 28 34 29 35 function supply(items: ArtworkRequest[]) { 30 - return worker.supply(transfer(items)); 36 + // return worker.supply(transfer(items)); 31 37 } 32 38 33 39 context.setActionHandler("artwork", artwork);
+51 -4
src/scripts/processor/artwork/worker.ts
··· 5 5 import { expose, transfer } from "@scripts/common"; 6 6 import { IDB_ARTWORK_PREFIX } from "./constants"; 7 7 import { musicMetadataTags } from "../metadata/common"; 8 + import { getTransferables } from "@okikio/transferables"; 8 9 9 10 // State 10 11 let queue: ArtworkRequest[] = []; ··· 12 13 //////////////////////////////////////////// 13 14 // ACTIONS 14 15 //////////////////////////////////////////// 15 - const actions = expose({ 16 + const c = expose({ 17 + connect, 18 + }); 19 + 20 + export type Actions = typeof c; 21 + 22 + const actions: { [key: string]: Function } = { 16 23 artwork, 17 24 supply, 18 - }); 25 + }; 26 + 27 + // ⚡️ 19 28 20 - export type Actions = typeof actions; 29 + async function connect(port: MessagePort) { 30 + port.onmessage = async (message) => { 31 + switch (message.data?.type) { 32 + case "action": 33 + return handleAction(port, message.data); 34 + } 35 + }; 36 + } 37 + 38 + async function handleAction( 39 + port: MessagePort, 40 + action: { 41 + type: "action"; 42 + id: string; 43 + actionId: string; 44 + arguments: any; 45 + }, 46 + ) { 47 + const result = await actions[action.actionId]?.(action.arguments); 48 + return postMessage(port, action.id, result); 49 + } 50 + 51 + function postMessage<T>(port: MessagePort, id: string, result: T) { 52 + port.postMessage( 53 + { 54 + type: "actioncomplete", 55 + id, 56 + result, 57 + }, 58 + { 59 + transfer: getTransferables(result), 60 + }, 61 + ); 62 + } 21 63 22 64 // Actions 23 65 24 66 async function artwork(request: ArtworkRequest) { 25 67 const art = await processRequest(request); 26 - return transfer(art); 68 + return art; 27 69 } 28 70 29 71 function supply(items: ArtworkRequest[]) { ··· 154 196 // TODO: Retry if none was found? 155 197 const cache = await IDB.get(`${IDB_ARTWORK_PREFIX}/${req.cacheId}`); 156 198 if (cache && Array.isArray(cache) && cache.length) return cache; 199 + 200 + // Request override 201 + if (req.tags?.artist?.toUpperCase() === "VA") { 202 + req.variousArtists = true; 203 + } 157 204 158 205 // 🚀 159 206 let art: Artwork[] = [];