Files: 7f130593fc972ef3178827c582d63c2fa8451fe7 / volunteers / addingZines.js
815 bytesRaw
1 | const smarkt = require('smarkt') |
2 | const _ = require('lodash') |
3 | |
4 | var archive = new DatArchive(window.location) |
5 | |
6 | function 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 | |
14 | function 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 | |
23 | function 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 | |
31 | module.exports = store |
32 |
Built with git-ssb-web