mirror of
https://github.com/hanzoai/frames.git
synced 2026-09-24 00:08:03 +00:00
@hanzo/frame is taken by the hero video primitive — one full-bleed video element — which has held that name on npm since it shipped. This repo is the video toolchain: a CLI, a renderer, a studio, a player. Plural is what it is, so the CLI publishes as @hanzo/frames and the workspace packages follow it (@hanzo/frames-core, @hanzo/frames-engine, and the rest). The binary stays `frames`, and now actually ships. The manifest mapped it to bin/frames.mjs while the file on disk was bin/hyperframes.mjs, so a global install produced no working command. The paths that name a package to fetch were pointing elsewhere. The update check read registry.npmjs.org/frames, a different author's package, and the npm, bun and pnpm installers would have pulled it over the CLI; the render image installed the upstream hyperframes; scaffolded projects and the docs pinned the unscoped name. All of them now name @hanzo/frames.
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { defineConfig } from "vite";
|
|
import path from "node:path";
|
|
import type { Plugin } from "vite";
|
|
import type { Connect } from "vite";
|
|
import type { ServerResponse } from "node:http";
|
|
import { createFsAdapter } from "@hanzo/frames-sdk/adapters/fs";
|
|
import type { PersistAdapter } from "@hanzo/frames-sdk";
|
|
|
|
const COMP_ROOT = path.resolve(import.meta.dirname);
|
|
const COMP_PATH = "composition.html";
|
|
|
|
function sendHtml(res: ServerResponse, html: string | undefined) {
|
|
if (html === undefined) {
|
|
res.statusCode = 404;
|
|
res.end("");
|
|
return;
|
|
}
|
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
res.end(html);
|
|
}
|
|
|
|
function readBody(req: Connect.IncomingMessage): Promise<string> {
|
|
return new Promise((resolve) => {
|
|
const chunks: Buffer[] = [];
|
|
req.on("data", (c: Buffer) => chunks.push(c));
|
|
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
});
|
|
}
|
|
|
|
function versionKeyOf(req: Connect.IncomingMessage): string | null {
|
|
return new URL(req.url ?? "/", "http://localhost").searchParams.get("version");
|
|
}
|
|
|
|
async function handleCompositionGet(
|
|
adapter: PersistAdapter,
|
|
req: Connect.IncomingMessage,
|
|
res: ServerResponse,
|
|
) {
|
|
const versionKey = versionKeyOf(req);
|
|
const html = versionKey
|
|
? await adapter.loadFrom(COMP_PATH, versionKey)
|
|
: await adapter.read(COMP_PATH);
|
|
sendHtml(res, html);
|
|
}
|
|
|
|
async function handleCompositionPut(
|
|
adapter: PersistAdapter,
|
|
req: Connect.IncomingMessage,
|
|
res: ServerResponse,
|
|
) {
|
|
await adapter.write(COMP_PATH, await readBody(req));
|
|
res.statusCode = 204;
|
|
res.end();
|
|
}
|
|
|
|
function methodNotAllowed(res: ServerResponse) {
|
|
res.statusCode = 405;
|
|
res.end();
|
|
}
|
|
|
|
function compositionPlugin(): Plugin {
|
|
const adapter = createFsAdapter({ root: COMP_ROOT });
|
|
|
|
return {
|
|
name: "hf-composition",
|
|
configureServer(server) {
|
|
server.middlewares.use("/api/composition/versions", async (req, res) => {
|
|
if (req.method !== "GET") return methodNotAllowed(res);
|
|
const versions = await adapter.listVersions(COMP_PATH);
|
|
res.setHeader("Content-Type", "application/json");
|
|
res.end(JSON.stringify(versions.map((v) => ({ key: v.key, timestamp: v.timestamp }))));
|
|
});
|
|
|
|
server.middlewares.use("/api/composition", async (req, res) => {
|
|
if (req.method === "GET") return handleCompositionGet(adapter, req, res);
|
|
if (req.method === "PUT") return handleCompositionPut(adapter, req, res);
|
|
methodNotAllowed(res);
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [compositionPlugin()],
|
|
});
|