mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-10-26 01:05:49 -04:00
add page stats typings
This commit is contained in:
@@ -2,21 +2,7 @@ import { prisma } from "../../lib/helpers/prisma";
|
||||
import { getAllNotes } from "../../lib/helpers/parse-notes";
|
||||
import { logServerError } from "../../lib/helpers/sentry";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
type PageStats = {
|
||||
slug: string;
|
||||
hits: number;
|
||||
title?: string;
|
||||
url?: string;
|
||||
date?: string;
|
||||
};
|
||||
|
||||
type SiteStats = {
|
||||
total: {
|
||||
hits: number;
|
||||
};
|
||||
pages: PageStats[];
|
||||
};
|
||||
import type { PageStats, DetailedPageStats, SiteStats } from "../../types";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
try {
|
||||
@@ -56,7 +42,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
};
|
||||
|
||||
const incrementPageHits = async (slug: string): Promise<Partial<PageStats>> => {
|
||||
const incrementPageHits = async (slug: string): Promise<PageStats> => {
|
||||
const { hits } = await prisma.hits.upsert({
|
||||
where: { slug },
|
||||
create: { slug },
|
||||
@@ -85,7 +71,7 @@ const getSiteStats = async (): Promise<SiteStats> => {
|
||||
|
||||
const total = { hits: 0 };
|
||||
|
||||
pages.forEach((page: PageStats) => {
|
||||
pages.forEach((page: DetailedPageStats) => {
|
||||
// match URLs from RSS feed with db to populate some metadata
|
||||
const match = notes.find((note) => `notes/${note.slug}` === page.slug);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import queryString from "query-string";
|
||||
import { logServerError } from "../../lib/helpers/sentry";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type { Track } from "../../types";
|
||||
|
||||
const { SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REFRESH_TOKEN } = process.env;
|
||||
|
||||
@@ -14,14 +15,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 Track = {
|
||||
artist: string;
|
||||
title: string;
|
||||
album: string;
|
||||
url: URL | string;
|
||||
image?: URL | string;
|
||||
};
|
||||
|
||||
type SpotifyTrackSchema = {
|
||||
name: string;
|
||||
artists: Array<{
|
||||
|
||||
Reference in New Issue
Block a user