1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-09-20 03:07:28 +00:00
cloudtube/api/video.js

20 lines
652 B
JavaScript
Raw Normal View History

2020-08-30 13:54:59 +00:00
const fetch = require("node-fetch")
const {render} = require("pinski/plugins")
const db = require("./utils/db")
const {getToken} = require("./utils/getuser")
module.exports = [
{
route: "/watch", methods: ["GET"], code: async ({req, url}) => {
const id = url.searchParams.get("v")
const video = await fetch(`http://localhost:3000/api/v1/videos/${id}`).then(res => res.json())
let subscribed = false
const token = getToken(req)
if (token) {
subscribed = !!db.prepare("SELECT * FROM Subscriptions WHERE token = ? AND ucid = ?").get([token, video.authorId])
}
return render(200, "pug/video.pug", {video, subscribed})
}
}
]