Also apply basic linting to Netlify functions

This commit is contained in:
Taevas 2024-04-27 18:45:18 +02:00
parent 3d38ba1768
commit eb85319f73
11 changed files with 272 additions and 258 deletions

View file

@ -1,45 +1,45 @@
import { Handler } from '@netlify/functions'
import { api } from "./shared/api"
import { LastfmInfo } from '../../src/components/infos/Lastfm'
import {type Handler} from "@netlify/functions";
import {api} from "./shared/api.js";
import {type LastfmInfo} from "../../src/components/Info/Lastfm.js";
const handler: Handler = async () => {
const lastfm = await api<{
recenttracks: {
track: {
track: Array<{
artist: {
"#text": string
},
image: {
size: string,
"#text": string
}[]
"#text": string;
};
image: Array<{
size: string;
"#text": string;
}>;
album: {
"#text": string
},
name: string,
"#text": string;
};
name: string;
"@attr"?: {
nowplaying?: string
}
url: string
}[]
}
nowplaying?: string;
};
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 image = lastfm.recenttracks.track[0].image.find((i) => i.size == "large");
const track: LastfmInfo = {
artist: lastfm.recenttracks.track[0].artist['#text'],
artist: lastfm.recenttracks.track[0].artist["#text"],
name: lastfm.recenttracks.track[0].name,
album: lastfm.recenttracks.track[0].album['#text'],
image: image ? image['#text'] : "",
listening: Boolean(lastfm.recenttracks.track[0]['@attr']?.nowplaying),
url: lastfm.recenttracks.track[0].url
}
album: lastfm.recenttracks.track[0].album["#text"],
image: image ? image["#text"] : "",
listening: Boolean(lastfm.recenttracks.track[0]["@attr"]?.nowplaying),
url: lastfm.recenttracks.track[0].url,
};
return {
statusCode: 200,
body: JSON.stringify(track)
}
}
body: JSON.stringify(track),
};
};
export { handler }
export {handler};