refactor: improve type safety, Svelte 5 reactivity, and API resilience

This commit is contained in:
Scott Idem
2026-01-16 17:29:33 -05:00
parent 09d1aa6720
commit ecb6ba5250
15 changed files with 6089 additions and 74 deletions

View File

@@ -33,7 +33,8 @@ export type key_val = {
};
/* This utility function will add commas to a number. */
function number_w_commas(x) {
function number_w_commas(x: number | string) {
if (!x) return '0';
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
@@ -86,6 +87,14 @@ function create_a_element({
extension = null,
text = 'Download',
class_li = 'text-blue-500'
}: {
account_id: string;
base_url: string;
hosted_file_id: string;
filename?: string | null;
extension?: string | null;
text?: string;
class_li?: string;
}) {
return `<a href="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" class="${class_li}">${text}</a>`;
}
@@ -99,6 +108,15 @@ function create_img_element({
class_li = 'max-w-64',
style = '',
inc_link = false
}: {
account_id: string;
base_url: string;
hosted_file_id: string;
filename?: string | null;
extension?: string | null;
class_li?: string;
style?: string;
inc_link?: boolean;
}) {
let img_html = '';
if (filename) {
@@ -129,6 +147,14 @@ function create_video_element({
extension = null,
class_li = 'max-w-64',
inc_link = false
}: {
account_id: string;
base_url: string;
hosted_file_id: string;
filename?: string | null;
extension?: string | null;
class_li?: string;
inc_link?: boolean;
}) {
let video_html = '';
if (filename) {