Skip to content

Instantly share code, notes, and snippets.

@dereknelson
Created June 14, 2019 19:06
Show Gist options
  • Save dereknelson/62c8ab2f14cd2ffc753ffcad8629b315 to your computer and use it in GitHub Desktop.
Save dereknelson/62c8ab2f14cd2ffc753ffcad8629b315 to your computer and use it in GitHub Desktop.
Conversion
{
"name": "convertnote",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "nodemon --exec babel-node src/server.js",
"build": "babel src --out-dir dist",
"serve": "node dist/server.js"
},
"repository": "https://github.com/dereknelson/convertnote.git",
"author": "Derek <dereknelsony0@gmail.com>",
"dependencies": {
"axios": "^0.18.0",
"express": "^4.16.4",
"http": "^0.0.0",
"node-quill-converter": "^0.3.2",
"nodemon": "^1.18.7"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/node": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"morgan": "^1.9.1"
}
}
import http from 'http'
import middlewares from './config/middlewares.js'
import { convertHtmlToDelta } from 'node-quill-converter'
import axios from 'axios'
const app = require('express')(), server = http.Server(app)
middlewares(app)
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`listening on ${PORT}`))
app.post('/convert/', convert)
async function convert(req, res, next) {
return new Promise(async (resolve, reject) => {
const { url, token } = req.body
// url that looks like "https://mosaic-pilot-api.herokuapp.com/api/project/24406/notes/?limit=15&offset=0"
try {
const { data } = await axios.get(url, { headers: { Authorization: `Bearer: ${token}` } })
const { total_count, notes: theNotes } = data
let notes = theNotes.map(note => ({ ...note, body: convertHtmlToDelta(note.body) }))
res.send(JSON.stringify({ total_count, notes }))
} catch (error) {
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment