Skip to content

Commit 0867693

Browse files
committed
fix: trakt api calls require user-agent
1 parent aac814d commit 0867693

5 files changed

+241
-99
lines changed

config/passport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ const traktStrategyConfig = new OAuth2Strategy(
750750
'trakt-api-version': 2,
751751
'trakt-api-key': process.env.TRAKT_ID,
752752
'Content-Type': 'application/json',
753+
'User-Agent': 'Hackathon-Starter',
753754
},
754755
});
755756
if (!response.ok) {

controllers/api.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,12 @@ async function fetchAndCacheTraktImage(imageUrl) {
12871287

12881288
// Download and save
12891289
try {
1290-
const response = await fetch(imageUrl);
1290+
const response = await fetch(imageUrl, {
1291+
method: 'GET',
1292+
headers: {
1293+
'User-Agent': 'Hackathon-Starter',
1294+
},
1295+
});
12911296
if (!response.ok) return null;
12921297
const buffer = Buffer.from(await response.arrayBuffer());
12931298
const absPath = path.join(imageCacheDir, filename);
@@ -1321,6 +1326,7 @@ async function fetchTraktUserProfile(traktToken) {
13211326
'trakt-api-version': 2,
13221327
'trakt-api-key': process.env.TRAKT_ID,
13231328
'Content-Type': 'application/json',
1329+
'User-Agent': 'Hackathon-Starter',
13241330
},
13251331
});
13261332
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
@@ -1334,6 +1340,7 @@ async function fetchTraktUserHistory(traktToken, limit) {
13341340
'trakt-api-version': 2,
13351341
'trakt-api-key': process.env.TRAKT_ID,
13361342
'Content-Type': 'application/json',
1343+
'User-Agent': 'Hackathon-Starter',
13371344
},
13381345
});
13391346
if (!res.ok) return [];
@@ -1346,6 +1353,7 @@ async function fetchTraktTrendingMovies(limit) {
13461353
'trakt-api-version': 2,
13471354
'trakt-api-key': process.env.TRAKT_ID,
13481355
'Content-Type': 'application/json',
1356+
'User-Agent': 'Hackathon-Starter',
13491357
},
13501358
});
13511359
if (!res.ok) return [];
@@ -1372,6 +1380,7 @@ async function fetchMovieDetails(slug, watchers) {
13721380
'trakt-api-version': 2,
13731381
'trakt-api-key': process.env.TRAKT_ID,
13741382
'Content-Type': 'application/json',
1383+
'User-Agent': 'Hackathon-Starter',
13751384
},
13761385
});
13771386
if (!res.ok) return null;

test/fixtures/GET_https%3A%2F%2Fapi.trakt.tv%2Fmovies%2Fa-house-of-dynamite-2025%3Fextended%3Dfull%252Cimages.json

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"ids": { "imdb": "tt31050594", "plex": { "guid": "65b41a7eb5cab988940e14b1", "slug": "mercy-2026" }, "slug": "mercy-2026", "tmdb": 1236153, "trakt": 1000015 },
3+
"year": 2026,
4+
"title": "Mercy",
5+
"votes": 3283,
6+
"colors": { "poster": ["#D3D6D1", "#564238"] },
7+
"genres": ["science-fiction", "action", "thriller"],
8+
"images": {
9+
"logo": ["media.trakt.tv/images/movies/001/000/015/logos/medium/f75246b9b7.png.webp"],
10+
"thumb": ["media.trakt.tv/images/movies/001/000/015/thumbs/medium/15b5134234.jpg.webp"],
11+
"banner": ["media.trakt.tv/images/movies/001/000/015/banners/medium/a12658a749.jpg.webp"],
12+
"fanart": ["media.trakt.tv/images/movies/001/000/015/fanarts/medium/9bff8f863d.jpg.webp"],
13+
"poster": ["media.trakt.tv/images/movies/001/000/015/posters/medium/504c0cc266.jpg.webp"],
14+
"clearart": ["media.trakt.tv/images/movies/001/000/015/cleararts/medium/3869f112e8.png.webp"]
15+
},
16+
"rating": 6.969235420227051,
17+
"status": "released",
18+
"country": "us",
19+
"runtime": 99,
20+
"tagline": "Prove your innocence to an AI judge or face execution.",
21+
"trailer": "https://youtube.com/watch?v=JUADqWkJiiE",
22+
"homepage": "https://www.amazon.com/salp/mercy?hhf=",
23+
"language": "en",
24+
"overview": "In the near future, a detective stands on trial accused of murdering his wife. He has ninety minutes to prove his innocence to the advanced AI Judge he once championed, before it determines his fate.",
25+
"released": "2026-01-23",
26+
"languages": ["en"],
27+
"subgenres": ["kidnapping", "father-daughter-relationship", "artificial-intelligence-a-i", "near-future"],
28+
"updated_at": "2026-02-24T08:29:10.000Z",
29+
"after_credits": false,
30+
"certification": "PG-13",
31+
"comment_count": 40,
32+
"during_credits": false,
33+
"original_title": "Mercy",
34+
"available_translations": ["ar", "az", "bg", "ca", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "he", "hr", "hu", "it", "ja", "ka", "ko", "lt", "lv", "nl", "pl", "pt", "ro", "ru", "sk", "sl", "sv", "th", "tr", "uk", "vi", "zh"]
35+
}

0 commit comments

Comments
 (0)