updated hardcover and steam apis to actually work after testing

This commit is contained in:
dylan 2025-12-28 18:40:03 +00:00
parent 7dfff74ea0
commit 48a5aab1c2
2 changed files with 37 additions and 14 deletions

View file

@ -116,9 +116,10 @@ export const services = [
{ {
id: 'hardcover', id: 'hardcover',
isActive: true, isActive: true,
userId: 'itsdylan', // your hardcover username userId: '62036', // your hardcover user ID (find in your API token or profile URL)
feedUrl: 'https://hardcover.app/api/graphql', feedUrl: 'https://api.hardcover.app/v1/graphql',
feedType: 'hardcover', feedType: 'hardcover',
showImage: true,
}, },
{ {
id: 'storygraph', id: 'storygraph',

View file

@ -262,10 +262,20 @@ export async function getHardcoverActivity(config) {
const query = ` const query = `
query { query {
user(username: "${userId}") { user_books(
currently_reading_books(limit: 1) { where: {user_id: {_eq: ${userId}}, status_id: {_eq: 2}}
) {
book {
title title
id id
image {
url
}
contributions {
author {
name
}
}
} }
} }
} }
@ -275,23 +285,24 @@ export async function getHardcoverActivity(config) {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
authorization: apiKey, authorization: `Bearer ${apiKey}`,
'User-Agent': 'now-updater/1.0 (omg.lol now page updater)',
}, },
body: JSON.stringify({ query }), body: JSON.stringify({ query }),
}) })
const data = await res.json() const data = await res.json()
if ( if (!data.data?.user_books || data.data.user_books.length === 0) {
!data.data?.user?.currently_reading_books ||
data.data.user.currently_reading_books.length === 0
) {
throw new Error('Nothing!') throw new Error('Nothing!')
} }
const book = data.data.user.currently_reading_books[0] const userBook = data.data.user_books[0]
const book = userBook.book
const author = book.contributions?.[0]?.author?.name || 'Unknown Author'
return { return {
text: book.title, text: `${book.title} by ${author}`,
url: `https://hardcover.app/books/${book.id}`, url: `https://hardcover.app/books/${book.id}`,
image: book.image?.url || null,
} }
} }
@ -310,20 +321,31 @@ export async function getSteamRecentlyPlayed(config) {
} }
const res = await fetch( const res = await fetch(
`https://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1/?key=${process.env.STEAM_WEBAPI_KEY}&steamid=${steamId}&format=json`, `https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key=${apiKey}&steamid=${steamId}&format=json&include_appinfo=1&include_played_free_games=1`,
) )
const data = await res.json() const data = await res.json()
if (!data.response.games || data.response.games.length === 0) { if (!data.response.games || data.response.games.length === 0) {
throw new Error('No recent games found') throw new Error('No games found')
} }
const game = data.response.games[0] // sort by most recently played
const games = data.response.games
const sortedGames = games
.filter((g) => g.rtime_last_played > 0)
.sort((a, b) => b.rtime_last_played - a.rtime_last_played)
if (sortedGames.length === 0) {
throw new Error('Nothing yet!')
}
const game = sortedGames[0]
const { name, appid } = game const { name, appid } = game
return { return {
text: name, text: name,
url: `https://store.steampowered.com/app/${appid}`, url: `https://store.steampowered.com/app/${appid}`,
image: `https://cdn.cloudflare.steamstatic.com/steam/apps/${appid}/library_600x900.jpg`,
} }
} }