Lint Netlify functions
This commit is contained in:
parent
eb85319f73
commit
d2f3cada52
11 changed files with 83 additions and 90 deletions
|
@ -7,6 +7,7 @@ const handler: Handler = async () => {
|
|||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"Accept": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
|
@ -53,8 +54,7 @@ const handler: Handler = async () => {
|
|||
};
|
||||
}
|
||||
|
||||
const p_json = await anilist.json() as Record<string, any>;
|
||||
const json = p_json.data.MediaList;
|
||||
const json = (await anilist.json() as any).data.MediaList;
|
||||
const anime: AnilistInfo = {
|
||||
title: json.media.title.romaji,
|
||||
episodes: {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {Octokit} from "@octokit/core";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {type GithubInfo} from "../../src/components/Info/Git.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const octokit = new Octokit({auth: process.env.API_GITHUB});
|
||||
const github = await octokit.request("GET /users/TTTaevas/events", {per_page: 100});
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username: "TTTaevas"});
|
||||
|
||||
if (github.status !== 200) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
|
@ -12,9 +14,9 @@ const handler: Handler = async () => {
|
|||
};
|
||||
}
|
||||
|
||||
const public_push = github.data.find((e: {type: string; public: boolean}) => e.type === "PushEvent" && e.public);
|
||||
const private_push = github.data.find((e: {type: string; public: boolean}) => e.type === "PushEvent" && !e.public);
|
||||
if (!public_push || !private_push) {
|
||||
const publicPush = github.data.find((e) => e.type === "PushEvent" && e.public);
|
||||
const privatePush = github.data.find((e) => e.type === "PushEvent" && !e.public);
|
||||
if (!publicPush || !privatePush) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: "",
|
||||
|
@ -23,11 +25,11 @@ const handler: Handler = async () => {
|
|||
|
||||
const info: GithubInfo = {
|
||||
public: {
|
||||
repo: public_push.repo.name,
|
||||
date: public_push.created_at.substring(0, public_push.created_at.indexOf("T")),
|
||||
repo: publicPush.repo.name,
|
||||
date: publicPush.created_at ? publicPush.created_at.substring(0, publicPush.created_at.indexOf("T")) : "",
|
||||
},
|
||||
private: {
|
||||
date: private_push.created_at.substring(0, private_push.created_at.indexOf("T")),
|
||||
date: privatePush.created_at ? privatePush.created_at.substring(0, privatePush.created_at.indexOf("T")) : "",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ const handler: Handler = async () => {
|
|||
headers: {
|
||||
"PRIVATE-TOKEN": process.env.API_GITLAB!,
|
||||
"Content-Type": "application/json",
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"Accept": "application/json",
|
||||
},
|
||||
});
|
||||
|
@ -19,9 +20,17 @@ const handler: Handler = async () => {
|
|||
};
|
||||
}
|
||||
|
||||
const json = await gitlab.json() as Record<string, any>;
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const {created_at} = (await gitlab.json() as Record<string, any>)[0];
|
||||
if (typeof created_at !== "string") {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: "",
|
||||
};
|
||||
}
|
||||
|
||||
const activity: GitlabInfo = {
|
||||
date: json[0].created_at.substring(0, json[0].created_at.indexOf("T")),
|
||||
date: created_at.substring(0, created_at.indexOf("T")),
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -7,8 +7,7 @@ const handler: Handler = async () => {
|
|||
profile: {
|
||||
activity: HacktheboxInfo[];
|
||||
};
|
||||
}>
|
||||
("https://www.hackthebox.com/api/v4/profile/activity/1063999");
|
||||
}>("https://www.hackthebox.com/api/v4/profile/activity/1063999");
|
||||
|
||||
const pwn = hackthebox.profile.activity.find((a: HacktheboxInfo) => a!.object_type === "machine");
|
||||
if (!pwn) {
|
||||
|
|
|
@ -23,8 +23,7 @@ const handler: Handler = async () => {
|
|||
url: string;
|
||||
}>;
|
||||
};
|
||||
}>
|
||||
(`http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=TTTaevas&api_key=${process.env.API_LASTFM}&format=json&limit=1`);
|
||||
}>(`http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=TTTaevas&api_key=${process.env.API_LASTFM}&format=json&limit=1`);
|
||||
|
||||
const image = lastfm.recenttracks.track[0].image.find((i) => i.size == "large");
|
||||
const track: LastfmInfo = {
|
||||
|
|
|
@ -28,16 +28,15 @@ const handler: Handler = async () => {
|
|||
mania: {global: 0, country: 0},
|
||||
};
|
||||
|
||||
for (let i = 0; i < profile.length; i++) {
|
||||
const ruleset = profile[i];
|
||||
for (const ruleset of profile) {
|
||||
if (ruleset.rank_history) {
|
||||
const stats = ruleset.statistics;
|
||||
info[ruleset.rank_history.mode].global = stats.global_rank || 0;
|
||||
info[ruleset.rank_history.mode].country = stats.country_rank || 0;
|
||||
info[ruleset.rank_history.mode].global = stats.global_rank ?? 0;
|
||||
info[ruleset.rank_history.mode].country = stats.country_rank ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
api.revokeToken();
|
||||
void api.revokeToken();
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
|
|
@ -15,10 +15,9 @@ const handler: Handler = async () => {
|
|||
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) => {
|
||||
const detailsToRequest = [new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
names: {
|
||||
|
@ -30,33 +29,30 @@ const handler: Handler = async () => {
|
|||
};
|
||||
};
|
||||
};
|
||||
}>
|
||||
(`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) => {
|
||||
detailsToRequest.push(new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
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) => {
|
||||
detailsToRequest.push(new Promise((resolve) => {
|
||||
resolve(api<{
|
||||
data: {
|
||||
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 [Record<string, any>];
|
||||
const details = await Promise.all(detailsToRequest) as [Record<string, any>];
|
||||
|
||||
const run: SpeedruncomInfo = {
|
||||
place: speedruncom.data[0].place,
|
||||
|
@ -64,7 +60,7 @@ 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 as {name: string}).name),
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -15,27 +15,30 @@ type Subject = {
|
|||
};
|
||||
};
|
||||
|
||||
function addStuffToLearn(ids: number[], data: Array<{available_at: string; subject_ids: number[]}>, subjects: Subject[]): Array<{
|
||||
type StuffToLearn = {
|
||||
available_at: string;
|
||||
type: string;
|
||||
writing: string;
|
||||
meanings: [{
|
||||
meanings: Array<{
|
||||
meaning: string;
|
||||
}];
|
||||
}>;
|
||||
url: string;
|
||||
}> {
|
||||
const arr: any[] = [];
|
||||
};
|
||||
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const summary_data = data.find(lesson => lesson.subject_ids.includes(ids[i]));
|
||||
const subject = subjects.find(subject => subject.id === ids[i]);
|
||||
if (!summary_data || !subject) {
|
||||
console.error("Failed: ", summary_data, subject);
|
||||
function addStuffToLearn(ids: number[], data: Array<{available_at: string; subject_ids: number[]}>, subjects: Subject[]): StuffToLearn[] {
|
||||
const arr: StuffToLearn[] = [];
|
||||
|
||||
for (const id of ids) {
|
||||
const summaryData = data.find(lesson => lesson.subject_ids.includes(id));
|
||||
const subject = subjects.find(subject => subject.id === id);
|
||||
if (!summaryData || !subject) {
|
||||
console.error("Failed: ", summaryData, subject);
|
||||
continue;
|
||||
}
|
||||
|
||||
arr.push({
|
||||
available_at: summary_data.available_at,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
available_at: summaryData.available_at,
|
||||
type: subject.object,
|
||||
writing: subject.data.characters || subject.data.slug || subject.data.meanings[0].meaning,
|
||||
meanings: subject.data.meanings,
|
||||
|
@ -95,42 +98,42 @@ const handler: Handler = async () => {
|
|||
};
|
||||
} = data[2];
|
||||
|
||||
const subject_ids_lessons: number[] = [];
|
||||
const subject_ids_reviews: number[] = [];
|
||||
for (let i = 0; i < summary.data.lessons.length; i++) {
|
||||
for (let e = 0; e < summary.data.lessons[i].subject_ids.length; e++) {
|
||||
subject_ids_lessons.push(summary.data.lessons[i].subject_ids[e]);
|
||||
const subjectIdsLessons: number[] = [];
|
||||
const subjectIdsReviews: number[] = [];
|
||||
for (const lesson of summary.data.lessons) {
|
||||
for (const subjectId of lesson.subject_ids) {
|
||||
subjectIdsLessons.push(subjectId);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < summary.data.reviews.length; i++) {
|
||||
for (let e = 0; e < summary.data.reviews[i].subject_ids.length; e++) {
|
||||
subject_ids_reviews.push(summary.data.reviews[i].subject_ids[e]);
|
||||
for (const review of summary.data.reviews) {
|
||||
for (const subjectId of review.subject_ids) {
|
||||
subjectIdsReviews.push(subjectId);
|
||||
}
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
// next_reviews checks what reviews will be available in the next 23 hours
|
||||
// summary.data.next_reviews_at checks beyond that, but will be the current time if a review is already available
|
||||
const next_reviews = summary.data.reviews
|
||||
const nextReviews = summary.data.reviews
|
||||
.map((r: {subject_ids: number[]; available_at: Date | string}) => {
|
||||
r.available_at = new Date(r.available_at); return r;
|
||||
})
|
||||
.filter((r) => r.available_at > now && r.subject_ids.length) as Array<{subject_ids: number[]; available_at: Date}>;
|
||||
const more_things_to_review_at = next_reviews[0] ? next_reviews[0].available_at.toISOString() : summary.data.next_reviews_at ? summary.data.next_reviews_at : null;
|
||||
const moreThingsToReviewAt = nextReviews[0] ? nextReviews[0].available_at.toISOString() : summary.data.next_reviews_at ? summary.data.next_reviews_at : undefined;
|
||||
|
||||
const subject_ids_all = subject_ids_lessons.concat(subject_ids_reviews);
|
||||
const subjects = await api<{data: Subject[]}>(`https://api.wanikani.com/v2/subjects?ids=${subject_ids_all.toString()}`, process.env.API_WANIKANI);
|
||||
const subjectIdsAll = subjectIdsLessons.concat(subjectIdsReviews);
|
||||
const subjects = await api<{data: Subject[]}>(`https://api.wanikani.com/v2/subjects?ids=${subjectIdsAll.toString()}`, process.env.API_WANIKANI);
|
||||
|
||||
const lessons = addStuffToLearn(subject_ids_lessons, summary.data.lessons, subjects.data);
|
||||
const reviews = addStuffToLearn(subject_ids_reviews, summary.data.reviews, subjects.data);
|
||||
const lessons = addStuffToLearn(subjectIdsLessons, summary.data.lessons, subjects.data);
|
||||
const reviews = addStuffToLearn(subjectIdsReviews, summary.data.reviews, subjects.data);
|
||||
|
||||
const info: WanikaniInfo = {
|
||||
progression,
|
||||
resets: resets.data,
|
||||
lessons,
|
||||
reviews,
|
||||
more_things_to_review_at,
|
||||
moreThingsToReviewAt,
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue