| 1 | // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt |
| 2 | |
| 3 | import { HTTP_MESSAGES, MD_TAGS } from '@hfs/shared' |
| 4 | import { Link } from '@mui/material' |
| 5 | import httpCodes from './httpCodes' |
| 6 | export * from '@hfs/shared' |
| 7 | |
| 8 | ;(MD_TAGS as any).a = Link |
| 9 | |
| 10 | export function err2msg(code: string | number) { |
| 11 | const permPath = typeof code === 'string' && code.split("Error: EPERM: operation not permitted, access ")[1]?.split('\n')[0] |
| 12 | if (permPath) |
| 13 | return `Access denied on disk for ${permPath}` |
| 14 | return { |
| 15 | github_quota: "Request denied. You may have reached the limit, retry later.", |
| 16 | ENOENT: "Not found", |
| 17 | ENOTDIR: "Not a folder", |
| 18 | }[code] || HTTP_MESSAGES[code as any] || httpCodes[code] || String(code) // prefer short form, as httpCodes is quite long |
| 19 | } |
| 20 | |
| 21 | export function formatTimestamp(x: number | string | Date) { |
| 22 | return !x ? '' : (x instanceof Date ? x : new Date(x)).toLocaleString() |
| 23 | } |