KawAnime/assets/api/watchList.js

35 lines
808 B
JavaScript
Raw Normal View History

/**
* Created by Kylart on 20/04/2017.
*/
const fs = require('fs')
const {userInfo} = require('os')
const {join} = require('path')
/* istanbul ignore next */
const wlPath = process.env.NODE_ENV !== 'KawAnime-test'
? join(userInfo().homedir, '.KawAnime', 'lists.json')
: join(userInfo().homedir, '.KawAnime-test', 'lists.json')
exports.getLists = (res) => {
const wlFile = require(wlPath)
console.log(`[WatchList] Gathered lists from local.`)
2017-05-08 13:18:10 +00:00
res.writeHead(200, {'Content-Type': 'application/json'})
res.write(JSON.stringify(wlFile))
res.end()
}
exports.saveWatchList = (req, res) => {
req.on('data', (chunk) => {
// Saving list
fs.writeFileSync(wlPath, chunk, 'utf-8')
console.log('[WatchList] Successfully saved lists.')
res.writeHead(200, {})
res.end()
})
}