34 lines
1 KiB
TypeScript
34 lines
1 KiB
TypeScript
import { google } from 'googleapis';
|
|
import { NextResponse } from 'next/server';
|
|
import { NextApiResponse } from 'next';
|
|
|
|
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) {
|
|
let sheetData: Array<Array<number>> = new Array<Array<number>>;
|
|
for (let i = 3; i < 17; i++) {
|
|
let tempArray = new Array<number>;
|
|
tempArray.push(rows[i][1]);
|
|
tempArray.push(rows[i][2]);
|
|
sheetData.push(tempArray);
|
|
}
|
|
return NextResponse.json({ sheetData });
|
|
}
|
|
else {
|
|
return NextResponse.json({ status: 500 })
|
|
}
|
|
} |