Update src/libpoketube/init/pages-api.js
This commit is contained in:
parent
3f4f7c7aa2
commit
b03057c726
@ -99,14 +99,19 @@ function parseUA(ua) {
|
||||
fs.writeFileSync(statsFile, JSON.stringify(data, null, 2))
|
||||
res.json({ ok: true })
|
||||
})
|
||||
|
||||
app.get("/api/stats", (req, res) => {
|
||||
app.get("/api/stats", (req, res) => {
|
||||
if (!telemetryConfig.telemetry)
|
||||
return res.json({ videos: {}, browsers: {}, os: {}, totalUsers: 0 })
|
||||
|
||||
const raw = fs.readFileSync(statsFile, "utf8")
|
||||
const data = JSON.parse(raw)
|
||||
|
||||
// ensure structure exists
|
||||
if (!data.videos) data.videos = {}
|
||||
if (!data.browsers) data.browsers = {}
|
||||
if (!data.os) data.os = {}
|
||||
if (!data.users) data.users = {}
|
||||
|
||||
const sortedVideos = Object.entries(data.videos)
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, 10)
|
||||
@ -121,6 +126,7 @@ function parseUA(ua) {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
app.get("/avatars/:v", async function (req, res) {
|
||||
var url = `https://yt3.ggpht.com/${req.params.v}`;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user