1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 18:06:38 -04:00

clean up type declarations

This commit is contained in:
2021-06-13 08:24:27 -04:00
parent e692d07031
commit f35bd7aac2
15 changed files with 161 additions and 179 deletions

View File

@ -1,4 +1,4 @@
"use strict";
/// <reference types="./types/hits" />
import { VercelRequest, VercelResponse } from "@vercel/node";
import { Client, query as q } from "faunadb";
@ -7,23 +7,6 @@ import pluralize from "pluralize";
import rssParser from "rss-parser";
const baseUrl = "https://jarv.is/";
type PageStats = {
title?: string;
url?: string;
date?: string;
slug: string;
hits: number;
pretty_hits: string;
pretty_unit: string;
};
type OverallStats = {
total: {
hits: number;
pretty_hits?: string;
pretty_unit?: string;
};
pages: PageStats[];
};
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default async (req: VercelRequest, res: VercelResponse) => {
@ -49,8 +32,6 @@ export default async (req: VercelRequest, res: VercelResponse) => {
// let Vercel edge and browser cache results for 15 mins
res.setHeader("Cache-Control", "public, max-age=900, s-maxage=900, stale-while-revalidate");
res.setHeader("Access-Control-Allow-Methods", "GET");
res.setHeader("Access-Control-Allow-Origin", "*");
} else {
// increment this page's hits
result = await incrementPageHits(slug, client);

View File

@ -1,4 +1,4 @@
"use strict";
/// <reference types="./types/projects" />
import { VercelRequest, VercelResponse } from "@vercel/node";
import { escape } from "html-escaper";
@ -9,21 +9,6 @@ import { gql } from "graphql-tag";
const username = "jakejarvis";
const endpoint = "https://api.github.com/graphql";
type Repository = {
name: string;
url: string;
description: string;
primaryLanguage?: {
color: string;
name: string;
};
stargazerCount: number;
stargazerCount_pretty?: string;
forkCount: number;
forkCount_pretty?: string;
pushedAt: string;
pushedAt_relative?: string;
};
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default async (req: VercelRequest, res: VercelResponse) => {

View File

@ -1,4 +1,4 @@
"use strict";
/// <reference types="./types/tracks" />
// Fetches my Spotify most-played tracks or currently playing track.
// Heavily inspired by @leerob: https://leerob.io/snippets/spotify
@ -17,31 +17,6 @@ const NOW_PLAYING_ENDPOINT = `https://api.spotify.com/v1/me/player/currently-pla
// https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-users-top-artists-and-tracks
const TOP_TRACKS_ENDPOINT = `https://api.spotify.com/v1/me/top/tracks?time_range=long_term&limit=10`;
type TrackSchema = {
name: string;
artists: Array<{
name: string;
}>;
album: {
name: string;
images: Array<{
url: string;
}>;
};
imageUrl?: string;
external_urls: {
spotify: string;
};
};
type Track = {
isPlaying: boolean;
artist?: string;
title?: string;
album?: string;
imageUrl?: string;
songUrl?: string;
};
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default async (req: VercelRequest, res: VercelResponse) => {
try {
@ -106,11 +81,6 @@ const getNowPlaying = async (): Promise<Track> => {
},
});
type Activity = {
is_playing: boolean;
item?: TrackSchema;
};
if (response.status === 204 || response.status > 400) {
return { isPlaying: false };
}

18
api/types/hits.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
type PageStats = {
title?: string;
url?: string;
date?: string;
slug: string;
hits: number;
pretty_hits: string;
pretty_unit: string;
};
type OverallStats = {
total: {
hits: number;
pretty_hits?: string;
pretty_unit?: string;
};
pages: PageStats[];
};

15
api/types/projects.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
type Repository = {
name: string;
url: string;
description: string;
primaryLanguage?: {
color: string;
name: string;
};
stargazerCount: number;
stargazerCount_pretty?: string;
forkCount: number;
forkCount_pretty?: string;
pushedAt: string;
pushedAt_relative?: string;
};

30
api/types/tracks.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
type TrackSchema = {
name: string;
artists: Array<{
name: string;
}>;
album: {
name: string;
images: Array<{
url: string;
}>;
};
imageUrl?: string;
external_urls: {
spotify: string;
};
};
type Track = {
isPlaying: boolean;
artist?: string;
title?: string;
album?: string;
imageUrl?: string;
songUrl?: string;
};
type Activity = {
is_playing: boolean;
item?: TrackSchema;
};