You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
951 B
33 lines
951 B
const jwt = require("jsonwebtoken")
|
|
const express = require("express")
|
|
const router = express.Router()
|
|
|
|
const common = require("./common")
|
|
const config = require("../../config")
|
|
const {storyApi} = require("../../rpdata/api/Story")
|
|
|
|
const listTemplate = require("../../marko/page/story/list.marko")
|
|
|
|
router.get("/", common, async(req, res) => {
|
|
if (!res.locals.user.loggedIn) {
|
|
return res.status(401).end("You are not logged in")
|
|
}
|
|
|
|
try {
|
|
await res.markoAsync(listTemplate, {
|
|
stories: storyApi.list({unlisted: true, author: res.locals.user.name}, {token: generateToken(res.locals.user.name)}),
|
|
selected: {unlisted: true},
|
|
})
|
|
} catch(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
|
|
/**
|
|
* @param {string} user
|
|
*/
|
|
function generateToken(user) {
|
|
return jwt.sign({user, permissions: ["member"], exp: Math.floor((Date.now() / 1000) + 1200)}, config.backend.secret, {header: {kid: config.backend.kid}})
|
|
}
|
|
|
|
module.exports = router
|