1
0
Fork 0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2026-05-26 12:32:25 +00:00

Add database and subscribe button

This commit is contained in:
Cadence Ember 2020-08-31 01:54:59 +12:00
parent 2af05e43a9
commit f24e1bb39c
No known key found for this signature in database
GPG key ID: 128B99B1B74A6412
25 changed files with 972 additions and 44 deletions

19
api/video.js Normal file
View file

@ -0,0 +1,19 @@
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})
}
}
]