mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-03-02 10:41:36 +00:00
Update feeds in background
This commit is contained in:
parent
4a3c1e2ac3
commit
643f1e0889
9 changed files with 118 additions and 25 deletions
|
|
@ -20,8 +20,8 @@ module.exports = [
|
|||
})
|
||||
if (subscriptions.length) {
|
||||
hasSubscriptions = true
|
||||
const all = await Promise.all(subscriptions.map(id => fetchChannelLatest(id)))
|
||||
videos = all.flat(1).sort((a, b) => b.published - a.published).slice(0, 60)
|
||||
const template = Array(subscriptions.length).fill("?").join(", ")
|
||||
videos = db.prepare(`SELECT * FROM Videos WHERE authorId IN (${template}) ORDER BY published DESC LIMIT 60`).all(subscriptions)
|
||||
}
|
||||
}
|
||||
return render(200, "pug/subscriptions.pug", {hasSubscriptions, videos, channels})
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const constants = {
|
|||
user_settings: {
|
||||
instance: {
|
||||
type: "string",
|
||||
default: "https://invidious.snopyta.org"
|
||||
default: "https://second.cadence.moe"
|
||||
},
|
||||
save_history: {
|
||||
type: "boolean",
|
||||
|
|
@ -11,7 +11,9 @@ const constants = {
|
|||
},
|
||||
|
||||
caching: {
|
||||
csrf_time: 4*60*60*1000
|
||||
csrf_time: 4*60*60*1000,
|
||||
seen_token_subscriptions_eligible: 40*60*60*1000,
|
||||
subscriptions_refresh_loop_min: 5*60*1000,
|
||||
},
|
||||
|
||||
regex: {
|
||||
|
|
|
|||
|
|
@ -6,16 +6,19 @@ const db = require("./db")
|
|||
function getToken(req, responseHeaders) {
|
||||
if (!req.headers.cookie) req.headers.cookie = ""
|
||||
const cookie = parseCookie(req.headers.cookie)
|
||||
const token = cookie.token
|
||||
if (token) return token
|
||||
if (responseHeaders) { // we should create a token
|
||||
const setCookie = responseHeaders["set-cookie"] || []
|
||||
const token = crypto.randomBytes(18).toString("base64").replace(/\W/g, "_")
|
||||
setCookie.push(`token=${token}; Path=/; Max-Age=2147483648; HttpOnly; SameSite=Lax`)
|
||||
responseHeaders["set-cookie"] = setCookie
|
||||
return token
|
||||
let token = cookie.token
|
||||
if (!token) {
|
||||
if (responseHeaders) { // we should create a token
|
||||
const setCookie = responseHeaders["set-cookie"] || []
|
||||
token = crypto.randomBytes(18).toString("base64").replace(/\W/g, "_")
|
||||
setCookie.push(`token=${token}; Path=/; Max-Age=2147483648; HttpOnly; SameSite=Lax`)
|
||||
responseHeaders["set-cookie"] = setCookie
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
db.prepare("REPLACE INTO SeenTokens (token, seen) VALUES (?, ?)").run([token, Date.now()])
|
||||
return token
|
||||
}
|
||||
|
||||
class User {
|
||||
|
|
|
|||
|
|
@ -13,14 +13,4 @@ async function fetchChannel(ucid, instance) {
|
|||
return channel
|
||||
}
|
||||
|
||||
function fetchChannelLatest(ucid) {
|
||||
return fetch(`http://localhost:3000/api/v1/channels/${ucid}/latest`).then(res => res.json()).then(root => {
|
||||
root.forEach(video => {
|
||||
video.descriptionHtml = video.descriptionHtml.replace(/<a /g, '<a tabindex="-1" ')
|
||||
})
|
||||
return root
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.fetchChannel = fetchChannel
|
||||
module.exports.fetchChannelLatest = fetchChannelLatest
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue