Add hoarding

This commit is contained in:
2024-11-01 16:34:32 -06:00
parent d9dfda60d8
commit d6390d365c
5 changed files with 61 additions and 1 deletions

View File

@@ -19,7 +19,16 @@ primary_region = 'den'
[[vm]]
size = 'shared-cpu-2x'
# [mounts]
# source = "usapi_data"
# destination = "/data"
# initial_size = "20gb"
# auto_extend_size_increment = "10gb"
# auto_extend_size_threshold = 80
# auto_extend_size_limit = "200gb"
[env]
DATA_ROOT_PATH = "/data"
FILE_DEFAULT_TTL = "600"
S3_ENDPOINT="s3.us-west-002.backblazeb2.com"
S3_PORT="443"

View File

@@ -29,6 +29,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
import { JunkDrawerModule } from './junk-drawer/junk-drawer.module';
import { EmailModule } from './email/email.module';
import { ContactModule } from './contact/contact.module';
import { HoardingModule } from './hoarding/hoarding.module';
@Module({
imports: [
@@ -104,6 +105,7 @@ import { ContactModule } from './contact/contact.module';
JunkDrawerModule,
EmailModule,
ContactModule,
HoardingModule,
],
controllers: [AppController],
providers: [

View File

@@ -17,7 +17,7 @@ export default () => ({
channel: process.env.IRC_CHANNEL ?? '#usdev',
password: process.env.IRC_PASSWORD ?? '',
nick:
process.env.IRC_NICK ?? process.env.NODE_ENV === 'production'
(process.env.IRC_NICK ?? process.env.NODE_ENV === 'production')
? 'us-bot'
: 'us-dev',
},
@@ -35,6 +35,9 @@ export default () => ({
process.env.FILE_DEFAULT_TTL ?? (30 * 24 * 60 * 60).toString(),
),
},
s3: {
bucketName: process.env.S3_BUCKET ?? 'api.us.dev',
},
focoLive: {
airtable: {
apiKey: process.env.FOCO_LIVE_AIRTABLE_APIKEY ?? '',

View File

@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { HoardingService } from './hoarding.service';
import { MinioService } from 'src/minio/minio.service';
@Module({
providers: [HoardingService, MinioService],
})
export class HoardingModule {}

View File

@@ -0,0 +1,38 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Cron } from '@nestjs/schedule';
import axios from 'axios';
import { MinioService } from 'src/minio/minio.service';
@Injectable()
export class HoardingService {
private readonly logger: Logger = new Logger(HoardingService.name);
constructor(public readonly minioService: MinioService) {
this.hoardChessStats();
}
@Cron('0 0 1 * * *')
async hoardChessStats() {
await this.hoardUserChessStats('letmutchessplayer');
await this.hoardUserChessStats('archyotype');
}
async hoardUserChessStats(user: string) {
this.logger.log(`Hoarding chess.com stats for ${user}`);
const chessState = (id: string) =>
`https://api.chess.com/pub/player/${id}/stats`;
const stats = await axios.get(chessState(user));
const time = new Date().getTime();
await this.minioService.uploadBuffer(
this.minioService.defaultBucketName,
`hoarding/chess.com-stats/${user}/${time}-${user}.json`,
Buffer.from(
JSON.stringify({
time,
data: stats.data,
}),
),
);
}
}