mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-17 10:11:31 +10:00
feat(homepage): add new sections to homepage
This commit is contained in:
30
apps/server/src/contributors/contributors.controller.ts
Normal file
30
apps/server/src/contributors/contributors.controller.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
|
||||
import { UtilsService } from "../utils/utils.service";
|
||||
import { ContributorsService } from "./contributors.service";
|
||||
|
||||
@Controller("contributors")
|
||||
export class ContributorsController {
|
||||
constructor(
|
||||
private readonly contributorsService: ContributorsService,
|
||||
private readonly utils: UtilsService,
|
||||
) {}
|
||||
|
||||
@Get("/github")
|
||||
async githubContributors() {
|
||||
return this.utils.getCachedOrSet(
|
||||
`contributors:github`,
|
||||
async () => this.contributorsService.fetchGitHubContributors(),
|
||||
1000 * 60 * 60 * 24, // 24 hours
|
||||
);
|
||||
}
|
||||
|
||||
@Get("/crowdin")
|
||||
async crowdinContributors() {
|
||||
return this.utils.getCachedOrSet(
|
||||
`contributors:crowdin`,
|
||||
async () => this.contributorsService.fetchCrowdinContributors(),
|
||||
1000 * 60 * 60 * 24, // 24 hours
|
||||
);
|
||||
}
|
||||
}
|
||||
12
apps/server/src/contributors/contributors.module.ts
Normal file
12
apps/server/src/contributors/contributors.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { HttpModule } from "@nestjs/axios";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
import { ContributorsController } from "./contributors.controller";
|
||||
import { ContributorsService } from "./contributors.service";
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
controllers: [ContributorsController],
|
||||
providers: [ContributorsService],
|
||||
})
|
||||
export class ContributorsModule {}
|
||||
55
apps/server/src/contributors/contributors.service.ts
Normal file
55
apps/server/src/contributors/contributors.service.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { HttpService } from "@nestjs/axios";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ContributorDto } from "@reactive-resume/dto";
|
||||
|
||||
import { Config } from "../config/schema";
|
||||
|
||||
type GitHubResponse = { id: number; login: string; html_url: string; avatar_url: string }[];
|
||||
type CrowdinContributorsResponse = {
|
||||
data: { data: { id: number; username: string; avatarUrl: string } }[];
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class ContributorsService {
|
||||
constructor(
|
||||
private readonly httpService: HttpService,
|
||||
private readonly configService: ConfigService<Config>,
|
||||
) {}
|
||||
|
||||
async fetchGitHubContributors() {
|
||||
const response = await this.httpService.axiosRef.get(
|
||||
`https://api.github.com/repos/AmruthPillai/Reactive-Resume/contributors`,
|
||||
);
|
||||
const data = response.data as GitHubResponse;
|
||||
|
||||
return data.map((user) => {
|
||||
return {
|
||||
id: user.id,
|
||||
name: user.login,
|
||||
url: user.html_url,
|
||||
avatar: user.avatar_url,
|
||||
} satisfies ContributorDto;
|
||||
});
|
||||
}
|
||||
|
||||
async fetchCrowdinContributors() {
|
||||
const projectId = this.configService.get("CROWDIN_PROJECT_ID");
|
||||
const accessToken = this.configService.get("CROWDIN_ACCESS_TOKEN");
|
||||
|
||||
const response = await this.httpService.axiosRef.get(
|
||||
`https://api.crowdin.com/api/v2/projects/${projectId}/members`,
|
||||
{ headers: { Authorization: `Bearer ${accessToken}` } },
|
||||
);
|
||||
const { data } = response.data as CrowdinContributorsResponse;
|
||||
|
||||
return data.map(({ data }) => {
|
||||
return {
|
||||
id: data.id,
|
||||
name: data.username,
|
||||
url: `https://crowdin.com/profile/${data.username}`,
|
||||
avatar: data.avatarUrl,
|
||||
} satisfies ContributorDto;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user