实时统计
This commit is contained in:
38
main.js
38
main.js
@@ -66,17 +66,6 @@ const 存档 = async (message = '正在存档...') => {
|
|||||||
if (正在存档) return
|
if (正在存档) return
|
||||||
正在存档 = true
|
正在存档 = true
|
||||||
console.log(message)
|
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({
|
await fs.promises.writeFile(`./data/${当前日期}.json`, JSON.stringify({
|
||||||
文章: Object.fromEntries(文章.浏览数.日),
|
文章: Object.fromEntries(文章.浏览数.日),
|
||||||
截图: Object.fromEntries(截图.浏览数.日),
|
截图: Object.fromEntries(截图.浏览数.日),
|
||||||
@@ -162,7 +151,11 @@ export function main() {
|
|||||||
if (item.request.uri.startsWith('/web/v1/article/get')) {
|
if (item.request.uri.startsWith('/web/v1/article/get')) {
|
||||||
const [uri, id] = item.request.uri.match(articleRegex) ?? []
|
const [uri, id] = item.request.uri.match(articleRegex) ?? []
|
||||||
if (uri && id) {
|
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')) {
|
if (item.request.uri.startsWith('/web/v1/images/detail/v2')) {
|
||||||
const [uri, id] = item.request.uri.match(imagesRegex) ?? []
|
const [uri, id] = item.request.uri.match(imagesRegex) ?? []
|
||||||
if (uri && id) {
|
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
|
return
|
||||||
}
|
}
|
||||||
@@ -179,7 +176,11 @@ export function main() {
|
|||||||
if (item.request.uri.startsWith('/web/v1/member/explorer/article/get')) {
|
if (item.request.uri.startsWith('/web/v1/member/explorer/article/get')) {
|
||||||
const [uri, id] = item.request.uri.match(collectionRegex) ?? []
|
const [uri, id] = item.request.uri.match(collectionRegex) ?? []
|
||||||
if (uri && id) {
|
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
|
return
|
||||||
}
|
}
|
||||||
@@ -188,7 +189,14 @@ export function main() {
|
|||||||
if (item.request.uri.startsWith('/api?query=')) {
|
if (item.request.uri.startsWith('/api?query=')) {
|
||||||
const url = decodeURI(item.request.uri)
|
const url = decodeURI(item.request.uri)
|
||||||
const regex = /text:"([^"]*)"/g
|
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)
|
console.log(match)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user