Skip to content
Permalink
Browse files

adds unique ids instead of timestamps

  • Loading branch information...
vnglst committed Nov 11, 2016
1 parent 02d4171 commit a9d1c3d2b9e7c39345052255f0e9bd8855dbe4a7
Showing with 11 additions and 42 deletions.
  1. +2 −1 package.json
  2. +5 −4 routes/pdf.js
  3. +0 −37 user-letters/letter1478890738915.md
  4. BIN user-letters/output1478890738915.pdf
  5. +4 −0 yarn.lock
@@ -19,7 +19,8 @@
"nodemon": "^1.11.0",
"pdfkit": "^0.8.0",
"pug": "~2.0.0-beta6",
"serve-favicon": "~2.3.0"
"serve-favicon": "~2.3.0",
"shortid": "^2.2.6"
},
"devDependencies": {
"standard": "^8.5.0"
@@ -1,4 +1,5 @@
const express = require('express')
const shortid = require('shortid')
const router = express.Router()
const fs = require('fs')
const
@@ -23,11 +24,11 @@ const makePDF = (inputFile, outputFile) => {
}

router.post('/', (req, res) => {
// Make sure user-letters folder exists
spawn(`mkdir`, [`-p`, `user-letters`])
const timestamp = new Date()
.getTime()
const inputFile = `user-letters/letter${timestamp}.md`
const outputFile = `user-letters/output${timestamp}.pdf`
const uniqueId = shortid.generate()
const inputFile = `user-letters/letter-${uniqueId}.md`
const outputFile = `user-letters/output-${uniqueId}.pdf`
const letterContent = formBodyToMarkDown(req.body)
fs.writeFile(inputFile, letterContent, () => {
makePDF(inputFile, outputFile)

This file was deleted.

Oops, something went wrong.
Binary file not shown.
@@ -2399,6 +2399,10 @@ shelljs@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.6.1.tgz#ec6211bed1920442088fe0f70b2837232ed2c8a8"

shortid:
version "2.2.6"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.6.tgz#3abbefc6c51074cf2c1f1e72f6216a1b45876d72"

signal-exit@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.1.tgz#5a4c884992b63a7acd9badb7894c3ee9cfccad81"

0 comments on commit a9d1c3d

Please sign in to comment.
You can’t perform that action at this time.