实时统计

This commit is contained in:
2024-12-16 10:50:14 +08:00
parent 31cf0d0daa
commit 5d22686cf8

38
main.js
View File

@@ -66,17 +66,6 @@ const 存档 = async (message = '正在存档...') => {
if (正在存档) return
正在存档 = true
console.log(message)
// 将今日浏览数并入总数
const all = { 文章, 作品, 游戏, 截图, 收藏, 综合 }
for (const key in all) {
const { , } = all[key].浏览数
.forEach((value, key) => {
.set(key, (.get(key) || 0) + value)
})
}
// 数据写入日志
await fs.promises.writeFile(`./data/${当前日期}.json`, JSON.stringify({
文章: Object.fromEntries(文章.浏览数.),
截图: Object.fromEntries(截图.浏览数.),
@@ -162,7 +151,11 @@ export function main() {
if (item.request.uri.startsWith('/web/v1/article/get')) {
const [uri, id] = item.request.uri.match(articleRegex) ?? []
if (uri && id) {
文章.浏览数..set(id, 文章.浏览数..has(id) ? 文章.浏览数..get(id) + 1 : 1)
文章.浏览数..set(id, (文章.浏览数..get(id) || 0) + 1)
文章.浏览数..set(id, (文章.浏览数..get(id) || 0) + 1)
文章.浏览数..set(id, (文章.浏览数..get(id) || 0) + 1)
文章.浏览数..set(id, (文章.浏览数..get(id) || 0) + 1)
文章.浏览数..set(id, (文章.浏览数..get(id) || 0) + 1)
}
}
@@ -170,7 +163,11 @@ export function main() {
if (item.request.uri.startsWith('/web/v1/images/detail/v2')) {
const [uri, id] = item.request.uri.match(imagesRegex) ?? []
if (uri && id) {
截图.浏览数..set(id, 截图.浏览数..has(id) ? 截图.浏览数..get(id) + 1 : 1)
截图.浏览数..set(id, (截图.浏览数..get(id) || 0) + 1)
截图.浏览数..set(id, (截图.浏览数..get(id) || 0) + 1)
截图.浏览数..set(id, (截图.浏览数..get(id) || 0) + 1)
截图.浏览数..set(id, (截图.浏览数..get(id) || 0) + 1)
截图.浏览数..set(id, (截图.浏览数..get(id) || 0) + 1)
}
return
}
@@ -179,7 +176,11 @@ export function main() {
if (item.request.uri.startsWith('/web/v1/member/explorer/article/get')) {
const [uri, id] = item.request.uri.match(collectionRegex) ?? []
if (uri && id) {
收藏.浏览数..set(id, 收藏.浏览数..has(id) ? 收藏.浏览数..get(id) + 1 : 1)
收藏.浏览数..set(id, (收藏.浏览数..get(id) || 0) + 1)
收藏.浏览数..set(id, (收藏.浏览数..get(id) || 0) + 1)
收藏.浏览数..set(id, (收藏.浏览数..get(id) || 0) + 1)
收藏.浏览数..set(id, (收藏.浏览数..get(id) || 0) + 1)
收藏.浏览数..set(id, (收藏.浏览数..get(id) || 0) + 1)
}
return
}
@@ -188,7 +189,14 @@ export function main() {
if (item.request.uri.startsWith('/api?query=')) {
const url = decodeURI(item.request.uri)
const regex = /text:"([^"]*)"/g
const match = regex.exec(url)
const match = regex.exec(url) || []
match.map(item => item[1]).forEach(item => {
截图.搜索词..set(item, (截图.搜索词..get(item) || 0) + 1)
截图.搜索词..set(item, (截图.搜索词..get(item) || 0) + 1)
截图.搜索词..set(item, (截图.搜索词..get(item) || 0) + 1)
截图.搜索词..set(item, (截图.搜索词..get(item) || 0) + 1)
截图.搜索词..set(item, (截图.搜索词..get(item) || 0) + 1)
})
console.log(match)
return
}