Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
added export function
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyklee committed Apr 29, 2019
1 parent 7513b05 commit f801b5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
.DS_Store
node_modules
db/*
db/*
exports/*
20 changes: 20 additions & 0 deletions index.js
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const logger = require('morgan');
const path = require('path');
const http = require('http');
const fs = require('fs');
const port = process.env.PORT || 3030;
const Datastore = require('nedb');
const pathToData = path.resolve(__dirname, "db/db")
Expand Down Expand Up @@ -67,6 +68,25 @@ app.post("/api", (req, res) => {
});
})

/**
*
* Export all images to PNG on the server
* */
app.get("/export/all", (req, res) => {
db.find({}).sort({'created':1}).exec(function (err, docs) {
if(err){
return err;
}
docs.forEach(item => {
const outImage = item.image.replace(/^data:image\/png;base64,/, '');
fs.writeFileSync(path.resolve(__dirname, `./exports/${item.created}.png`) , outImage, 'base64');
console.log('writing ', `${item.created}.png`)
})
res.send('done!')
});
})



// use the http module to create an http server listening on the specified port
http.createServer(app).listen(port, () =>{
Expand Down

0 comments on commit f801b5f

Please sign in to comment.