Run count downloads every 24 hours

This commit is contained in:
topjohnwu 2024-07-25 11:59:46 -07:00
parent 4f334f6f73
commit 249f22fd5a
3 changed files with 8 additions and 6 deletions

View File

@ -10,12 +10,10 @@
"scripts": {
"start": "esrun src/index.ts",
"build": "rm -rf dist && tsc",
"prod": "node dist/index.js",
"count": "esrun src/count.ts"
"prod": "node dist/index.js"
},
"author": "topjohnwu",
"devDependencies": {
"@digitak/esrun": "^3.2.26",
"@tsconfig/node22": "^22.0.0",
"@types/node": "^20.14.12",
"@typescript-eslint/eslint-plugin": "^7.17.0",
@ -25,6 +23,7 @@
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"esrun": "^3.2.26",
"prettier": "3.3.3",
"typescript": "^5.5.4"
},

View File

@ -32,7 +32,7 @@ type GhContentType = Unpacked<
GetResponseDataTypeFromEndpointMethod<typeof gh.repos.getContent>
>;
async function countDownloads() {
export default async function countDownloads() {
const results: ResultInfo = {
totalString: '',
total: 0,
@ -201,5 +201,3 @@ async function countDownloads() {
sha: count_json.sha,
});
}
countDownloads();

View File

@ -1,11 +1,16 @@
import { blockAllSpam } from './utils.js';
import server from './webhook.js';
import countDownloads from './count.js';
async function main() {
// Scan and block all spam every 8 hours
await blockAllSpam();
setInterval(blockAllSpam, 8 * 60 * 60 * 1000);
// Count downloads every 24 hours
await countDownloads();
setInterval(countDownloads, 24 * 60 * 60 * 1000);
// Start webhook server
try {
await server.listen({ port: Number(process.env.PORT), host: '0.0.0.0' });