Add hoarding
This commit is contained in:
9
fly.toml
9
fly.toml
@@ -19,7 +19,16 @@ primary_region = 'den'
|
|||||||
[[vm]]
|
[[vm]]
|
||||||
size = 'shared-cpu-2x'
|
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]
|
[env]
|
||||||
|
DATA_ROOT_PATH = "/data"
|
||||||
FILE_DEFAULT_TTL = "600"
|
FILE_DEFAULT_TTL = "600"
|
||||||
S3_ENDPOINT="s3.us-west-002.backblazeb2.com"
|
S3_ENDPOINT="s3.us-west-002.backblazeb2.com"
|
||||||
S3_PORT="443"
|
S3_PORT="443"
|
||||||
|
@@ -29,6 +29,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
|
|||||||
import { JunkDrawerModule } from './junk-drawer/junk-drawer.module';
|
import { JunkDrawerModule } from './junk-drawer/junk-drawer.module';
|
||||||
import { EmailModule } from './email/email.module';
|
import { EmailModule } from './email/email.module';
|
||||||
import { ContactModule } from './contact/contact.module';
|
import { ContactModule } from './contact/contact.module';
|
||||||
|
import { HoardingModule } from './hoarding/hoarding.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -104,6 +105,7 @@ import { ContactModule } from './contact/contact.module';
|
|||||||
JunkDrawerModule,
|
JunkDrawerModule,
|
||||||
EmailModule,
|
EmailModule,
|
||||||
ContactModule,
|
ContactModule,
|
||||||
|
HoardingModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [
|
providers: [
|
||||||
|
@@ -17,7 +17,7 @@ export default () => ({
|
|||||||
channel: process.env.IRC_CHANNEL ?? '#usdev',
|
channel: process.env.IRC_CHANNEL ?? '#usdev',
|
||||||
password: process.env.IRC_PASSWORD ?? '',
|
password: process.env.IRC_PASSWORD ?? '',
|
||||||
nick:
|
nick:
|
||||||
process.env.IRC_NICK ?? process.env.NODE_ENV === 'production'
|
(process.env.IRC_NICK ?? process.env.NODE_ENV === 'production')
|
||||||
? 'us-bot'
|
? 'us-bot'
|
||||||
: 'us-dev',
|
: 'us-dev',
|
||||||
},
|
},
|
||||||
@@ -35,6 +35,9 @@ export default () => ({
|
|||||||
process.env.FILE_DEFAULT_TTL ?? (30 * 24 * 60 * 60).toString(),
|
process.env.FILE_DEFAULT_TTL ?? (30 * 24 * 60 * 60).toString(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
s3: {
|
||||||
|
bucketName: process.env.S3_BUCKET ?? 'api.us.dev',
|
||||||
|
},
|
||||||
focoLive: {
|
focoLive: {
|
||||||
airtable: {
|
airtable: {
|
||||||
apiKey: process.env.FOCO_LIVE_AIRTABLE_APIKEY ?? '',
|
apiKey: process.env.FOCO_LIVE_AIRTABLE_APIKEY ?? '',
|
||||||
|
8
src/hoarding/hoarding.module.ts
Normal file
8
src/hoarding/hoarding.module.ts
Normal 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 {}
|
38
src/hoarding/hoarding.service.ts
Normal file
38
src/hoarding/hoarding.service.ts
Normal 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,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user