1
0
Fork 0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2026-03-02 02:31:35 +00:00

Support t parameter using media fragments

This commit is contained in:
Cadence Ember 2021-01-14 00:55:31 +13:00
parent 36f33b9f7e
commit bb4816c4b3
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
3 changed files with 56 additions and 4 deletions

View file

@ -122,20 +122,23 @@ module.exports = [
route: "/watch", methods: ["GET", "POST"], upload: true, code: async ({req, url, body}) => {
const user = getUser(req)
const settings = user.getSettingsOrDefaults()
const id = url.searchParams.get("v")
if (req.method === "GET") {
const id = url.searchParams.get("v")
const t = url.searchParams.get("t")
let mediaFragment = converters.tToMediaFragment(t)
if (!settings.local) {
const instanceOrigin = settings.instance
const outURL = `${instanceOrigin}/api/v1/videos/${id}`
const videoPromise = request(outURL).then(res => res.json())
return renderVideo(videoPromise, {user, id, instanceOrigin})
return renderVideo(videoPromise, {user, id, instanceOrigin}, {mediaFragment})
} else {
return render(200, "pug/local-video.pug", {id})
}
} else { // req.method === "POST"
const video = JSON.parse(new URLSearchParams(body.toString()).get("video"))
const videoPromise = Promise.resolve(video)
return renderVideo(videoPromise, {user})
const instanceOrigin = "http://localhost:3000"
return renderVideo(videoPromise, {user, id, instanceOrigin})
}
}
}