mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-05-26 04:22:25 +00:00
Compare commits
2 commits
be33a66e8c
...
8815e4f10b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8815e4f10b | ||
|
|
a488052573 |
3 changed files with 24 additions and 4 deletions
|
|
@ -20,7 +20,7 @@ module.exports = [
|
||||||
channels = db.prepare(`SELECT Channels.* FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ? ORDER BY name`).all(user.token)
|
channels = db.prepare(`SELECT Channels.* FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ? ORDER BY name`).all(user.token)
|
||||||
missingChannelCount = channels.reduce((a, c) => a + c.missing, 0)
|
missingChannelCount = channels.reduce((a, c) => a + c.missing, 0)
|
||||||
// get refreshed status
|
// get refreshed status
|
||||||
refreshed = db.prepare(`SELECT min(refreshed) as min, max(refreshed) as max, count(refreshed) as count FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ?`).get(user.token)
|
refreshed = db.prepare(`SELECT min(refreshed) as min, max(refreshed) as max, count(refreshed) as count FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ? AND missing = 0`).get(user.token)
|
||||||
// get watched videos
|
// get watched videos
|
||||||
const watchedVideos = user.getWatchedVideos()
|
const watchedVideos = user.getWatchedVideos()
|
||||||
// get videos
|
// get videos
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class RefreshQueue {
|
||||||
// get the next set of scheduled channels to refresh
|
// get the next set of scheduled channels to refresh
|
||||||
const afterTime = Date.now() - constants.caching.seen_token_subscriptions_eligible
|
const afterTime = Date.now() - constants.caching.seen_token_subscriptions_eligible
|
||||||
const channels = db.prepare(
|
const channels = db.prepare(
|
||||||
"SELECT DISTINCT Subscriptions.ucid FROM SeenTokens INNER JOIN Subscriptions ON SeenTokens.token = Subscriptions.token INNER JOIN Channels ON Channels.ucid = Subscriptions.ucid WHERE Channels.missing = 0 AND SeenTokens.seen > ? ORDER BY SeenTokens.seen DESC"
|
"SELECT DISTINCT Subscriptions.ucid FROM SeenTokens INNER JOIN Subscriptions ON SeenTokens.token = Subscriptions.token INNER JOIN Channels ON Channels.ucid = Subscriptions.ucid WHERE Channels.missing = 0 AND SeenTokens.seen > ? ORDER BY SeenTokens.seen DESC, Channels.refreshed ASC"
|
||||||
).pluck().all(afterTime)
|
).pluck().all(afterTime)
|
||||||
this.addLast(channels)
|
this.addLast(channels)
|
||||||
this.lastLoadTime = Date.now()
|
this.lastLoadTime = Date.now()
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,32 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
function request(url, options = {}) {
|
async function request(url, options = {}) {
|
||||||
if (!options.headers) options.headers = {}
|
if (!options.headers) options.headers = {}
|
||||||
options.headers = {
|
options.headers = {
|
||||||
"user-agent": "CloudTubeBackend/1.0"
|
"user-agent": "CloudTubeBackend/1.0"
|
||||||
}
|
}
|
||||||
return fetch(url, options)
|
const res = await fetch(url, options)
|
||||||
|
|
||||||
|
if (res.status >= 400) {
|
||||||
|
if (res.status == 500) {
|
||||||
|
let body = await res.text();
|
||||||
|
|
||||||
|
const traceback_start = '<pre id="traceback">';
|
||||||
|
const traceback_end = '</pre>';
|
||||||
|
|
||||||
|
const si = body.indexOf(traceback_start)
|
||||||
|
if (si >= 0) body = body.slice(si + traceback_start.length);
|
||||||
|
|
||||||
|
const ei = body.indexOf(traceback_end)
|
||||||
|
if (ei >= 0) body = body.slice(0, ei);
|
||||||
|
|
||||||
|
throw new Error(`Unexpected error in backend:\n\n${body}`);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unexpected response from backend: ${res.status} ${res.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.request = request
|
module.exports.request = request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue