gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb2980734b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmreb2980734/lib/uploads.hl

2.3 KB

  1. // lib/uploads.hl — WHERE THE SHOWCASE KEEPS UPLOADED FILES (the site's decision, not the components'): the file upload demo
  2. // keeps each file in storage/uploads under a random name (nothing is served back; the pick-first demo too); the Markdown editor demo keeps its files in
  3. // storage/md-files (served at /md-editor/files/…, see project.hl), only with a known kind of extension (nothing a browser would
  4. // run). Both keep a file for one day: every upload first stores, then removes what is older.
  5. import { writeFile, mkDir, listDir, remove } from 'hl:fs'
  6. import { randomBytes } from 'hl:crypto'
  7. import { now } from 'hl:time'
  8. static kinds = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'txt', 'md', 'zip']
  9. // the file upload demo: one file in, its name and size back
  10. static storeUpload = (file) => {
  11. mkDir('storage/uploads')
  12. writeFile('storage/uploads/' + now() + '-' + randomBytes(6) + '.bin', file.bytes)
  13. dropOld('storage/uploads')
  14. return { name = file.name size = file.size }
  15. }
  16. // the pick-first demo (files upload in pick mode): a message's text and its files in; the text and "name (size)" of each file back
  17. static storeMessage = (text, files) => {
  18. mkDir('storage/uploads')
  19. let names = ''
  20. for (f of files) {
  21. writeFile('storage/uploads/' + now() + '-' + randomBytes(6) + '.bin', f.bytes)
  22. names = names + (names == '' ? '' : ', ') + f.name + ' (' + f.bytes.length + ' B)'
  23. }
  24. dropOld('storage/uploads')
  25. return { text = text files = names }
  26. }
  27. // the Markdown editor demo: files in, the address of each back, in order
  28. static storeMdFiles = (files) => {
  29. mkDir('storage/md-files')
  30. urls = []
  31. for (f of files) {
  32. let stored = now() + '-' + randomBytes(6) + '.' + extensionOf(f.name)
  33. writeFile('storage/md-files/' + stored, f.bytes)
  34. urls.push('/md-editor/files/' + stored)
  35. }
  36. dropOld('storage/md-files')
  37. return urls
  38. }
  39. // the stored extension: the file's own when it is a known kind, else 'bin'
  40. static extensionOf = (name) => {
  41. dot = name.lastIndexOf('.')
  42. ext = dot >= 0 ? name.slice(dot + 1).toLowerCase() : ''
  43. let known = false
  44. for (k of kinds) { if (k == ext) { known = true } }
  45. return known ? ext : 'bin'
  46. }
  47. // removes the files of a folder stored more than a day ago (the name starts with the time it was stored)
  48. static dropOld = (dir) => {
  49. for (e of listDir(dir)) {
  50. let stamp = toNumber(e.name.slice(0, e.name.indexOf('-')))
  51. if (stamp != null && stamp < now() - 86400000) { remove(e.path) }
  52. }
  53. }

Branches

Latest commits

  • b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
  • 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
  • 9e1ab228MP: report, LOG line, STATUS entrymre
  • dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
  • e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
  • 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
  • 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
  • 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre
  • 0a9216fbMdEditor: a Table button in the toolbar, a typed pipe row fills the cells, tables take the page theme's look; gate checks updated for 12 toolbar buttonsmre
  • f9d405c8comments: reactions row half as far from its comment (creator 2026-10-24: 'half this distance please'); the 44 px tap targets staymre
  • 4922f9cfsessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 0355975areports/MC-mobile.md, LOG, STATUS (MC)mre
  • 3f0a7229Month view, date picker, range picker: names follow the page language (English by default, not the browser's), weekday/month names formatted in UTC (a UTC+12 zone showed Tue first), 44 px day cells and buttons, Send row air; gate checks at 390 px for every page, popup and dialog (MC)mre
  • 29eb07eaPhone: 44 px targets on the site (brand, home links, buttons), comments, modal and pagination; the header is the brand alone on a phone; comments demo: labelled 'You are' group with the chosen user pressed (MC)mre
  • d1cc83e2reports/E2-toolbar.mdmre
  • 214c3183MdEditor on a phone: toolbar as two even rows of 44 px targets (no clipped icon, no swipe), 'Markdown source' label 15 px, table head 16 px; gate checks (E2)mre
  • 9215bbaareports/F5-empty.mdmre
  • 134b4e3eMdEditor: an editor the framework puts into the page is built at once (page observer), a surface put in anew under a built editor is redrawn; gates for both (hybriel#211)mre
  • 0dce2899reports/K1-bubble.mdmre
  • 6b0936a0comments: 'edited' foldable also drops the theme's border, margin and radius (display: contents alone left them computed)mre