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

Compare commits

..

No commits in common. "8815e4f10b740dcdbad4008c7ec7dcc88bcb2f03" and "be33a66e8c113bb5869cceec1ed6777f0d40ceb8" have entirely different histories.

3 changed files with 4 additions and 24 deletions

View file

@ -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 = ? AND missing = 0`).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 = ?`).get(user.token)
// get watched videos // get watched videos
const watchedVideos = user.getWatchedVideos() const watchedVideos = user.getWatchedVideos()
// get videos // get videos

View file

@ -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, Channels.refreshed ASC" "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"
).pluck().all(afterTime) ).pluck().all(afterTime)
this.addLast(channels) this.addLast(channels)
this.lastLoadTime = Date.now() this.lastLoadTime = Date.now()

View file

@ -2,32 +2,12 @@
// @ts-ignore // @ts-ignore
const fetch = require("node-fetch") const fetch = require("node-fetch")
async function request(url, options = {}) { 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"
} }
const res = await fetch(url, options) return 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