From dc20519c860571f2803a6e031019fa525e9d729f Mon Sep 17 00:00:00 2001 From: not-nullptr <62841684+not-nullptr@users.noreply.github.com> Date: Sat, 22 Mar 2025 01:07:46 +0000 Subject: [PATCH] feat: customisable default vertd url --- .env.example | 3 +- Dockerfile | 2 + docker-compose.yml | 2 + src/lib/converters/vertd.svelte.ts | 75 ++++++++++++++--------- src/lib/sections/settings/index.svelte.ts | 3 +- 5 files changed, 53 insertions(+), 32 deletions(-) diff --git a/.env.example b/.env.example index 500a46c..2a68a73 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ PUB_HOSTNAME=localhost:5173 # only gets used for plausible (for now) PUB_PLAUSIBLE_URL=https://plausible.example.com # can be empty -PUB_ENV=development # "production", "development", or "nightly" \ No newline at end of file +PUB_ENV=development # "production", "development", or "nightly" +PUB_VERTD_URL=https://vertd.vert.sh # whatever you want the default vertd url to be \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 48aed31..d15dfdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,12 @@ WORKDIR /app ARG PUB_ENV ARG PUB_HOSTNAME ARG PUB_PLAUSIBLE_URL +ARG PUB_VERTD_URL ENV PUB_ENV=${PUB_ENV} ENV PUB_HOSTNAME=${PUB_HOSTNAME} ENV PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL} +ENV PUB_VERTD_URL=${PUB_VERTD_URL} COPY package.json ./ diff --git a/docker-compose.yml b/docker-compose.yml index 8bbb17a..b3e1485 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: - PUB_HOSTNAME=${PUB_HOSTNAME:-vert.sh} - PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL:-https://plausible.example.com} - PUB_ENV=${PUB_ENV:-production} + - PUB_VERTD_URL=${PUB_VERTD_URL:-https://vertd.vert.sh} - PORT=${PORT:-3000} build: context: . @@ -13,6 +14,7 @@ services: PUB_HOSTNAME: ${PUB_HOSTNAME:-vert.sh} PUB_PLAUSIBLE_URL: ${PUB_PLAUSIBLE_URL:-https://plausible.example.com} PUB_ENV: ${PUB_ENV:-production} + PUB_VERTD_URL: ${PUB_VERTD_URL:-https://vertd.vert.sh} restart: unless-stopped ports: - ${PORT:-3000}:80 diff --git a/src/lib/converters/vertd.svelte.ts b/src/lib/converters/vertd.svelte.ts index d7adf9c..caf0c40 100644 --- a/src/lib/converters/vertd.svelte.ts +++ b/src/lib/converters/vertd.svelte.ts @@ -60,33 +60,26 @@ export type ConversionSpeed = | "fast" | "ultraFast"; +interface HelloMessage { + type: "hello"; + auth: string; +} + interface StartJobMessage { type: "startJob"; - data: { - token: string; - jobId: string; - to: string; - speed: ConversionSpeed; - }; + to: string; + speed: ConversionSpeed; } interface ErrorMessage { type: "error"; - data: { - message: string; - }; + message: string; } -interface ProgressMessage { - type: "progressUpdate"; - data: ProgressData; -} +type ProgressMessage = ProgressData; interface CompletedMessage { type: "jobFinished"; - data: { - jobId: string; - }; } interface FpsProgress { @@ -102,6 +95,7 @@ interface FrameProgress { type ProgressData = FpsProgress | FrameProgress; type VertdMessage = + | HelloMessage | StartJobMessage | ErrorMessage | ProgressMessage @@ -127,6 +121,17 @@ const uploadFile = async (file: VertFile): Promise => { const apiUrl = Settings.instance.settings.vertdURL; const formData = new FormData(); formData.append("file", file.file, file.name); + formData.append( + "json", + new Blob( + [ + JSON.stringify({ + jobType: "conversion", + }), + ], + { type: "application/json" }, + ), + ); const xhr = new XMLHttpRequest(); xhr.open("POST", `${apiUrl}/api/upload`, true); @@ -236,14 +241,16 @@ export class VertdConverter extends Converter { ws.onopen = () => { const speed = Settings.instance.settings.vertdSpeed; this.log("opened ws connection to vertd"); + const hello: HelloMessage = { + type: "hello", + auth: uploadRes.auth, + }; + ws.send(JSON.stringify(hello)); + this.log("sent hello message"); const msg: StartJobMessage = { type: "startJob", - data: { - jobId: uploadRes.id, - token: uploadRes.auth, - to, - speed, - }, + to, + speed, }; ws.send(JSON.stringify(msg)); this.log("sent startJob message"); @@ -253,12 +260,20 @@ export class VertdConverter extends Converter { const msg: VertdMessage = JSON.parse(e.data); this.log(`received message ${msg.type}`); switch (msg.type) { - case "progressUpdate": { - const data = msg.data; - if (data.type !== "frame") break; - const frame = data.data; + // case "progressUpdate": { + // const data = msg.data; + // if (data.type !== "frame") break; + // const frame = data.data; + // input.progress = progressEstimate( + // frame / uploadRes.totalFrames, + // "convert", + // ); + // break; + // } + + case "frame": { input.progress = progressEstimate( - frame / uploadRes.totalFrames, + msg.data / uploadRes.totalFrames, "convert", ); break; @@ -267,7 +282,7 @@ export class VertdConverter extends Converter { case "jobFinished": { this.log("job finished"); ws.close(); - const url = `${apiUrl}/api/download/${msg.data.jobId}/${uploadRes.auth}`; + const url = `${apiUrl}/api/download/${uploadRes.auth}`; this.log(`downloading from ${url}`); // const res = await fetch(url).then((res) => res.blob()); const res = await downloadFile(url, input); @@ -276,8 +291,8 @@ export class VertdConverter extends Converter { } case "error": { - this.log(`error: ${msg.data.message}`); - reject(msg.data.message); + this.log(`error: ${msg.message}`); + reject(msg.message); } } }; diff --git a/src/lib/sections/settings/index.svelte.ts b/src/lib/sections/settings/index.svelte.ts index 6c7a933..a53b844 100644 --- a/src/lib/sections/settings/index.svelte.ts +++ b/src/lib/sections/settings/index.svelte.ts @@ -1,3 +1,4 @@ +import { PUB_VERTD_URL } from "$env/static/public"; import type { ConversionSpeed } from "$lib/converters/vertd.svelte"; export { default as Appearance } from "./Appearance.svelte"; @@ -18,7 +19,7 @@ export class Settings { public settings: ISettings = $state({ filenameFormat: "VERT_%name%", plausible: true, - vertdURL: "https://vertd.vert.sh", + vertdURL: PUB_VERTD_URL, vertdSpeed: "slow", });