Also apply basic linting to Netlify functions
This commit is contained in:
parent
3d38ba1768
commit
eb85319f73
11 changed files with 272 additions and 258 deletions
|
@ -1,62 +1,62 @@
|
|||
import { Handler } from '@netlify/functions'
|
||||
import { api } from "./shared/api"
|
||||
import { SpeedruncomInfo } from '../../src/components/infos/Speedruncom'
|
||||
import {type Handler} from "@netlify/functions";
|
||||
import {api} from "./shared/api.js";
|
||||
import {type SpeedruncomInfo} from "../../src/components/Info/Speedruncom.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// using the API's embedding would be stupid here, as that'd create lag due to irrelevant runs
|
||||
const speedruncom = await api<{
|
||||
data: {
|
||||
place: number,
|
||||
data: Array<{
|
||||
place: number;
|
||||
run: {
|
||||
weblink: string
|
||||
game: string
|
||||
level: string | null
|
||||
category: string | null
|
||||
date: string
|
||||
}
|
||||
}[]
|
||||
weblink: string;
|
||||
game: string;
|
||||
level: string | undefined;
|
||||
category: string | undefined;
|
||||
date: string;
|
||||
};
|
||||
}>;
|
||||
}>
|
||||
(`https://www.speedrun.com/api/v1/users/j03v45mj/personal-bests`)
|
||||
("https://www.speedrun.com/api/v1/users/j03v45mj/personal-bests");
|
||||
|
||||
const details_to_request = [new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
names: {
|
||||
international: string
|
||||
}
|
||||
international: string;
|
||||
};
|
||||
assets: {
|
||||
"cover-tiny": {
|
||||
uri: string
|
||||
}
|
||||
}
|
||||
}
|
||||
uri: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
}>
|
||||
(`https://www.speedrun.com/api/v1/games/${speedruncom.data[0].run.game}`))
|
||||
})]
|
||||
(`https://www.speedrun.com/api/v1/games/${speedruncom.data[0].run.game}`));
|
||||
})];
|
||||
|
||||
if (speedruncom.data[0].run.level) {
|
||||
details_to_request.push(new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
name: string
|
||||
}
|
||||
name: string;
|
||||
};
|
||||
}>
|
||||
(`https://www.speedrun.com/api/v1/levels/${speedruncom.data[0].run.level}`))
|
||||
}))
|
||||
(`https://www.speedrun.com/api/v1/levels/${speedruncom.data[0].run.level}`));
|
||||
}));
|
||||
}
|
||||
|
||||
if (speedruncom.data[0].run.category) {
|
||||
details_to_request.push(new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
name: string
|
||||
}
|
||||
name: string;
|
||||
};
|
||||
}>
|
||||
(`https://www.speedrun.com/api/v1/categories/${speedruncom.data[0].run.category}`))
|
||||
}))
|
||||
(`https://www.speedrun.com/api/v1/categories/${speedruncom.data[0].run.category}`));
|
||||
}));
|
||||
}
|
||||
|
||||
const details = await Promise.all(details_to_request) as [{[key: string]: any}]
|
||||
const details = await Promise.all(details_to_request) as [Record<string, any>];
|
||||
|
||||
const run: SpeedruncomInfo = {
|
||||
place: speedruncom.data[0].place,
|
||||
|
@ -64,13 +64,13 @@ const handler: Handler = async () => {
|
|||
date: speedruncom.data[0].run.date,
|
||||
thumbnail: details[0].data.assets["cover-tiny"].uri,
|
||||
game: details[0].data.names.international,
|
||||
details: details.slice(1).map((d) => d.data.name) || []
|
||||
}
|
||||
details: details.slice(1).map((d) => d.data.name) || [],
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(run)
|
||||
}
|
||||
}
|
||||
body: JSON.stringify(run),
|
||||
};
|
||||
};
|
||||
|
||||
export { handler }
|
||||
export {handler};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue