Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

feat: file card size limit error

JovannMC4dd5eca52edd
diff --git a/messages/en.json b/messages/en.json
index 49c703a..418a751 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -211,7 +211,7 @@
"server": "what are you doing..? you're supposed to run the vertd server!",
"not_found": "Could not find the vertd instance to start video conversion. Are you sure the instance URL is set correctly?",
"ratelimit": "Your video, '{filename}', has failed to convert a few times. To prevent server overload, further conversion attempts for this file have been temporarily blocked. Please try again later.",
- "file_too_large": "This file is too big for the specified vertd server ({fileSize}/{limit}). Please choose a smaller file or use another converter/server.",
+ "file_too_large": "This file is too big for the specified vertd server ({fileSize}/{limit}). Try another server or converter.",
"failed_to_keep": "Failed to keep the video on the server: {error}",
"retry": "Retrying video conversion for {filename} with different settings due to failure. This may take longer than usual.",
"generic": {
@@ -293,7 +293,7 @@
"title": "Server video conversion",
"status": "status:",
"loading": "loading...",
- "available": "available, commit id {commitId}",
+ "available": "available, size limit {sizeLimit}, commit id {commitId}",
"unavailable": "unavailable (is the url right?)",
"description": {
"main": "When possible, VERT converts videos locally in your browser, however some conversions may require the use of the <code>vertd</code> project, a server wrapper for FFmpeg. This allows you to convert videos through the convenience of VERT's web interface, while still being able to harness the power of your GPU to do it as quickly as possible.",
diff --git a/src/lib/converters/vertd/vertd.svelte.ts b/src/lib/converters/vertd/vertd.svelte.ts
index 11b8184..f2fd54b 100644
--- a/src/lib/converters/vertd/vertd.svelte.ts
+++ b/src/lib/converters/vertd/vertd.svelte.ts
@@ -13,9 +13,7 @@ import { ToastManager } from "$lib/util/toast.svelte";
import type {
SettingDefinition,
ConversionSettings,
- NormalizedSettings,
} from "$lib/types/conversion-settings";
-import { formatBytes } from "$lib/util/file";
interface UploadResponse {
id: string;
@@ -62,6 +60,9 @@ export const vertdFetch: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = async (url: any, options: RequestInit, body?: any) => {
const domain = await VertdInstance.instance.url();
+
+ if (!domain) return undefined;
+
const headers = new Headers(options.headers);
for (const [key, value] of Object.entries(getVertdCustomHeaders()))
headers.set(key, value);
@@ -366,54 +367,6 @@ export class VertdConverter extends Converter {
this.status = "ready";
}
- private async getServerSizeLimit(apiUrl: string): Promise<number | null> {
- const cacheKey = `vertd:size-limit:${apiUrl}`;
-
- if (typeof sessionStorage !== "undefined") {
- try {
- const cached = sessionStorage.getItem(cacheKey);
- if (cached !== null) {
- const parsedCached = Number(cached);
- if (Number.isFinite(parsedCached) && parsedCached > 0) {
- this.log(
- `using cached vertd size limit: ${parsedCached} bytes`,
- );
- return parsedCached;
- }
- sessionStorage.removeItem(cacheKey);
- }
- } catch (e) {
- this.error(
- `failed to read vertd size limit from sessionStorage: ${e}`,
- );
- }
- }
-
- try {
- const limit = await vertdFetch("/api/size_limit", {
- method: "GET",
- });
- const parsed = Number(limit);
- if (!Number.isFinite(parsed) || parsed <= 0) return null;
-
- if (typeof sessionStorage !== "undefined") {
- try {
- sessionStorage.setItem(cacheKey, parsed.toString());
- } catch (e) {
- this.error(
- `failed to cache vertd size limit in sessionStorage: ${e}`,
- );
- }
- }
-
- this.log(`fetched vertd size limit: ${parsed} bytes`);
- return parsed;
- } catch (e) {
- this.error(`failed to fetch vertd size limit: ${e}`);
- return null;
- }
- }
-
private blocked(hash: string): boolean {
let blockedHashes = Settings.instance.settings.vertdBlockedHashes;
@@ -657,43 +610,6 @@ export class VertdConverter extends Converter {
return defaults;
}
- public async normalizeSettings(
- input: VertFile,
- to: string,
- settings: ConversionSettings,
- ): Promise<NormalizedSettings> {
- const normalized = { ...settings };
- const changes: NormalizedSettings["changes"] = [];
-
- const change = (setting: string, newValue: string | number) => {
- const oldValue = normalized[setting];
- if (oldValue === newValue) return;
-
- normalized[setting] = newValue;
- changes.push({
- setting,
- oldValue,
- newValue,
- file: input.name,
- });
- };
-
- // handled in backend now
- // if (to === ".mxf") {
- // change("sampleRate", "48000");
- // }
-
- // // gxf was used for tv program systems/archives, so only PAL/NTSC resolutions
- // if (to === ".gxf") {
- // // for now, just PAL cause highest res at 720x576
- // change("resolution", "720x576");
- // change("sampleRate", "48000");
- // change("audioChannels", "1");
- // }
-
- return { settings: normalized, changes };
- }
-
public async convert(
input: VertFile,
to: string,
@@ -722,19 +638,6 @@ export class VertdConverter extends Converter {
}
const apiUrl = await VertdInstance.instance.url();
- const sizeLimit =
- (await this.getServerSizeLimit(apiUrl)) || Number.POSITIVE_INFINITY; // fall back to no limit just in case - server will block if too large anyways
- if (sizeLimit !== null && fileUpload.file.size > sizeLimit) {
- this.log(
- `blocked upload for ${input.name}: ${fileUpload.file.size} bytes exceeds server limit of ${sizeLimit} bytes`,
- );
- throw new Error(
- m["convert.errors.vertd.file_too_large"]({
- fileSize: formatBytes(fileUpload.file.size),
- limit: formatBytes(sizeLimit),
- }),
- );
- }
const uploadTask = await createUploadTask(fileUpload);
this.activeUploads.set(input.id, uploadTask);
diff --git a/src/lib/sections/settings/Vertd.svelte b/src/lib/sections/settings/Vertd.svelte
index ecdf601..c00bb11 100644
--- a/src/lib/sections/settings/Vertd.svelte
+++ b/src/lib/sections/settings/Vertd.svelte
@@ -11,9 +11,11 @@
import {
VertdInstance,
getVertdCustomHeaders,
+ vertdSizeLimit,
type VertdInner,
} from "./vertdSettings.svelte";
import FancyInput from "$lib/components/functional/FancyInput.svelte";
+ import { formatBytes } from "$lib/util/file";
let vertdCommit = $state<string | null>(null);
let abortController: AbortController | null = null;
@@ -81,6 +83,7 @@
? m["settings.vertd.loading"]()
: m["settings.vertd.available"]({
commitId: vertdCommit,
+ sizeLimit: formatBytes($vertdSizeLimit),
})
: m["settings.vertd.unavailable"]()}
</p>
diff --git a/src/lib/sections/settings/vertdSettings.svelte.ts b/src/lib/sections/settings/vertdSettings.svelte.ts
index c8819f5..e3c6a2a 100644
--- a/src/lib/sections/settings/vertdSettings.svelte.ts
+++ b/src/lib/sections/settings/vertdSettings.svelte.ts
@@ -1,6 +1,8 @@
import { Settings } from "./index.svelte";
import { PUB_VERTD_URL } from "$env/static/public";
import { log } from "$lib/util/logger";
+import { writable } from "svelte/store";
+import { getVertdLimit } from "$lib/store/index.svelte";
const LOCATIONS = [
{ url: "https://eu.vertd.vert.sh" },
@@ -33,6 +35,8 @@ export const getVertdCustomHeaders = (): Record<string, string> => {
return headers;
};
+export const vertdSizeLimit = writable(Number.POSITIVE_INFINITY);
+
export class VertdInstance {
public static instance = new VertdInstance();
@@ -134,3 +138,73 @@ export class VertdInstance {
}
}
}
+
+export function useVertdSizeLimit() {
+ $effect(() => {
+ let cancelled = false;
+
+ const loadLimit = async () => {
+ const apiUrl = await VertdInstance.instance.url();
+ if (cancelled) return;
+
+ const cacheKey = `vertd:size-limit:${apiUrl}`;
+ const sessionStorageAvailable =
+ typeof sessionStorage !== "undefined";
+
+ let cachedLimit: number | null = null;
+
+ if (sessionStorageAvailable) {
+ try {
+ const cached = sessionStorage.getItem(cacheKey);
+ if (cached !== null) {
+ const parsed = Number(cached);
+ if (Number.isFinite(parsed) && parsed > 0) {
+ cachedLimit = parsed;
+ } else {
+ sessionStorage.removeItem(cacheKey);
+ }
+ }
+ } catch (e) {
+ log(
+ ["vertd"],
+ `failed to read vertd size limit from sessionStorage: ${e}`,
+ );
+ }
+ }
+
+ if (cachedLimit !== null) {
+ log(
+ ["vertd"],
+ `using cached vertd size limit: ${cachedLimit} bytes`,
+ );
+ vertdSizeLimit.set(cachedLimit);
+ return;
+ }
+
+ const serverLimit = await getVertdLimit();
+ const finalLimit = serverLimit ?? Number.POSITIVE_INFINITY;
+ vertdSizeLimit.set(finalLimit);
+ log(
+ ["vertd"],
+ `fetched vertd size limit: ${finalLimit} bytes`,
+ );
+
+ if (sessionStorageAvailable) {
+ try {
+ sessionStorage.setItem(cacheKey, finalLimit.toString());
+ } catch (e) {
+ log(
+ ["vertd"],
+ `failed to cache vertd size limit in sessionStorage: ${e}`,
+ );
+ }
+ }
+ };
+
+ void loadLimit();
+
+ return () => {
+ cancelled = true;
+ };
+ });
+}
diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts
index ef7a0ff..2f53249 100644
--- a/src/lib/store/index.svelte.ts
+++ b/src/lib/store/index.svelte.ts
@@ -13,6 +13,7 @@ import { ToastManager } from "$lib/util/toast.svelte";
import { GB } from "$lib/util/consts";
import { readSettings } from "$lib/util/settings";
import { formatFilename } from "$lib/util/file";
+import { vertdFetch } from "$lib/converters/vertd/vertd.svelte";
class Files {
public files = $state<VertFile[]>([]);
@@ -663,3 +664,19 @@ export const getMaxArrayBufferSize = (): number => {
};
export const MAX_ARRAY_BUFFER_SIZE = getMaxArrayBufferSize();
+
+export const getVertdLimit = async (): Promise<number | null> => {
+ try {
+ const limit = await vertdFetch("/api/size_limit", {
+ method: "GET",
+ });
+ const parsed = Number(limit);
+ if (!Number.isFinite(parsed) || parsed <= 0) return null;
+
+ log(["vertd"], `fetched vertd size limit: ${parsed} bytes`);
+ return parsed;
+ } catch (e) {
+ error(["vertd"], `failed to fetch vertd size limit: ${e}`);
+ return null;
+ }
+};
diff --git a/src/lib/types/file.svelte.ts b/src/lib/types/file.svelte.ts
index 7887dba..28b56e1 100644
--- a/src/lib/types/file.svelte.ts
+++ b/src/lib/types/file.svelte.ts
@@ -25,6 +25,7 @@ export class VertFile {
public from = $state("");
public name = $state("");
public to = $state("");
+ public size = $state(0);
public fileType = $state<Awaited<ReturnType<typeof fileTypeFromBuffer>>>();
public isZip = $state(() => this.from === ".zip");
@@ -59,6 +60,7 @@ export class VertFile {
this.convert = this.convert.bind(this);
this.download = this.download.bind(this);
this.blobUrl = blobUrl;
+ this.size = newFile.size;
log(
["file", "init"],
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index c67ff2c..361b495 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -6,7 +6,7 @@
import {
DISABLE_ALL_EXTERNAL_REQUESTS,
VERT_NAME,
- } from "$lib/util/consts.js";
+ } from "$lib/util/consts";
import * as Layout from "$lib/components/layout";
import * as Navbar from "$lib/components/layout/Navbar";
import { Settings } from "$lib/sections/settings/index.svelte";
@@ -22,11 +22,14 @@
} from "$lib/store/index.svelte";
import "$lib/css/app.scss";
import { browser } from "$app/environment";
- import { initStores as initAnimStores } from "$lib/util/animation.js";
- import { VertdInstance } from "$lib/sections/settings/vertdSettings.svelte.js";
- import { ToastManager } from "$lib/util/toast.svelte.js";
- import { m } from "$lib/paraglide/messages.js";
- import { log } from "$lib/util/logger.js";
+ import { initStores as initAnimStores } from "$lib/util/animation";
+ import {
+ useVertdSizeLimit,
+ VertdInstance,
+ } from "$lib/sections/settings/vertdSettings.svelte";
+ import { ToastManager } from "$lib/util/toast.svelte";
+ import { m } from "$lib/paraglide/messages";
+ import { log } from "$lib/util/logger";
let { children } = $props();
let enablePlausible = $state(false);
@@ -130,6 +133,11 @@
history.pushState = History.prototype.pushState;
}
});
+
+ onMount(() => {
+ // query vertd server for size limit on mount and on settings change
+ useVertdSizeLimit();
+ });
</script>
<svelte:head>
diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte
index 3198acb..04955bd 100644
--- a/src/routes/convert/+page.svelte
+++ b/src/routes/convert/+page.svelte
@@ -35,6 +35,8 @@
import { Settings } from "$lib/sections/settings/index.svelte";
import { MAX_ARRAY_BUFFER_SIZE } from "$lib/store/index.svelte";
import { GB } from "$lib/util/consts";
+ import { formatBytes } from "$lib/util/file";
+ import { vertdSizeLimit } from "$lib/sections/settings/vertdSettings.svelte";
let processedFileIds = $state(new Set<string>());
@@ -263,6 +265,8 @@
(f) => f.name === file.from,
)}
{@const isLarge = file.isLarge()}
+ {@const size = file.size}
+ {@const limit = $vertdSizeLimit}
{#if formatInfo && !formatInfo.fromSupported}
<div
class="h-full flex flex-col text-center justify-center text-failure"
@@ -274,6 +278,21 @@
{m["convert.errors.format_output_only"]()}
</p>
</div>
+ {:else if size > limit}
+ <div
+ class="h-full flex flex-col text-center justify-center text-failure"
+ >
+ <p class="font-body font-bold">
+ {m["convert.errors.cant_convert"]()}
+ </p>
+ <p class="font-normal">
+ {m["convert.errors.vertd.file_too_large"]({
+ fileSize: formatBytes(size),
+ limit: formatBytes(limit),
+ })}
+ </p>
+ </div>
+ <!-- TODO: add settings button to change to mediabunny, only show if vertd is actually being used -->
{:else if isLarge && !file.supportsStreaming()}
<div
class="h-full flex flex-col text-center justify-center text-failure"
@@ -299,7 +318,7 @@
type: isAudio
? m["convert.errors.audio"]()
: isVideo
- ? "Video"
+ ? m["convert.errors.video"]()
: isDocument
? m["convert.errors.doc"]()
: m["convert.errors.image"](),
@@ -318,7 +337,7 @@
type: isAudio
? m["convert.errors.audio"]()
: isVideo
- ? "Video"
+ ? m["convert.errors.video"]()
: isDocument
? m["convert.errors.doc"]()
: m["convert.errors.image"](),