mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-17 21:24:11 +00:00
7e3aaa8c30
* style: consistent casing on menu * refactor: bundle demo from code * feat: allow uploading custom views
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { baseURI, serverURL } from '../../../../externals';
|
|
|
|
export const customViewsDocs = 'https://docs.getontime.no/features/custom-views/';
|
|
const customViewSlugPattern = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
const maxUploadBytes = 4_000_000;
|
|
export const maxUploadLabel = `${maxUploadBytes / 1_000_000}MB`;
|
|
|
|
export function getSlugError(slug: string): string | null {
|
|
if (!slug) {
|
|
return 'Name is required.';
|
|
}
|
|
if (!customViewSlugPattern.test(slug)) {
|
|
return 'Use lowercase letters, numbers, and dashes only.';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getFileError(file: File | null): string | null {
|
|
if (!file) {
|
|
return 'index.html is required.';
|
|
}
|
|
if (file.name.toLowerCase() !== 'index.html') {
|
|
return 'Only index.html uploads are supported.';
|
|
}
|
|
if (file.size === 0) {
|
|
return 'Uploaded file is empty.';
|
|
}
|
|
if (file.size > maxUploadBytes) {
|
|
return `File size limit (${maxUploadLabel}) exceeded.`;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getViewUrl(slug: string): string {
|
|
const url = new URL(serverURL);
|
|
const path = slug ? `external/${encodeURIComponent(slug)}/` : 'external/';
|
|
url.pathname = baseURI ? `${baseURI}/${path}` : `/${path}`;
|
|
return url.toString();
|
|
}
|