From f50b59ff1744fcfe4acff7191b042cf3c43b7f1a Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 8 Nov 2026 11:21:41 +0100 Subject: [PATCH 1/2] feat(preview): scrape with the shared sable-link-preview crate --- .github/workflows/test.yml | 10 + .gitignore | 4 +- README.md | 2 + package.json | 2 + src/env.d.ts | 7 +- src/preview.ts | 326 +-------- wasm/.gitignore | 1 + wasm/Cargo.lock | 1328 ++++++++++++++++++++++++++++++++++++ wasm/Cargo.toml | 25 + wasm/src/lib.rs | 100 +++ wrangler.jsonc | 3 +- 11 files changed, 1488 insertions(+), 320 deletions(-) create mode 100644 wasm/.gitignore create mode 100644 wasm/Cargo.lock create mode 100644 wasm/Cargo.toml create mode 100644 wasm/src/lib.rs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6cbb28f..403c9bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,16 @@ jobs: node-version: 20 cache: pnpm + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Install wasm-bindgen + uses: taiki-e/install-action@v2 + with: + tool: wasm-bindgen@0.2.130 + - name: Install dependencies run: pnpm install --frozen-lockfile - name: Run Vitest diff --git a/.gitignore b/.gitignore index c285b6e..9c1bd2c 100644 --- a/.gitignore +++ b/.gitignore @@ -169,4 +169,6 @@ dist # vscode junk -.lh \ No newline at end of file +.lh +# wasm-bindgen output of wasm/, built by `pnpm build:wasm` +src/wasm diff --git a/README.md b/README.md index 7b13e9f..7f58307 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ You need to generate a matrix id, using the algorithm as shown above. `GET /_soliditas/preview_url?url=[url]` answers in the shape of the Matrix `/preview_url` endpoint. Missing `og:` tags are filled from `twitter:` tags, ``, `<meta name="description">` and oEmbed. Twitter/X links are read from the [FxTwitter API](https://github.com/FxEmbed/FxEmbed), Reddit and TikTok titles from their oEmbed endpoints, Tumblr posts without an image get the [fxtumblr](https://github.com/knuxify/fxtumblr) render, and Misskey-family notes show their images from the ActivityPub object unless marked sensitive, instead of the author's avatar. +The scraper is the Rust crate `sable-link-preview`, which the Sable client also runs natively. `wasm/` compiles it for the worker, and `pnpm build:wasm` (run before `test`, `dev` and `deploy`) needs Rust with the `wasm32-unknown-unknown` target and `wasm-bindgen-cli` 0.2.130. + `og:image` is returned as `mxc://[servername]/og_[base64url of the image url]`. When a post has more than one image, `com.sable.images` lists up to ten of them as `{ url, width, height }`, and `og:image` stays the single image other clients show (the FxTwitter mosaic for tweets). ## License diff --git a/package.json b/package.json index 257095f..f169730 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,11 @@ "version": "0.0.0", "private": true, "scripts": { + "build:wasm": "cargo build --manifest-path wasm/Cargo.toml --release --target wasm32-unknown-unknown && wasm-bindgen --target web --out-dir src/wasm wasm/target/wasm32-unknown-unknown/release/soliditas_wasm.wasm", "deploy": "wrangler deploy", "dev": "wrangler dev", "start": "wrangler dev", + "pretest": "pnpm build:wasm", "test": "vitest", "cf-typegen": "wrangler types" }, diff --git a/src/env.d.ts b/src/env.d.ts index 1a4b698..99d2029 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -2,4 +2,9 @@ export interface Env { HOSTNAME?: string; SERVERNAME?: string; PORT?: number; -} \ No newline at end of file +} + +declare module '*.wasm' { + const module: WebAssembly.Module; + export default module; +} diff --git a/src/preview.ts b/src/preview.ts index 408c607..df5d626 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -18,325 +18,19 @@ import { matrixInvalidParam, matrixRessourceNotFound } from './matrixError'; import { toMatrixID } from './mxcId'; +import { initSync, parsePublicUrl as parsePublic, scrapePreview } from './wasm/soliditas_wasm.js'; +import wasm from './wasm/soliditas_wasm_bg.wasm'; -const USER_AGENT = 'Soliditas (bot; +https://github.com/SableClient/soliditas) facebookexternalhit/1.1'; +initSync({ module: wasm }); const CORS_HEADERS = { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', }; -const TWITTER_HOSTS = /^(?:www\.|mobile\.)?(?:twitter|x|fxtwitter|fixupx|vxtwitter|fixvx)\.com$/; -const TWITTER_STATUS = /^\/(?:[^/]+|i\/web)\/status(?:es)?\/(\d+)/; - -const TUMBLR_BLOG_POST = /^([a-z\d-]+)\.tumblr\.com$/; -const TUMBLR_DASHBOARD_POST = /^\/([a-z\d-]+)\/(\d+)/; - -const OEMBED_ENDPOINTS: [RegExp, string][] = [ - [/(?:^|\.)reddit\.com$/, 'https://www.reddit.com/oembed'], - [/(?:^|\.)tiktok\.com$/, 'https://www.tiktok.com/oembed'], -]; - -const NAMED_ENTITIES: Record<string, string> = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: '\u00a0' }; - -const MAX_IMAGES = 10; - -const THEME_COLOR = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i; - -const MAX_DIRECT_VIDEO_BYTES = 100 * 1024 * 1024; - -const VIDEO_EXTENSION = /\.(?:mp4|webm|mov|m4v|ogv)$/i; - -type Tags = Record<string, string>; - -type Image = { url: string; width?: number; height?: number }; - -type Video = { url: string; type: string; width?: number; height?: number }; - -type Preview = { tags: Tags; images: Image[]; cover?: Image; video?: Video }; - -type OEmbed = { - title?: string; - author_name?: string; - author_url?: string; - provider_name?: string; - thumbnail_url?: string; - thumbnail_width?: number; - thumbnail_height?: number; -}; - -type ActivityNote = { - sensitive?: boolean; - attachment?: { mediaType?: string; url?: string; width?: number; height?: number }[]; -}; - -type FxMedia = { url?: string; thumbnail_url?: string; width?: number; height?: number }; - -type FxTweet = { - text?: string; - author?: { name?: string; screen_name?: string; avatar_url?: string }; - media?: { photos?: FxMedia[]; videos?: FxMedia[]; mosaic?: { formats?: { jpeg?: string } } }; -}; - -export function parsePublicUrl(value: string, base?: string | URL): URL | null { - let url: URL; - try { - url = new URL(value, base); - } catch { - return null; - } - if (url.protocol !== 'https:' && url.protocol !== 'http:') return null; - const host = url.hostname.toLowerCase(); - if (!host.includes('.') || host.includes(':') || host.startsWith('[')) return null; - if (/^[\d.]+$/.test(host)) return null; - if (host === 'localhost' || /\.(localhost|local|internal|home\.arpa)$/.test(host)) return null; - return url; -} - -function decodeEntities(value: string): string { - return value.replace(/&(?:#x([\da-f]+)|#(\d+)|([a-z]+));/gi, (entity, hex, decimal, name) => { - const code = hex ? Number.parseInt(hex, 16) : decimal ? Number.parseInt(decimal, 10) : undefined; - if (code !== undefined) return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : entity; - return NAMED_ENTITIES[name.toLowerCase()] ?? entity; - }); -} - -function fetchPublic(url: URL, accept: string): Promise<Response | null> { - return fetch(url, { headers: { 'User-Agent': USER_AGENT, Accept: accept }, redirect: 'follow' }) - .then((response) => (response.ok ? response : null)) - .catch(() => null); -} - -async function fetchJson<T>(url: URL): Promise<T | null> { - const response = await fetchPublic(url, 'application/json'); - return response ? ((await response.json().catch(() => null)) as T | null) : null; -} - -function setTag(tags: Tags, key: string, value: string | number | undefined): void { - if (value === undefined || value === '' || tags[key]) return; - tags[key] = String(value); -} - -function toSize(value: string | number | undefined): number | undefined { - const size = typeof value === 'number' ? value : Number.parseInt(value ?? '', 10); - return Number.isFinite(size) && size > 0 ? size : undefined; -} - -function toImage(value: string | undefined, base?: string | URL, width?: string | number, height?: string | number): Image | null { - const url = value ? parsePublicUrl(value, base) : null; - if (!url || url.pathname === '/') return null; - return { url: url.href, width: toSize(width), height: toSize(height) }; -} - -function toVideo(value: string | undefined, base: string | URL, type?: string, width?: string | number, height?: string | number): Video | null { - const url = value ? parsePublicUrl(value, base) : null; - if (!url || url.pathname === '/') return null; - const mime = type?.split(';')[0].trim().toLowerCase(); - if (mime ? !mime.startsWith('video/') : !VIDEO_EXTENSION.test(url.pathname)) return null; - return { url: url.href, type: mime ?? 'video/mp4', width: toSize(width), height: toSize(height) }; -} - -function imageKey(image: Image): string { - const url = new URL(image.url); - if (!url.hostname.endsWith('.media.tumblr.com')) return url.href; - return url.pathname.split('/').slice(1, 3).join('/'); -} - -function addImages(images: Image[], candidates: (Image | null)[]): void { - for (const image of candidates) { - if (image && images.length < MAX_IMAGES && !images.some((known) => imageKey(known) === imageKey(image))) images.push(image); - } -} - -async function readPage(page: Response, base: string | URL): Promise<{ preview: Preview; oembed?: string; misskeyNote: boolean }> { - const tags: Tags = {}; - const fallback: Tags = {}; - const found: { url: string; width?: string; height?: string }[] = []; - let title = ''; - let oembed: string | undefined; - let misskeyNote = false; - const clip: { url?: string; secure?: string; type?: string; width?: string; height?: string } = {}; - - await new HTMLRewriter() - .on('meta', { - element(element) { - const key = element.getAttribute('property') ?? element.getAttribute('name'); - const raw = element.getAttribute('content'); - const content = raw && decodeEntities(raw).trim(); - if (!key || !content) return; - if (key === 'misskey:note-id') misskeyNote = true; - if (key === 'og:video' || key === 'og:video:url') clip.url ??= content; - else if (key === 'og:video:secure_url') clip.secure ??= content; - else if (key === 'og:video:type') clip.type ??= content; - else if (key === 'og:video:width') clip.width ??= content; - else if (key === 'og:video:height') clip.height ??= content; - else if (key === 'og:image' || key === 'og:image:url') found.push({ url: content }); - else if (key === 'og:image:width' || key === 'og:image:height') { - const last = found.at(-1); - const side = key === 'og:image:width' ? 'width' : 'height'; - if (last && !last[side]) last[side] = content; - } else if (key.startsWith('og:image')) return; - else if (key.startsWith('og:')) setTag(tags, key, content); - else if (key.startsWith('twitter:') || key === 'description' || key === 'theme-color') setTag(fallback, key, content); - }, - }) - .on('link[rel="alternate"][type="application/json+oembed"]', { - element(element) { - const href = element.getAttribute('href'); - oembed ??= href ? decodeEntities(href) : undefined; - }, - }) - .on('title', { - text(text) { - title += text.text; - }, - }) - .transform(page) - .arrayBuffer(); - - setTag(tags, 'og:title', fallback['twitter:title'] ?? decodeEntities(title).trim()); - setTag(tags, 'og:description', fallback['twitter:description'] ?? fallback['description']); - - const color = fallback['theme-color']; - if (color && THEME_COLOR.test(color)) tags['com.sable.theme_color'] = color; - const card = fallback['twitter:card']; - if (card === 'summary' || card === 'summary_large_image') tags['com.sable.card'] = card; - - const images: Image[] = []; - addImages(images, found.map((image) => toImage(image.url, base, image.width, image.height))); - if (!images.length) addImages(images, [toImage(fallback['twitter:image'] ?? fallback['twitter:image:src'], base)]); - const video = toVideo(clip.secure ?? clip.url, base, clip.type, clip.width, clip.height); - return { preview: { tags, images, video: video ?? undefined }, oembed, misskeyNote }; -} - -async function noteImages(url: URL): Promise<Image[]> { - const response = await fetchPublic(url, 'application/activity+json'); - const note = response ? ((await response.json().catch(() => null)) as ActivityNote | null) : null; - if (!note || note.sensitive) return []; - const images: Image[] = []; - addImages( - images, - (note.attachment ?? []).filter((file) => file.mediaType?.startsWith('image/')).map((file) => toImage(file.url, url, file.width, file.height)), - ); - return images; -} - -function mergeOEmbed(preview: Preview, oembed: OEmbed, authoritative: boolean): void { - const { tags } = preview; - if (authoritative && oembed.title) tags['og:description'] = oembed.title; - setTag(tags, 'og:title', oembed.title ?? oembed.author_name); - setTag(tags, 'com.sable.author_name', oembed.author_name); - setTag(tags, 'og:site_name', oembed.provider_name); - if (!preview.images.length) addImages(preview.images, [toImage(oembed.thumbnail_url, undefined, oembed.thumbnail_width, oembed.thumbnail_height)]); -} - -async function previewTweet(id: string): Promise<Preview | null> { - const body = await fetchJson<{ tweet?: FxTweet }>(new URL(`https://api.fxtwitter.com/status/${id}`)); - const tweet = body?.tweet; - if (!tweet) return null; - - const tags: Tags = { 'og:site_name': 'X' }; - const { name, screen_name: handle, avatar_url: avatar } = tweet.author ?? {}; - setTag(tags, 'og:title', name && handle ? `${name} (@${handle})` : (name ?? handle)); - setTag(tags, 'og:description', tweet.text); - - const images: Image[] = []; - const media = [...(tweet.media?.photos ?? []), ...(tweet.media?.videos ?? [])]; - addImages(images, media.map((item) => toImage(item.thumbnail_url ?? item.url, undefined, item.width, item.height))); - if (!images.length) addImages(images, [toImage(avatar)]); - - const mosaic = images.length > 1 ? toImage(tweet.media?.mosaic?.formats?.jpeg) : null; - return { tags, images, cover: mosaic ?? undefined }; -} - -function imageType(page: Response): string | null { - const type = /^\s*(image\/[\w.+-]+)/i.exec(page.headers.get('Content-Type') ?? '')?.[1].toLowerCase(); - return type && type !== 'image/svg+xml' ? type : null; -} - -function videoType(page: Response): string | null { - return /^\s*(video\/[\w.+-]+)/i.exec(page.headers.get('Content-Type') ?? '')?.[1].toLowerCase() ?? null; -} - -function videoSize(page: Response): number { - return toSize(page.headers.get('Content-Length') ?? undefined) ?? 0; -} - -async function previewPage(url: URL): Promise<Preview | null> { - const endpoint = OEMBED_ENDPOINTS.find(([host]) => host.test(url.hostname))?.[1]; - const known = endpoint ? fetchJson<OEmbed>(new URL(`${endpoint}?format=json&url=${encodeURIComponent(url.href)}`)) : null; - - const page = await fetchPublic(url, 'text/html'); - const base = page?.url || url; - const clipType = page && videoType(page); - if (page && clipType) { - await page.body?.cancel(); - const video = toVideo(base.toString(), base, clipType); - return video && videoSize(page) <= MAX_DIRECT_VIDEO_BYTES ? { tags: {}, images: [], video } : null; - } - const type = page && imageType(page); - if (page && type) { - await page.body?.cancel(); - const image = toImage(base.toString()); - return image ? { tags: { 'og:image:type': type }, images: [image] } : null; - } - const html = page?.headers.get('Content-Type')?.includes('text/html') ? await readPage(page, base) : null; - const knownOEmbed = await known; - if (!html && !knownOEmbed) return null; - - const preview = html?.preview ?? { tags: {}, images: [] }; - const { tags } = preview; - if (knownOEmbed) mergeOEmbed(preview, knownOEmbed, true); - else if (html?.oembed && !(tags['og:title'] && tags['og:description'] && preview.images.length)) { - const discovered = parsePublicUrl(html.oembed, base); - const found = discovered ? await fetchJson<OEmbed>(discovered) : null; - if (found) mergeOEmbed(preview, found, false); - } - if (html?.misskeyNote) { - const attachments = await noteImages(url); - if (attachments.length) preview.images = attachments; - } - return preview; -} - -function tumblrPost(url: URL): string | null { - const blog = TUMBLR_BLOG_POST.exec(url.hostname)?.[1]; - if (blog && blog !== 'www') { - const id = /^\/post\/(\d+)/.exec(url.pathname)?.[1]; - return id ? `${blog}/${id}` : null; - } - if (!/^(?:www\.)?tumblr\.com$/.test(url.hostname)) return null; - const [, dashboardBlog, id] = TUMBLR_DASHBOARD_POST.exec(url.pathname) ?? []; - return id ? `${dashboardBlog}/${id}` : null; -} - -async function previewTumblr(url: URL, post: string): Promise<Preview | null> { - const [preview, fxtumblr] = await Promise.all([previewPage(url), previewPage(new URL(`https://tpmblr.com/${post}`))]); - if (!preview || preview.images.length || !fxtumblr?.images.length) return preview ?? fxtumblr; - preview.images = fxtumblr.images; - return preview; -} - -function toMatrixPreview({ tags, images, cover, video }: Preview, serverName: string): Record<string, unknown> { - const toMxc = (image: Image) => `mxc://${serverName}/${toMatrixID(image.url, 'og_')}`; - const preview: Record<string, unknown> = { ...tags }; - - const main = cover ?? images[0]; - if (main) { - preview['og:image'] = toMxc(main); - if (main.width) preview['og:image:width'] = main.width; - if (main.height) preview['og:image:height'] = main.height; - } - if (video) { - preview['og:video'] = toMxc({ url: video.url }); - preview['og:video:type'] = video.type; - if (video.width) preview['og:video:width'] = video.width; - if (video.height) preview['og:video:height'] = video.height; - } - if (images.length > 1) { - preview['com.sable.images'] = images.map((image) => ({ url: toMxc(image), width: image.width, height: image.height })); - } - return preview; +export function parsePublicUrl(value: string): URL | null { + const url = parsePublic(value); + return url === undefined ? null : new URL(url); } export async function previewUrl(target: string | null, serverName: string): Promise<Response> { @@ -348,17 +42,15 @@ export async function previewUrl(target: string | null, serverName: string): Pro }); } - const tweet = TWITTER_HOSTS.test(url.hostname) ? TWITTER_STATUS.exec(url.pathname)?.[1] : undefined; - const tumblr = tumblrPost(url); - const preview = (tweet ? await previewTweet(tweet) : null) ?? (tumblr ? await previewTumblr(url, tumblr) : await previewPage(url)); - if (!preview) { + const preview = await scrapePreview(url.href, (media: string) => `mxc://${serverName}/${toMatrixID(media, 'og_')}`); + if (preview === undefined) { return new Response(JSON.stringify(matrixRessourceNotFound('no html preview for this url')), { headers: CORS_HEADERS, status: 404, }); } - return new Response(JSON.stringify(toMatrixPreview(preview, serverName)), { + return new Response(preview, { headers: { ...CORS_HEADERS, 'Cache-Control': 'public, max-age=86400' }, }); } diff --git a/wasm/.gitignore b/wasm/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/wasm/.gitignore @@ -0,0 +1 @@ +target diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock new file mode 100644 index 0000000..f8f994e --- /dev/null +++ b/wasm/Cargo.lock @@ -0,0 +1,1328 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "cc" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + +[[package]] +name = "cssparser" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dae61cf9c0abb83bd659dab65b7e4e38d8236824c85f0f804f173567bda257d2" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "darling" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6837e2cf7485aaae18f86181d2f0e9a7ed297a025e220aeabf63fdebd3a2ddff" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 3.0.9", +] + +[[package]] +name = "darling_macro" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785" +dependencies = [ + "darling_core", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "deranged" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.119", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "dtoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c3cf4824e2d5f025c7b531afcb2325364084a16806f6d47fbc1f5fbd9960590" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "encoding_rs" +version = "0.8.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jiff" +version = "0.2.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ed8250fe4472173a765b89fea4b46f2c4aa12adc12a3e310f1dc6c108e041b" +dependencies = [ + "jiff-core", + "jiff-static", + "jiff-tzdb-platform", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-link", +] + +[[package]] +name = "jiff-core" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecfc96f3a325d3a9b0ee6db9a81a83b40b94e781021c044a0a7f4c4630a1e482" +dependencies = [ + "log", +] + +[[package]] +name = "jiff-static" +version = "0.2.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9522de39a5298859d9e844b660eb7d5e6fd1b63b9953f51535408a62f2d31b3" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jiff-tzdb" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" + +[[package]] +name = "jiff-tzdb-platform" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" +dependencies = [ + "jiff-tzdb", +] + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "lol_html" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "691b898297b684292c8808d0285769fc05fb721a36ee5b62c75c8da83e60d350" +dependencies = [ + "bitflags", + "cfg-if", + "cssparser", + "encoding_rs", + "foldhash", + "hashbrown 0.17.1", + "memchr", + "mime", + "precomputed-hash", + "selectors", + "thiserror", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1" + +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "phf" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_macros", + "phf_shared", + "serde", +] + +[[package]] +name = "phf_codegen" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" +dependencies = [ + "fastrand", + "phf_shared", +] + +[[package]] +name = "phf_macros" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ref-cast" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "sable-link-preview" +version = "0.1.0" +source = "git+https://git.sable.moe/SableClient/link-preview.git?rev=19f24c8adeef9d7ec88c48d38c308f7b12ae5aad#19f24c8adeef9d7ec88c48d38c308f7b12ae5aad" +dependencies = [ + "futures-util", + "lol_html", + "serde", + "serde_json", + "serde_with", + "url", +] + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "selectors" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cfaaa6035167f0e604e42723c7650d59ee269ef220d7bbe0565602c8a0173b9" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "log", + "new_debug_unreachable", + "phf", + "phf_codegen", + "precomputed-hash", + "rustc-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_with" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9adc193c780ef8f159aee8b61e2d5801aaa555e6eb0947fe45530ec506296f" +dependencies = [ + "base64", + "bs58", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.14.2", + "jiff", + "schemars 0.9.0", + "schemars 1.2.3", + "serde_core", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17bbc68e28663bbbb90df47e058aa7eda4fb445b89fe70457bb94fbccf6e49" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "servo_arc" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170fb83ab34de17dc69aa7c67482b22218ddb85da56546f9bd6b929e32a05930" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "siphasher" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" + +[[package]] +name = "soliditas-wasm" +version = "0.0.0" +dependencies = [ + "js-sys", + "sable-link-preview", + "serde_json", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "pin-project-lite", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e14e0327cb5368ad60ccb22d04a9827a693c95a926d8d125e9fa39e0baec501" +dependencies = [ + "js-sys", + "tokio", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.9", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml new file mode 100644 index 0000000..ae69ac6 --- /dev/null +++ b/wasm/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "soliditas-wasm" +version = "0.0.0" +edition = "2024" +license = "Apache-2.0" +publish = false + +[lib] +crate-type = ["cdylib"] + +[dependencies] +sable-link-preview = { git = "https://git.sable.moe/SableClient/link-preview.git", rev = "19f24c8adeef9d7ec88c48d38c308f7b12ae5aad", features = ["scrape"] } +serde_json = "1" +url = "2" +wasm-bindgen = "=0.2.130" +wasm-bindgen-futures = "0.4" +js-sys = "0.3" +web-sys = { version = "0.3", features = ["Headers", "ReadableStream", "RequestInit", "RequestRedirect", "Response"] } + +[profile.release] +opt-level = "z" +lto = true +codegen-units = 1 +panic = "abort" +strip = "debuginfo" diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs new file mode 100644 index 0000000..543cc88 --- /dev/null +++ b/wasm/src/lib.rs @@ -0,0 +1,100 @@ +use js_sys::{Function, Promise, Uint8Array}; +use sable_link_preview::{Fetch, Response, parse_public_url, scrape}; +use url::Url; +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use web_sys::{Headers, RequestInit, RequestRedirect}; + +const USER_AGENT: &str = + "Soliditas (bot; +https://github.com/SableClient/soliditas) facebookexternalhit/1.1"; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_name = fetch)] + fn global_fetch(input: &str, init: &RequestInit) -> Promise; +} + +struct WorkerFetch; + +struct WorkerResponse { + requested: Url, + response: web_sys::Response, +} + +fn cancel(response: &web_sys::Response) { + if !response.body_used() + && let Some(body) = response.body() + { + let _ = body.cancel(); + } +} + +impl Fetch for WorkerFetch { + type Response = WorkerResponse; + + async fn get(&self, url: &Url, accept: &'static str) -> Option<WorkerResponse> { + let headers = Headers::new().ok()?; + headers.set("User-Agent", USER_AGENT).ok()?; + headers.set("Accept", accept).ok()?; + let init = RequestInit::new(); + init.set_method("GET"); + init.set_headers(&headers); + init.set_redirect(RequestRedirect::Follow); + let response: web_sys::Response = JsFuture::from(global_fetch(url.as_str(), &init)) + .await + .ok()? + .dyn_into() + .ok()?; + if !response.ok() { + cancel(&response); + return None; + } + Some(WorkerResponse { + requested: url.clone(), + response, + }) + } +} + +impl Response for WorkerResponse { + fn url(&self) -> Url { + Url::parse(&self.response.url()).unwrap_or_else(|_| self.requested.clone()) + } + + fn header(&self, name: &str) -> Option<String> { + self.response.headers().get(name).ok().flatten() + } + + async fn body(self, limit: usize) -> Option<Vec<u8>> { + let buffer = JsFuture::from(self.response.array_buffer().ok()?).await.ok()?; + let bytes = Uint8Array::new(&buffer); + let length = bytes.length().min(u32::try_from(limit).unwrap_or(u32::MAX)); + Some(bytes.subarray(0, length).to_vec()) + } +} + +impl Drop for WorkerResponse { + fn drop(&mut self) { + cancel(&self.response); + } +} + +#[wasm_bindgen(js_name = parsePublicUrl)] +#[must_use] +pub fn parse_public(value: &str) -> Option<String> { + parse_public_url(value, None).map(String::from) +} + +#[wasm_bindgen(js_name = scrapePreview)] +pub async fn scrape_preview(target: String, to_mxc: Function) -> Option<String> { + let url = parse_public_url(&target, None)?; + let preview = scrape(&WorkerFetch, &url).await?; + let media = |url: &Url| { + to_mxc + .call1(&JsValue::NULL, &JsValue::from_str(url.as_str())) + .ok() + .and_then(|uri| uri.as_string()) + .unwrap_or_default() + }; + serde_json::to_string(&preview.to_matrix(media)).ok() +} diff --git a/wrangler.jsonc b/wrangler.jsonc index 7a0b535..7616e45 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -11,7 +11,8 @@ "enabled": true }, "upload_source_maps": true, - "compatibility_flags": [] + "compatibility_flags": [], + "build": { "command": "pnpm build:wasm" } /** * Smart Placement * https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement From f7555c4411a741d6bfc3a65c70cf6993cebb7b51 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher <erwanleboucher@gmail.com> Date: Sun, 8 Nov 2026 12:15:24 +0100 Subject: [PATCH 2/2] chore(deps): bump sable-link-preview --- wasm/Cargo.lock | 2 +- wasm/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index f8f994e..6fbc576 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -768,7 +768,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] name = "sable-link-preview" version = "0.1.0" -source = "git+https://git.sable.moe/SableClient/link-preview.git?rev=19f24c8adeef9d7ec88c48d38c308f7b12ae5aad#19f24c8adeef9d7ec88c48d38c308f7b12ae5aad" +source = "git+https://git.sable.moe/SableClient/link-preview.git?rev=931c614c21534edb570fafcee6c4e1ec0f502fac#931c614c21534edb570fafcee6c4e1ec0f502fac" dependencies = [ "futures-util", "lol_html", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index ae69ac6..102fbd8 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -9,7 +9,7 @@ publish = false crate-type = ["cdylib"] [dependencies] -sable-link-preview = { git = "https://git.sable.moe/SableClient/link-preview.git", rev = "19f24c8adeef9d7ec88c48d38c308f7b12ae5aad", features = ["scrape"] } +sable-link-preview = { git = "https://git.sable.moe/SableClient/link-preview.git", rev = "931c614c21534edb570fafcee6c4e1ec0f502fac", features = ["scrape"] } serde_json = "1" url = "2" wasm-bindgen = "=0.2.130"