-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): 지원자 수 google spreadsheet 연동 후 cron 적용하여 1시간마다 데이터 가져오기 구현
- Loading branch information
1 parent
2164841
commit c14a8e9
Showing
18 changed files
with
198 additions
and
10 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.78 KB
.yarn/cache/buffer-equal-constant-time-npm-1.0.1-41826f3419-80bb945f5d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
namespace NodeJS { | ||
interface ProcessEnv extends NodeJS.ProcessEnv { | ||
AUTH_SECRET: string; | ||
AUTH_GOOGLE_ID: string; | ||
AUTH_GOOGLE_SECRET: string; | ||
ALLOWED_EMAIL_ADDRESSES: string; | ||
DND_ACADEMY_V2_BLOB_READ_WRITE_TOKEN: string; | ||
AUTH_SECRET: string; | ||
GOOGLE_CLIENT_EMAIL: string; | ||
GOOGLE_PRIVATE_KEY: string; | ||
CRON_SECRET: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/admin/src/app/api/cron/current-applicant-count/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { put } from '@vercel/blob'; | ||
import { JWT } from 'google-auth-library'; | ||
import { GoogleSpreadsheet } from 'google-spreadsheet'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export const runtime = 'nodejs'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const authHeader = request.headers.get('authorization'); | ||
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) { | ||
return new Response('Unauthorized', { | ||
status: 401, | ||
}); | ||
} | ||
|
||
const serviceAccountAuth = new JWT({ | ||
email: process.env.GOOGLE_CLIENT_EMAIL, | ||
key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'), | ||
scopes: ['https://www.googleapis.com/auth/spreadsheets'], | ||
}); | ||
|
||
const developerApplicantDoc = new GoogleSpreadsheet('1LLxVCTkqtTZoMftrEkYOlwVdyEwoEKwCg7WvXwfW2Rk', serviceAccountAuth); | ||
const designerApplicantDoc = new GoogleSpreadsheet('1BToiD3gjzT-SKWeKnQMRuFvGXmYv44oEigSIJy_w1Jc', serviceAccountAuth); | ||
|
||
await developerApplicantDoc.loadInfo(); | ||
await designerApplicantDoc.loadInfo(); | ||
|
||
const developerApplicantRows = await developerApplicantDoc.sheetsByIndex[0].getRows(); | ||
const designerApplicantRows = await designerApplicantDoc.sheetsByIndex[0].getRows(); | ||
|
||
const currentApplicantCountForm = { | ||
developer: developerApplicantRows.length, | ||
designer: designerApplicantRows.length, | ||
}; | ||
|
||
const jsonString = JSON.stringify(currentApplicantCountForm); | ||
|
||
const requestBlob = new Blob([jsonString], { type: 'application/json' }); | ||
|
||
await put('current_applicant_count.json', requestBlob, { | ||
access: 'public', | ||
token: process.env.DND_ACADEMY_V2_BLOB_READ_WRITE_TOKEN, | ||
addRandomSuffix: false, | ||
cacheControlMaxAge: 3600, | ||
}); | ||
|
||
return NextResponse.json(currentApplicantCountForm, { | ||
status: 200, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"crons": [{ | ||
"path": "/api/cron/current-applicant-count", | ||
"schedule": "0 * * * *" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters