git ssb

0+

Zach! / dat-zine-library



Tree: 7f130593fc972ef3178827c582d63c2fa8451fe7

Files: 7f130593fc972ef3178827c582d63c2fa8451fe7 / volunteers / addingZines.js

815 bytesRaw
1const smarkt = require('smarkt')
2const _ = require('lodash')
3
4var archive = new DatArchive(window.location)
5
6function store (state, emitter) {
7 emitter.on('zine submitted', function (zineSubmission) {
8 var details = getDetails(zineSubmission)
9 var zineJson = JSON.stringify(details, null, 2)
10 writeZineTxt(zineJson, emitter)
11 })
12}
13
14function getDetails (form) {
15 var formData = new FormData(form)
16 var data = {}
17 for (var pair of formData.entries()) {
18 data[pair[0]] = pair[1]
19 }
20 return data
21}
22
23function writeZineTxt (zine, emitter) {
24 zine = JSON.parse(zine)
25 var fileName = zine.title.replace(/ /g, '-') + '.txt'
26 var pleasantText = smarkt.stringify(zine)
27 archive.writeFile(`zines/${fileName}`, pleasantText)
28 .then(() => emitter.emit('update library', zine))
29}
30
31module.exports = store
32

Built with git-ssb-web