mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-03-02 10:41:36 +00:00
Display how recently channels were refreshed
This commit is contained in:
parent
2e69dfc4b7
commit
83dec0c7ab
4 changed files with 31 additions and 10 deletions
|
|
@ -2,7 +2,7 @@ const {render} = require("pinski/plugins")
|
|||
const db = require("../utils/db")
|
||||
const {fetchChannelLatest} = require("../utils/youtube")
|
||||
const {getUser} = require("../utils/getuser")
|
||||
const converters = require("../utils/converters")
|
||||
const {timeToPastText} = require("../utils/converters")
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
|
|
@ -11,25 +11,26 @@ module.exports = [
|
|||
let hasSubscriptions = false
|
||||
let videos = []
|
||||
let channels = []
|
||||
let refreshed = null
|
||||
if (user.token) {
|
||||
// get channels
|
||||
const subscriptions = user.getSubscriptions()
|
||||
const channelPrepared = db.prepare("SELECT * FROM Channels WHERE ucid = ?")
|
||||
channels = subscriptions.map(id => channelPrepared.get(id)).sort((a, b) => {
|
||||
if (a.name < b.name) return -1
|
||||
else if (b.name > a.name) return 1
|
||||
else return 0
|
||||
})
|
||||
const template = Array(subscriptions.length).fill("?").join(", ")
|
||||
channels = db.prepare(`SELECT * FROM Channels WHERE ucid IN (${template}) ORDER BY name`).all(subscriptions)
|
||||
// get refreshed status
|
||||
refreshed = db.prepare(`SELECT min(refreshed) as min, max(refreshed) as max, count(refreshed) as count FROM Channels WHERE ucid IN (${template})`).get(subscriptions)
|
||||
// get videos
|
||||
if (subscriptions.length) {
|
||||
hasSubscriptions = true
|
||||
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)
|
||||
.map(video => {
|
||||
video.publishedText = converters.timeToPastText(video.published * 1000)
|
||||
video.publishedText = timeToPastText(video.published * 1000)
|
||||
return video
|
||||
})
|
||||
}
|
||||
}
|
||||
return render(200, "pug/subscriptions.pug", {hasSubscriptions, videos, channels})
|
||||
return render(200, "pug/subscriptions.pug", {hasSubscriptions, videos, channels, refreshed, timeToPastText})
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue