Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
89 lines
3.8 KiB
JavaScript
89 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Publish the cast receiver (cast-receiver/) to the public R2 bucket.
|
|
* Prints the wrangler commands; `--run` runs them (needs `wrangler login`
|
|
* on the owner's account). Bucket and prefix: CAST_R2_BUCKET (default
|
|
* menivor-public) and CAST_R2_PREFIX (default cast).
|
|
*
|
|
* API allowlist (build time): CAST_API_ORIGINS, comma separated https origins
|
|
* (default https://api.menivor.com, the committed cast-receiver/config.js),
|
|
* and CAST_ALLOW_LOCALHOST=1 for a dev receiver that also accepts
|
|
* http://localhost. When either is set, a generated config.js is uploaded in
|
|
* place of the committed one.
|
|
*/
|
|
|
|
import { execFileSync } from "node:child_process";
|
|
import { mkdtempSync, readdirSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
const DIR = join(import.meta.dirname, "..", "cast-receiver");
|
|
const TYPES = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8" };
|
|
|
|
export const DEFAULT_API_ORIGINS = ["https://api.menivor.com"];
|
|
|
|
/**
|
|
* The allowlist from the environment: exact https origins only; anything else stops the publish.
|
|
* @param {Record<string, string | undefined>} [env]
|
|
*/
|
|
export function apiOrigins(env = process.env) {
|
|
const raw = (env.CAST_API_ORIGINS || "").split(",").map((v) => v.trim()).filter(Boolean);
|
|
if (!raw.length) return DEFAULT_API_ORIGINS;
|
|
return raw.map((entry) => {
|
|
let url;
|
|
try {
|
|
url = new URL(entry);
|
|
} catch {
|
|
throw new Error(`CAST_API_ORIGINS: ${entry} is not a URL`);
|
|
}
|
|
if (url.protocol !== "https:" || url.username || url.password || url.origin !== entry.replace(/\/+$/, "")) {
|
|
throw new Error(`CAST_API_ORIGINS: ${entry} must be a bare https origin like https://api.menivor.com`);
|
|
}
|
|
return url.origin;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* The receiver's config.js for this environment.
|
|
* @param {Record<string, string | undefined>} [env]
|
|
*/
|
|
export function renderConfig(env = process.env) {
|
|
return [
|
|
"// Generated by scripts/cast-publish.mjs from CAST_API_ORIGINS / CAST_ALLOW_LOCALHOST.",
|
|
`export const API_ORIGINS = ${JSON.stringify(apiOrigins(env))};`,
|
|
`export const ALLOW_LOCALHOST = ${env.CAST_ALLOW_LOCALHOST === "1"};`,
|
|
"",
|
|
].join("\n");
|
|
}
|
|
|
|
/**
|
|
* Path of the config.js to upload: the committed default, or a generated copy when the env overrides it.
|
|
* @param {Record<string, string | undefined>} [env]
|
|
*/
|
|
export function configFile(env = process.env) {
|
|
if (!env.CAST_API_ORIGINS && env.CAST_ALLOW_LOCALHOST !== "1") return join(DIR, "config.js");
|
|
const file = join(mkdtempSync(join(tmpdir(), "menivor-cast-")), "config.js");
|
|
writeFileSync(file, renderConfig(env));
|
|
return file;
|
|
}
|
|
|
|
export function uploads(files, bucket = "menivor-public", prefix = "cast", config = join(DIR, "config.js")) {
|
|
return files
|
|
.filter((name) => Object.keys(TYPES).some((ext) => name.endsWith(ext)))
|
|
.sort()
|
|
.map((name) => ["r2", "object", "put", `${bucket}/${prefix}/${name}`, "--file", name === "config.js" ? config : join(DIR, name),
|
|
"--content-type", TYPES[name.slice(name.lastIndexOf("."))], "--cache-control", "public, max-age=300", "--remote"]);
|
|
}
|
|
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
if (process.env.CAST_ALLOW_LOCALHOST === "1" && (process.env.CAST_R2_PREFIX || "cast") === "cast") {
|
|
throw new Error("CAST_ALLOW_LOCALHOST=1 is for a dev receiver: set CAST_R2_PREFIX to something other than cast");
|
|
}
|
|
const commands = uploads(readdirSync(DIR), process.env.CAST_R2_BUCKET || undefined, process.env.CAST_R2_PREFIX || undefined,
|
|
configFile(process.env));
|
|
for (const args of commands) {
|
|
console.log(`npx wrangler ${args.map((a) => (/[\s;]/.test(a) ? JSON.stringify(a) : a)).join(" ")}`);
|
|
if (process.argv.includes("--run")) execFileSync("npx", ["wrangler", ...args], { stdio: "inherit" });
|
|
}
|
|
}
|