Hoard lichess stats

This commit is contained in:
2024-12-05 16:39:05 -07:00
parent 3ada3433cc
commit 368f2b100f
2 changed files with 39 additions and 1 deletions

View File

@@ -50,4 +50,9 @@ export default () => ({
mailgun: { mailgun: {
hooliKey: process.env.MAILGUN_SEND_KEY_HOOLI ?? '', hooliKey: process.env.MAILGUN_SEND_KEY_HOOLI ?? '',
}, },
thirdPartyServices: {
lichess: {
token: process.env.SVC_LICHESS_TOKEN ?? '',
},
},
}); });

View File

@@ -7,7 +7,10 @@ import { MinioService } from 'src/minio/minio.service';
@Injectable() @Injectable()
export class HoardingService { export class HoardingService {
private readonly logger: Logger = new Logger(HoardingService.name); private readonly logger: Logger = new Logger(HoardingService.name);
constructor(public readonly minioService: MinioService) { constructor(
public readonly minioService: MinioService,
private readonly configService: ConfigService,
) {
this.hoardChessStats(); this.hoardChessStats();
} }
@@ -23,6 +26,36 @@ export class HoardingService {
} catch (e) { } catch (e) {
this.logger.error(e); this.logger.error(e);
} }
try {
await this.hoardLichessStats('sentientcrouton');
} catch (e) {
this.logger.error(e);
}
}
async hoardLichessStats(user: string) {
if (!this.configService.get('thirdPartyServices.lichess.token')) {
this.logger.error('No lichess token found');
return;
}
const token = this.configService.get('thirdPartyServices.lichess.token');
this.logger.log(`Hoarding lichess stats for ${user}`);
const lichessState = (id: string) => `https://lichess.org/api/user/${id}`;
const stats = await axios.get(lichessState(user), {
headers: {
Authorization: `Bearer ${token}`,
},
});
await this.minioService.uploadBuffer(
this.minioService.defaultBucketName,
`hoarding/lichess-stats/${user}/${new Date().getTime()}-${user}.json`,
Buffer.from(
JSON.stringify({
time: new Date().getTime(),
data: stats.data,
}),
),
);
} }
async hoardUserChessStats(user: string) { async hoardUserChessStats(user: string) {