-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.ts
30 lines (27 loc) · 882 Bytes
/
stats.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as fs from 'fs'
import * as logger from './logger'
var statsJson: any
export function init(config: any) {
statsJson = JSON.parse(fs.readFileSync("data/stats/stats.json").toString())
setInterval(function () {
logger.info("Saving stats data...", "stats")
fs.writeFileSync("data/stats/stats.json", JSON.stringify(statsJson))
logger.info("Stats data saved!", "stats")
}, 15 * 60 * 1000)
logger.debug(JSON.stringify(statsJson), "stats")
}
export function view(type: String, id: String) {
let item = statsJson.find((item: any) => {
return item.type == type && item.id == id
})
if (item != null) {
item.valueView += 1
} else {
statsJson.push({
"type": type,
"id": id,
"valueView": 1
})
}
logger.debug(`${type} ${id} view 增加了 1`, "stats")
}