From caeb4f8ac77c2f79addf80ea7efdfb5ab4aee868 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Tue, 24 Feb 2026 13:06:51 +0100 Subject: [PATCH] chore: replace uuids with tids --- _config.ts | 16 ++++++++++++++++ deno.jsonc | 1 + src/common/element.js | 1 - src/common/facets/utils.js | 4 +++- src/common/loader.js | 5 +++-- src/common/themes/utils.js | 4 +++- src/components/input/opensubsonic/worker.js | 5 +++-- src/components/input/s3/worker.js | 7 ++++--- src/components/orchestrator/favourites/worker.js | 4 +++- src/facets/index.js | 4 +++- src/facets/tools/v3-import.html.txt | 3 ++- src/themes/index.js | 4 +++- src/themes/webamp/configurators/input/element.js | 4 +++- 13 files changed, 47 insertions(+), 15 deletions(-) diff --git a/_config.ts b/_config.ts index 4195257c..11eb4bfd 100644 --- a/_config.ts +++ b/_config.ts @@ -59,6 +59,22 @@ site.use(esbuild({ ); }, }, + { + name: "atcute-tid-browser", + setup(build) { + build.onLoad( + { filter: /@atcute\+tid.*random-node\.js$/ }, + async (args) => { + const browserPath = args.path.replace( + "random-node.js", + "random-web.js", + ); + const contents = await Deno.readTextFile(browserPath); + return { contents, loader: "js" }; + }, + ); + }, + }, { name: "atcute-multibase-browser", setup(build) { diff --git a/deno.jsonc b/deno.jsonc index 710f6508..09629c8b 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -5,6 +5,7 @@ "imports": { "98.css": "npm:98.css@^0.1.21", "@atcute/cbor": "npm:@atcute/cbor@^2.3.0", + "@atcute/tid": "npm:@atcute/tid@^1.0.0", "@atcute/client": "npm:@atcute/client@^4.2.1", "@atcute/identity-resolver": "npm:@atcute/identity-resolver@^1.2.2", "@atcute/lexicons": "npm:@atcute/lexicons@^1.2.7", diff --git a/src/common/element.js b/src/common/element.js index 717c9293..cab742a7 100644 --- a/src/common/element.js +++ b/src/common/element.js @@ -28,7 +28,6 @@ export class DiffuseElement extends HTMLElement { constructor() { super(); - this.uuid = crypto.randomUUID(); this.worker = this.worker.bind(this); this.workerLink = this.workerLink.bind(this); } diff --git a/src/common/facets/utils.js b/src/common/facets/utils.js index 616dec68..7a81f865 100644 --- a/src/common/facets/utils.js +++ b/src/common/facets/utils.js @@ -1,5 +1,7 @@ // import { fragments, serializeFragments } from "@fcrozatier/htmlcrunch"; +import * as TID from "@atcute/tid"; + import { loadURI } from "../loader.js"; import * as CID from "../cid.js"; @@ -22,7 +24,7 @@ export async function facetFromURI({ name, uri }, { fetchHTML }) { const facet = { $type: "sh.diffuse.output.facet", createdAt: timestamp, - id: crypto.randomUUID(), + id: TID.now(), cid, html, name, diff --git a/src/common/loader.js b/src/common/loader.js index f39eaea0..acde180c 100644 --- a/src/common/loader.js +++ b/src/common/loader.js @@ -1,4 +1,5 @@ import * as URI from "fast-uri"; +import * as TID from "@atcute/tid"; import { Client, ok, simpleFetchHandler } from "@atcute/client"; import { CompositeDidDocumentResolver, @@ -61,7 +62,7 @@ export function createLoader(config) { if (path) { item = { $type: config.$type, - id: crypto.randomUUID(), + id: TID.now(), name: "temporary", uri: `diffuse://${path}`, }; @@ -70,7 +71,7 @@ export function createLoader(config) { } else if (uri) { item = { $type: config.$type, - id: crypto.randomUUID(), + id: TID.now(), name: "temporary", uri, }; diff --git a/src/common/themes/utils.js b/src/common/themes/utils.js index 6b9341f8..370190dc 100644 --- a/src/common/themes/utils.js +++ b/src/common/themes/utils.js @@ -1,3 +1,5 @@ +import * as TID from "@atcute/tid"; + import { loadURI } from "../loader.js"; import * as CID from "../cid.js"; @@ -20,7 +22,7 @@ export async function themeFromURI({ name, uri }, { fetchHTML }) { const theme = { $type: "sh.diffuse.output.theme", createdAt: timestamp, - id: crypto.randomUUID(), + id: TID.now(), cid, html, name, diff --git a/src/components/input/opensubsonic/worker.js b/src/components/input/opensubsonic/worker.js index 7a61c051..d9aef79b 100644 --- a/src/components/input/opensubsonic/worker.js +++ b/src/components/input/opensubsonic/worker.js @@ -1,4 +1,5 @@ import * as URI from "fast-uri"; +import * as TID from "@atcute/tid"; import { ostiary, rpc } from "@common/worker.js"; import { SCHEME } from "./constants.js"; @@ -154,7 +155,7 @@ export async function list(cachedTracks = []) { /** @type {Track} */ const track = { $type: "sh.diffuse.output.track", - id: crypto.randomUUID(), + id: TID.now(), kind: autoTypeToTrackKind(song.type), uri: buildURI(server, { songId: song.id, path }), @@ -239,7 +240,7 @@ export async function list(cachedTracks = []) { if (!tracks.length) { tracks = [{ $type: "sh.diffuse.output.track", - id: crypto.randomUUID(), + id: TID.now(), kind: "placeholder", uri: buildURI(server), }]; diff --git a/src/components/input/s3/worker.js b/src/components/input/s3/worker.js index d983b7d0..1b93ec5a 100644 --- a/src/components/input/s3/worker.js +++ b/src/components/input/s3/worker.js @@ -1,3 +1,4 @@ +import * as TID from "@atcute/tid"; import { ostiary, rpc } from "@common/worker.js"; import { detach as detachUtil, @@ -130,7 +131,7 @@ export async function list(cachedTracks = []) { .map((l) => { const cachedTrack = cache[bid]?.[l.key]; - const id = cachedTrack?.id || crypto.randomUUID(); + const id = cachedTrack?.id || TID.now(); const stats = cachedTrack?.stats; const tags = cachedTrack?.tags; @@ -152,7 +153,7 @@ export async function list(cachedTracks = []) { if (!tracks.length) { tracks = [{ $type: "sh.diffuse.output.track", - id: crypto.randomUUID(), + id: TID.now(), kind: "placeholder", uri: buildURI(bucket), }]; @@ -211,7 +212,7 @@ export function demo() { /** @type {Track} */ const track = { $type: "sh.diffuse.output.track", - id: crypto.randomUUID(), + id: TID.now(), kind: "placeholder", uri, }; diff --git a/src/components/orchestrator/favourites/worker.js b/src/components/orchestrator/favourites/worker.js index 762ca48a..3817d8a4 100644 --- a/src/components/orchestrator/favourites/worker.js +++ b/src/components/orchestrator/favourites/worker.js @@ -1,3 +1,5 @@ +import * as TID from "@atcute/tid"; + import { ostiary, rpc } from "@common/worker.js"; import { filterFavourites } from "./common.js"; @@ -43,7 +45,7 @@ function createFavouriteItem(track) { return /** @type {PlaylistItem} */ ({ $type: "sh.diffuse.output.playlistItem", - id: crypto.randomUUID(), + id: TID.now(), playlist: "Favourites", criteria: [ { diff --git a/src/facets/index.js b/src/facets/index.js index b0dff494..92c16ff1 100644 --- a/src/facets/index.js +++ b/src/facets/index.js @@ -9,6 +9,8 @@ import { html as langHtml } from "@codemirror/lang-html"; import { javascript as langJs } from "@codemirror/lang-javascript"; import { autocompletion } from "@codemirror/autocomplete"; +import * as TID from "@atcute/tid"; + import * as CID from "@common/cid.js"; import foundation from "@common/facets/foundation.js"; import { effect, signal } from "@common/signal.js"; @@ -273,7 +275,7 @@ async function onBuildSubmit(event) { } : { $type: "sh.diffuse.output.facet", - id: crypto.randomUUID(), + id: TID.now(), cid, description, html, diff --git a/src/facets/tools/v3-import.html.txt b/src/facets/tools/v3-import.html.txt index 721ad5e8..d8fafbf2 100644 --- a/src/facets/tools/v3-import.html.txt +++ b/src/facets/tools/v3-import.html.txt @@ -79,6 +79,7 @@