updated hardcover and steam apis to actually work after testing
This commit is contained in:
parent
7dfff74ea0
commit
48a5aab1c2
2 changed files with 37 additions and 14 deletions
|
|
@ -116,9 +116,10 @@ export const services = [
|
|||
{
|
||||
id: 'hardcover',
|
||||
isActive: true,
|
||||
userId: 'itsdylan', // your hardcover username
|
||||
feedUrl: 'https://hardcover.app/api/graphql',
|
||||
userId: '62036', // your hardcover user ID (find in your API token or profile URL)
|
||||
feedUrl: 'https://api.hardcover.app/v1/graphql',
|
||||
feedType: 'hardcover',
|
||||
showImage: true,
|
||||
},
|
||||
{
|
||||
id: 'storygraph',
|
||||
|
|
|
|||
46
utils.js
46
utils.js
|
|
@ -262,10 +262,20 @@ export async function getHardcoverActivity(config) {
|
|||
|
||||
const query = `
|
||||
query {
|
||||
user(username: "${userId}") {
|
||||
currently_reading_books(limit: 1) {
|
||||
user_books(
|
||||
where: {user_id: {_eq: ${userId}}, status_id: {_eq: 2}}
|
||||
) {
|
||||
book {
|
||||
title
|
||||
id
|
||||
image {
|
||||
url
|
||||
}
|
||||
contributions {
|
||||
author {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -275,23 +285,24 @@ export async function getHardcoverActivity(config) {
|
|||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
authorization: apiKey,
|
||||
authorization: `Bearer ${apiKey}`,
|
||||
'User-Agent': 'now-updater/1.0 (omg.lol now page updater)',
|
||||
},
|
||||
body: JSON.stringify({ query }),
|
||||
})
|
||||
|
||||
const data = await res.json()
|
||||
if (
|
||||
!data.data?.user?.currently_reading_books ||
|
||||
data.data.user.currently_reading_books.length === 0
|
||||
) {
|
||||
if (!data.data?.user_books || data.data.user_books.length === 0) {
|
||||
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 {
|
||||
text: book.title,
|
||||
text: `${book.title} by ${author}`,
|
||||
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(
|
||||
`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()
|
||||
|
||||
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
|
||||
|
||||
return {
|
||||
text: name,
|
||||
url: `https://store.steampowered.com/app/${appid}`,
|
||||
image: `https://cdn.cloudflare.steamstatic.com/steam/apps/${appid}/library_600x900.jpg`,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue