mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 23:14:31 -06:00
Use unauthorized helper function in each API route, remote unused 'center' constant
This commit is contained in:
@@ -1,22 +1,15 @@
|
|||||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import {env} from '@/env/server.mjs';
|
import { unauthorized } from '@/utils/helpers';
|
||||||
|
|
||||||
type StatusData = { status: ResponseStatus };
|
type StatusData = { status: ResponseStatus };
|
||||||
|
|
||||||
type ResponseStatus =
|
type ResponseStatus = 'unauthorized' | 'success';
|
||||||
| 'unauthorized'
|
|
||||||
| 'success';
|
|
||||||
|
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<StatusData>
|
res: NextApiResponse<StatusData>
|
||||||
) {
|
) {
|
||||||
if (req.query.key != env.API_KEY) {
|
if (unauthorized(req, res)) return;
|
||||||
// auth failed
|
|
||||||
res.status(401).json({ status: 'unauthorized' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.status(200).json({ status: 'success'});
|
res.status(200).json({ status: 'success' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { env } from '@/env/server.mjs';
|
|
||||||
import { fetchConfiguration, setConfiguration } from '@/db';
|
import { fetchConfiguration, setConfiguration } from '@/db';
|
||||||
import { Configuration, ConfigurationSchema } from '@/timing';
|
import { Configuration, ConfigurationSchema } from '@/timing';
|
||||||
|
import { unauthorized } from '@/utils/helpers';
|
||||||
|
|
||||||
type StatusData = { status: ResponseStatus };
|
type StatusData = { status: ResponseStatus };
|
||||||
|
|
||||||
@@ -11,11 +11,7 @@ export default async function handler(
|
|||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<StatusData | Configuration>
|
res: NextApiResponse<StatusData | Configuration>
|
||||||
) {
|
) {
|
||||||
if (req.query.key != env.API_KEY) {
|
if (unauthorized(req, res)) return;
|
||||||
// auth failed
|
|
||||||
res.status(401).json({ status: 'unauthorized' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method == 'GET') {
|
if (req.method == 'GET') {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { getMatchingTime } from '@/timing';
|
import { getMatchingTime } from '@/timing';
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { getDistance } from '@/location';
|
import { getDistance } from '@/location';
|
||||||
import { env } from '@/env/server.mjs';
|
|
||||||
import monitorAsync from '@/monitor';
|
import monitorAsync from '@/monitor';
|
||||||
import { sendNotification } from '@/notify';
|
import { sendNotification } from '@/notify';
|
||||||
import {
|
import {
|
||||||
@@ -32,11 +31,6 @@ type ResponseStatus =
|
|||||||
| 'notified'
|
| 'notified'
|
||||||
| 'error';
|
| 'error';
|
||||||
|
|
||||||
const center = {
|
|
||||||
latitude: env.CENTER_LATITUDE,
|
|
||||||
longitude: env.CENTER_LONGITUDE
|
|
||||||
};
|
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<(ResponseData & StatusData) | StatusData>
|
res: NextApiResponse<(ResponseData & StatusData) | StatusData>
|
||||||
|
|||||||
Reference in New Issue
Block a user