use lexicon.ts for VideoRecord type

This commit is contained in:
Charlotte Som 2025-06-06 11:24:50 +01:00
parent aa0f0885f9
commit 1d41bc2711
5 changed files with 89 additions and 9 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "vendor/lexicon.ts"]
path = vendor/lexicon.ts
url = https://github.com/char/lexicon.ts.git

View file

@ -1,13 +1,10 @@
import type { Infer } from "@char/lexicon.ts";
import type { VideoLexiconUniverse } from "../common/lexicons.ts";
import { resolveDid, resolveHandle } from "../common/identity.ts";
import { VIDEO_PATTERN } from "../common/routes.ts";
type BlobRef = {
$type: "blob";
ref: { $link: string };
mimeType?: string;
size?: number;
};
type VideoRecord = { video: BlobRef; title?: string; description?: string };
type VideoRecord = Infer<VideoLexiconUniverse, "blue.cerulea.video.video">;
const fetchVideoRecord = async (
did: string,
@ -58,7 +55,10 @@ const main = async () => {
const did = repo.startsWith("did:") ? repo : await resolveHandle(repo);
const record = await fetchVideoRecord(did, rkey);
const videoURL = await resolveVideoURL(did, record.video.ref.$link);
const videoURL = await resolveVideoURL(
did,
"ref" in record.video ? record.video.ref.$link : record.video.cid
);
const video = (
<video crossOrigin="anonymous" controls>
<source src={videoURL} />

75
common/lexicons.ts Normal file
View file

@ -0,0 +1,75 @@
import type { MakeLexiconUniverse } from "@char/lexicon.ts";
export const videoLexicon = {
lexicon: 1,
id: "blue.cerulea.video.video",
defs: {
main: {
type: "record",
key: "any",
record: {
type: "object",
required: ["video"],
properties: {
video: {
type: "blob",
accept: ["video/mp4", "video/webm"],
maxSize: 536870912,
},
title: {
type: "string",
maxGraphemes: 300,
maxLength: 3000,
},
description: {
type: "string",
},
},
},
},
},
} as const;
export const fetchVideoLexicon = {
lexicon: 1,
id: "blue.cerulea.video.fetchVideo",
defs: {
main: {
type: "procedure",
input: {
encoding: "application/json",
schema: {
type: "object",
required: ["repo", "blob"],
properties: {
repo: {
type: "string",
format: "did",
},
blob: {
type: "string",
format: "cid",
},
},
},
},
output: {
encoding: "application/json",
schema: {
type: "object",
required: ["filename"],
properties: {
filename: {
type: "string",
},
},
},
},
errors: [{ name: "Denied" }],
},
},
} as const;
export type VideoLexiconUniverse = MakeLexiconUniverse<
[typeof videoLexicon, typeof fetchVideoLexicon]
>;

View file

@ -12,7 +12,8 @@
"@std/fs": "jsr:@std/fs@^1.0.17",
"@std/http": "jsr:@std/http@^1.0.17",
"@std/path": "jsr:@std/path@^1.1.0",
"@zod/mini": "npm:@zod/mini@^4.0.0-beta.20250505T195954"
"@zod/mini": "npm:@zod/mini@^4.0.0-beta.20250505T195954",
"@char/lexicon.ts": "./vendor/lexicon.ts/lib/mod.ts"
},
"compilerOptions": {
"lib": ["deno.window", "dom"],

1
vendor/lexicon.ts vendored Submodule

@ -0,0 +1 @@
Subproject commit f070c8b56df7d3335a970118a401dfd7ee2f63f2