1
0
Fork 0
This repository has been archived on 2023-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
chellaris-galaxy-political-.../app/api/empires/route.ts

30 lines
863 B
TypeScript
Raw Normal View History

2023-05-31 22:10:59 +00:00
import { google } from 'googleapis';
import { NextResponse } from 'next/server';
import { NextApiResponse } from 'next';
2023-06-01 16:56:15 +00:00
import { time } from 'console';
2023-05-31 22:10:59 +00:00
export async function GET() {
const target = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
const jwt = new google.auth.JWT(
process.env.API_EMAIL,
undefined,
(process.env.API_KEY || '').replace(/\\n/g, '\n'),
target
);
const sheets = google.sheets({version: 'v4', auth: jwt});
const response = await sheets.spreadsheets.values.get({
spreadsheetId: process.env.SPREADSHEET_ID,
range: 'Overview',
});
const rows = response.data.values;
if (rows?.length) {
2023-06-01 16:56:15 +00:00
let empireCount: number = rows[0][1];
return NextResponse.json({ empireCount });
2023-05-31 22:10:59 +00:00
}
else {
return NextResponse.json({ status: 500 })
}
}