hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { createSignal } from "solid-js"; |
| 2 | |
| 3 | // The whole set the avatar endpoint accepts — deliberately narrower than |
| 4 | // limits.file.image_content_types, which also carries SVG for other uploads |
| 5 | // and would be refused here. |
| 6 | export const AVATAR_CONTENT_TYPES = ["image/png", "image/jpeg", "image/webp", "image/gif"]; |
| 7 | |
| 8 | export const AVATAR_ACCEPT = AVATAR_CONTENT_TYPES.join(","); |
| 9 | |
| 10 | // GET /users/{id}/avatar answers at one fixed URL, so an upload or a delete |
| 11 | // leaves the address unchanged and the browser's in-memory image cache can go |
| 12 | // on serving the old bytes. Every mounted avatar reads this counter into its |
| 13 | // `?v=` query, so bumping it once re-requests all of them — which is also how |
| 14 | // the sidebar chip picks up a photo changed on the profile page. |
| 15 | const [avatarRevision, setAvatarRevision] = createSignal(0); |
| 16 | |
| 17 | export { avatarRevision }; |
| 18 | |
| 19 | export function bumpAvatarRevision(): void { |
| 20 | setAvatarRevision((n) => n + 1); |
| 21 | } |
| 22 | |
| 23 | export function formatBytes(bytes: number): string { |
| 24 | if (bytes >= 1024 * 1024) return `${Math.round(bytes / (1024 * 1024))} MB`; |
| 25 | if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`; |
| 26 | return `${bytes} B`; |
| 27 | } |