API reordering
This commit is contained in:
parent
6e07d6c564
commit
a1e429f94b
2 changed files with 32 additions and 0 deletions
30
app/api/empires/route.ts
Normal file
30
app/api/empires/route.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { google } from 'googleapis';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { NextApiResponse } from 'next';
|
||||||
|
import { time } from 'console';
|
||||||
|
|
||||||
|
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 empireCount: number = rows[0][1];
|
||||||
|
|
||||||
|
return NextResponse.json({ empireCount });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NextResponse.json({ status: 500 })
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import { google } from 'googleapis';
|
import { google } from 'googleapis';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
|
import { time } from 'console';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const target = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
|
const target = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
|
||||||
|
@ -26,6 +27,7 @@ export async function GET() {
|
||||||
tempArray.push(rows[i][2]);
|
tempArray.push(rows[i][2]);
|
||||||
sheetData.push(tempArray);
|
sheetData.push(tempArray);
|
||||||
}
|
}
|
||||||
|
console.log("New Google Data loaded " + Intl.DateTimeFormat('en-UK', {hour: 'numeric', minute: 'numeric', hour12: false}).format(Date.now()));
|
||||||
return NextResponse.json({ sheetData });
|
return NextResponse.json({ sheetData });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
Reference in a new issue