mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-21 12:11:25 +10:00
🚀 release v3.0.0
This commit is contained in:
17
server/src/fonts/fonts.controller.ts
Normal file
17
server/src/fonts/fonts.controller.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { CacheInterceptor, Controller, Get, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
|
||||
import { JwtAuthGuard } from '@/auth/guards/jwt.guard';
|
||||
|
||||
import { FontsService } from './fonts.service';
|
||||
|
||||
@Controller('fonts')
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
export class FontsController {
|
||||
constructor(private fontsService: FontsService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
getAll() {
|
||||
return this.fontsService.getAll();
|
||||
}
|
||||
}
|
||||
16
server/src/fonts/fonts.module.ts
Normal file
16
server/src/fonts/fonts.module.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
import { FontsController } from './fonts.controller';
|
||||
import { FontsService } from './fonts.service';
|
||||
|
||||
// Every week
|
||||
const cacheTTL = 60 * 60 * 24 * 7;
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, HttpModule, CacheModule.register({ ttl: cacheTTL })],
|
||||
controllers: [FontsController],
|
||||
providers: [FontsService],
|
||||
})
|
||||
export class FontsModule {}
|
||||
21
server/src/fonts/fonts.service.ts
Normal file
21
server/src/fonts/fonts.service.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Font } from '@reactive-resume/schema';
|
||||
import { get } from 'lodash';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class FontsService {
|
||||
constructor(private configService: ConfigService, private httpService: HttpService) {}
|
||||
|
||||
async getAll(): Promise<Font[]> {
|
||||
const apiKey = this.configService.get<string>('google.apiKey');
|
||||
const url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' + apiKey;
|
||||
|
||||
const response = await firstValueFrom(this.httpService.get(url));
|
||||
const data = get(response.data, 'items', []);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user