mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 17:46:39 -04:00
lots of random cleanup & organization
This commit is contained in:
@ -118,7 +118,7 @@ const getSiteStats = async (client: Client): Promise<OverallStats> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
||||
p.url = match.link;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
p.date = new Date(match.pubDate).toISOString();
|
||||
p.date = new Date(match.pubDate);
|
||||
}
|
||||
|
||||
// add these hits to running tally
|
||||
|
@ -3,7 +3,7 @@ import { VercelRequest, VercelResponse } from "@vercel/node";
|
||||
import { graphql, GraphQlQueryResponseData } from "@octokit/graphql";
|
||||
import { encode } from "html-entities";
|
||||
|
||||
import type { Repository } from "./types/projects";
|
||||
import type { Repository, GHRepoSchema } from "./types/projects";
|
||||
|
||||
Sentry.init({
|
||||
dsn: process.env.SENTRY_DSN || "",
|
||||
@ -91,10 +91,17 @@ const fetchRepos = async (sort: string): Promise<Repository[]> => {
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
const repos: Repository[] = user.repositories.edges.map(({ node: repo }: { [key: string]: Repository }) => ({
|
||||
...repo,
|
||||
description: encode(repo.description),
|
||||
}));
|
||||
const repos: Repository[] = user.repositories.edges.map(
|
||||
({ node: repo }: { [key: string]: Readonly<GHRepoSchema> }) => ({
|
||||
name: repo.name,
|
||||
url: repo.url,
|
||||
description: encode(repo.description),
|
||||
updatedAt: new Date(repo.pushedAt),
|
||||
stars: repo.stargazerCount,
|
||||
forks: repo.forkCount,
|
||||
language: repo.primaryLanguage,
|
||||
})
|
||||
);
|
||||
|
||||
return repos;
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ import { VercelRequest, VercelResponse } from "@vercel/node";
|
||||
import fetch from "node-fetch";
|
||||
import * as queryString from "query-string";
|
||||
|
||||
import type { Track, TrackSchema, Activity } from "./types/tracks";
|
||||
import type { Track, SpotifyTrackSchema, SpotifyActivitySchema } from "./types/tracks";
|
||||
|
||||
const { SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REFRESH_TOKEN } = process.env;
|
||||
|
||||
@ -99,7 +99,7 @@ const getNowPlaying = async (): Promise<Track> => {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const active: Activity = await response.json();
|
||||
const active: SpotifyActivitySchema = await response.json();
|
||||
|
||||
if (active.is_playing === true && active.item) {
|
||||
return {
|
||||
@ -107,7 +107,7 @@ const getNowPlaying = async (): Promise<Track> => {
|
||||
artist: active.item.artists.map((_artist) => _artist.name).join(", "),
|
||||
title: active.item.name,
|
||||
album: active.item.album.name,
|
||||
imageUrl: active.item.album.images[0].url,
|
||||
imageUrl: active.item.album.images ? active.item.album.images[0].url : undefined,
|
||||
songUrl: active.item.external_urls.spotify,
|
||||
};
|
||||
} else {
|
||||
@ -131,11 +131,11 @@ const getTopTracks = async (): Promise<Track[]> => {
|
||||
const { items } = await response.json();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
const tracks: Track[] = items.map((track: TrackSchema) => ({
|
||||
const tracks: Track[] = items.map((track: Readonly<SpotifyTrackSchema>) => ({
|
||||
artist: track.artists.map((_artist) => _artist.name).join(", "),
|
||||
title: track.name,
|
||||
album: track.album.name,
|
||||
imageUrl: track.album.images[0].url,
|
||||
imageUrl: track.album.images ? track.album.images[0].url : undefined,
|
||||
songUrl: track.external_urls.spotify,
|
||||
}));
|
||||
|
||||
|
4
api/types/hits.d.ts
vendored
4
api/types/hits.d.ts
vendored
@ -2,8 +2,8 @@ export type PageStats = {
|
||||
slug: string;
|
||||
hits: number;
|
||||
title?: string;
|
||||
url?: string;
|
||||
date?: string;
|
||||
url?: URL;
|
||||
date?: Date;
|
||||
};
|
||||
|
||||
export type OverallStats = {
|
||||
|
16
api/types/projects.d.ts
vendored
16
api/types/projects.d.ts
vendored
@ -1,11 +1,21 @@
|
||||
import type { Language } from "@octokit/graphql-schema";
|
||||
|
||||
export type Repository = {
|
||||
type BaseRepoInfo = {
|
||||
name: string;
|
||||
url: string;
|
||||
url: URL;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export type GHRepoSchema = Required<BaseRepoInfo> & {
|
||||
primaryLanguage?: Language;
|
||||
stargazerCount: number;
|
||||
forkCount: number;
|
||||
pushedAt: string;
|
||||
pushedAt: Date;
|
||||
};
|
||||
|
||||
export type Repository = Required<BaseRepoInfo> & {
|
||||
language?: Language;
|
||||
stars: number;
|
||||
forks: number;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
24
api/types/tracks.d.ts
vendored
24
api/types/tracks.d.ts
vendored
@ -1,30 +1,30 @@
|
||||
export type TrackSchema = {
|
||||
export type SpotifyTrackSchema = {
|
||||
name: string;
|
||||
artists: Array<{
|
||||
name: string;
|
||||
}>;
|
||||
album: {
|
||||
name: string;
|
||||
images: Array<{
|
||||
url: string;
|
||||
images?: Array<{
|
||||
url: URL;
|
||||
}>;
|
||||
};
|
||||
imageUrl?: string;
|
||||
imageUrl?: URL;
|
||||
external_urls: {
|
||||
spotify: string;
|
||||
spotify: URL;
|
||||
};
|
||||
};
|
||||
|
||||
export type SpotifyActivitySchema = {
|
||||
is_playing: boolean;
|
||||
item?: SpotifyTrackSchema;
|
||||
};
|
||||
|
||||
export type Track = {
|
||||
isPlaying: boolean;
|
||||
artist?: string;
|
||||
title?: string;
|
||||
album?: string;
|
||||
imageUrl?: string;
|
||||
songUrl?: string;
|
||||
};
|
||||
|
||||
export type Activity = {
|
||||
is_playing: boolean;
|
||||
item?: TrackSchema;
|
||||
imageUrl?: URL;
|
||||
songUrl?: URL;
|
||||
};
|
||||
|
Reference in New Issue
Block a user