gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit23b9164a23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre23b9164a/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

  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
  • 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