Experiment to rebuild Diffuse using web applets.
0

Configure Feed

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

1import * as IDB from "idb-keyval"; 2 3import { expose, jsonDecode, jsonEncode } from "@scripts/common"; 4import type { Track } from "@applets/core/types"; 5import { IDB_PREFIX } from "./constants"; 6 7//////////////////////////////////////////// 8// ACTIONS 9//////////////////////////////////////////// 10const actions = expose({ 11 getTracks, 12 putTracks, 13}); 14 15export type Actions = typeof actions; 16 17// Actions 18 19async function getTracks() { 20 const encoded = await get({ name: "tracks.json" }); 21 if (!encoded) return []; 22 return jsonDecode<Track[]>(encoded); 23} 24 25async function putTracks(tracks: Track[]) { 26 const data = jsonEncode(tracks); 27 await put({ name: "tracks.json", data }); 28} 29 30//////////////////////////////////////////// 31// 🛠️ 32//////////////////////////////////////////// 33 34async function get({ name }: { name: string }) { 35 return await IDB.get(`${IDB_PREFIX}/${name}`); 36} 37 38async function put({ data, name }: { data: Uint8Array; name: string }) { 39 return await IDB.set(`${IDB_PREFIX}/${name}`, data); 40}