Create and delete tokens from web ui

This commit is contained in:
2025-03-19 21:08:59 +01:00
parent 544513d118
commit 7155d91bed
14 changed files with 822 additions and 1 deletions

View File

@ -0,0 +1,20 @@
import dayjs, { Dayjs } from "dayjs";
export function timeToDate(time: number | undefined): Dayjs | undefined {
if (!time) return undefined;
return dayjs(new Date(time * 1000));
}
export function dateToTime(date: Dayjs | undefined): number | undefined {
if (!date) return undefined;
return Math.floor(date.toDate().getTime() / 1000);
}
/**
* Get UNIX time
*
* @returns Number of seconds since Epoch
*/
export function time(): number {
return Math.floor(new Date().getTime() / 1000);
}

View File

@ -0,0 +1,32 @@
import { LenConstraint } from "../api/ServerApi";
/**
* Check if a constraint was respected or not
*
* @returns An error message appropriate for the constraint
* violation, if any, or undefined otherwise
*/
export function checkConstraint(
constraint: LenConstraint,
value: string | undefined
): string | undefined {
value = value ?? "";
if (value.length < constraint.min)
return `Please specify at least ${constraint.min} characters !`;
if (value.length > constraint.max)
return `Please specify at least ${constraint.min} characters !`;
return undefined;
}
/**
* Check out whether a given URL is valid or not
*/
export function checkURL(s: string): boolean {
try {
return Boolean(new URL(s));
} catch (e) {
return false;
}
}