components
All repositories: gitoria
2.3 KB
// lib/uploads.hl — WHERE THE SHOWCASE KEEPS UPLOADED FILES (the site's decision, not the components'): the file upload demo// 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// storage/md-files (served at /md-editor/files/…, see project.hl), only with a known kind of extension (nothing a browser would// run). Both keep a file for one day: every upload first stores, then removes what is older.import { writeFile, mkDir, listDir, remove } from 'hl:fs'import { randomBytes } from 'hl:crypto'import { now } from 'hl:time'static kinds = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'txt', 'md', 'zip']// the file upload demo: one file in, its name and size backstatic storeUpload = (file) => {mkDir('storage/uploads')writeFile('storage/uploads/' + now() + '-' + randomBytes(6) + '.bin', file.bytes)dropOld('storage/uploads')return { name = file.name size = file.size }}// 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 backstatic storeMessage = (text, files) => {mkDir('storage/uploads')let names = ''for (f of files) {writeFile('storage/uploads/' + now() + '-' + randomBytes(6) + '.bin', f.bytes)names = names + (names == '' ? '' : ', ') + f.name + ' (' + f.bytes.length + ' B)'}dropOld('storage/uploads')return { text = text files = names }}// the Markdown editor demo: files in, the address of each back, in orderstatic storeMdFiles = (files) => {mkDir('storage/md-files')urls = []for (f of files) {let stored = now() + '-' + randomBytes(6) + '.' + extensionOf(f.name)writeFile('storage/md-files/' + stored, f.bytes)urls.push('/md-editor/files/' + stored)}dropOld('storage/md-files')return urls}// the stored extension: the file's own when it is a known kind, else 'bin'static extensionOf = (name) => {dot = name.lastIndexOf('.')ext = dot >= 0 ? name.slice(dot + 1).toLowerCase() : ''let known = falsefor (k of kinds) { if (k == ext) { known = true } }return known ? ext : 'bin'}// removes the files of a folder stored more than a day ago (the name starts with the time it was stored)static dropOld = (dir) => {for (e of listDir(dir)) {let stamp = toNumber(e.name.slice(0, e.name.indexOf('-')))if (stamp != null && stamp < now() - 86400000) { remove(e.path) }}}
Branches
Latest commits
- 8176eb14Record CS23b deployment and live verificationmre
- 84e3ddaaRemove blank line before pagination Style closing bracemre
- a92298ddRecord exact CSS and same-date proof after specificity reviewmre
- c71a0abePreserve consumer theme specificity with nested tag rulesmre
- 64a2bc27Document CS23b style formatting proof and review statusmre
- a72b57cficons: nest Style rules in the language's formmre
- 927616e2pagination: nest Style rules in the language's formmre
- aab8ad29code-editor: nest Style rules in the language's formmre
- ba30727afile-upload: nest Style rules in the language's formmre
- 42fefa4emodal: nest Style rules in the language's formmre
- 6fd953e3range-picker: nest Style rules in the language's formmre
- f661951ddate-picker: nest Style rules in the language's formmre
- 363577e6media-player: nest Style rules in the language's formmre
- 0b3fd8c9comments: nest Style rules in the language's formmre
- 67e043c8plugins/web/README.md from hybriel cb9e480dmre
- 519b56e9styles.hl: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
- 29f63d01md-editor: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
- 869f49c7files-upload: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
- f60dab20month-view: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
- 5b3c349aRe-vendor to Hybriel set day35 (cb9e480d): plugins core and web sources, README vendoring notemre