const router = require('express').Router()
const fs = require('fs')
const _ = require('lodash')
const util = require('../server/util')

router.get('/all', async (req, res) => {
  res.setHeader('Content-Type', 'application/rss+xml')
  res.end(await util.getRSS({ channel: 'all', format: 'rss' }))
})
router.get('/all.atom', async (req, res) => {
  res.setHeader('Content-Type', 'application/atom+xml')
  res.end(await util.getRSS({ channel: 'all', format: 'atom' }))
})
router.get('/all.json', async (req, res) => {
  res.setHeader('Content-Type', 'application/feed+json')
  res.end(await util.getRSS({ channel: 'all', format: 'json' }))
})

router.get('/blog', async (req, res) => {
  res.setHeader('Content-Type', 'application/rss+xml')
  res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'rss' }))
})
router.get('/blog.atom', async (req, res) => {
  res.setHeader('Content-Type', 'application/atom+xml')
  res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'atom' }))
})
router.get('/blog.json', async (req, res) => {
  res.setHeader('Content-Type', 'application/feed+json')
  res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'json' }))
})

router.get('/notes', async (req, res) => {
  res.setHeader('Content-Type', 'application/rss+xml')
  res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'rss' }))
})
router.get('/notes.atom', async (req, res) => {
  res.setHeader('Content-Type', 'application/atom+xml')
  res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'atom' }))
})
router.get('/notes.json', async (req, res) => {
  res.setHeader('Content-Type', 'application/feed+json')
  res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'json' }))
})

module.exports = router
