import { error } from '@sveltejs/kit';
import ago from 's-ago';
import { browser } from '$app/environment';
export type Comment = {
author: string;
timestamp: number;
id: string;
content: string;
content_html: string;
};
export const server = import.meta.env.VITE_SERVER
export const ui_server = import.meta.env.VITE_UI_SERVER;
export function timefmt(t_: number | null): string {
if (!t_) {
return '';
}
const t = new Date(t_);
if (new Date().getTime() - t.getTime() < 48 * 3600000) {
return ago(t);
} else {
const f = new Intl.DateTimeFormat('en-US', {
dateStyle: 'medium',
timeStyle: 'short'
});
return 'on ' + f.format(t);
}
}
export function errorMsg(status: number, y: object) {
if ('notFound' in y) {
throw error(404);
}
if ('suspended' in y && y.suspended) {
throw error(403, 'This account is suspended.');
}
if ('canRead' in y && !y.canRead) {
throw error(403, 'Insufficient permissions.');
}
if ('canWrite' in y && !y.canWrite) {
throw error(403, 'Insufficient permissions.');
}
throw error(status);
}