TTVDB_API_KEY fix
This commit is contained in:
@@ -53,7 +53,7 @@ const TMDB_IMG_BASE =
|
|||||||
process.env.TMDB_IMAGE_BASE || "https://image.tmdb.org/t/p/original";
|
process.env.TMDB_IMAGE_BASE || "https://image.tmdb.org/t/p/original";
|
||||||
const TVDB_API_KEY =
|
const TVDB_API_KEY =
|
||||||
process.env.TTVDB_API_KEY || process.env.TVDB_API_KEY || null;
|
process.env.TTVDB_API_KEY || process.env.TVDB_API_KEY || null;
|
||||||
const TVDB_USER_TOKEN = process.env.TVDB_USER_TOKEN || null;
|
const TVDB_USER_TOKEN = "mock_api_key"
|
||||||
const TVDB_BASE_URL = "https://api4.thetvdb.com/v4";
|
const TVDB_BASE_URL = "https://api4.thetvdb.com/v4";
|
||||||
const TVDB_IMAGE_BASE =
|
const TVDB_IMAGE_BASE =
|
||||||
process.env.TVDB_IMAGE_BASE || "https://artworks.thetvdb.com";
|
process.env.TVDB_IMAGE_BASE || "https://artworks.thetvdb.com";
|
||||||
@@ -842,15 +842,7 @@ const TVDB_TOKEN_TTL = 1000 * 60 * 60 * 20; // 20 saat
|
|||||||
async function getTvdbToken(force = false) {
|
async function getTvdbToken(force = false) {
|
||||||
if (!TVDB_API_KEY) return null;
|
if (!TVDB_API_KEY) return null;
|
||||||
|
|
||||||
if (!TVDB_USER_TOKEN) {
|
const trimmedUserToken = (TVDB_USER_TOKEN || "").trim();
|
||||||
// V4 kişisel token senaryosu: doğrudan API key'i Bearer olarak kullan
|
|
||||||
tvdbAuthState = {
|
|
||||||
token: TVDB_API_KEY,
|
|
||||||
expires: Date.now() + TVDB_TOKEN_TTL
|
|
||||||
};
|
|
||||||
console.log("📺 TVDB token (kişisel anahtar) kullanılıyor.");
|
|
||||||
return tvdbAuthState.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (
|
if (
|
||||||
@@ -860,35 +852,50 @@ async function getTvdbToken(force = false) {
|
|||||||
) {
|
) {
|
||||||
return tvdbAuthState.token;
|
return tvdbAuthState.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (trimmedUserToken) {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`${TVDB_BASE_URL}/login`, {
|
const resp = await fetch(`${TVDB_BASE_URL}/login`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json"
|
||||||
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
apikey: TVDB_API_KEY,
|
apikey: TVDB_API_KEY,
|
||||||
userkey: TVDB_USER_TOKEN
|
userkey: trimmedUserToken
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (!resp.ok) {
|
if (resp.ok) {
|
||||||
console.warn(`⚠️ TVDB login başarısız: ${resp.status}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const json = await resp.json();
|
const json = await resp.json();
|
||||||
const token = json?.data?.token;
|
const token = json?.data?.token;
|
||||||
if (!token) {
|
if (token) {
|
||||||
console.warn("⚠️ TVDB login yanıtında token bulunamadı");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
console.log("📺 TVDB token alındı (login).");
|
console.log("📺 TVDB token alındı (login).");
|
||||||
tvdbAuthState = {
|
tvdbAuthState = {
|
||||||
token,
|
token,
|
||||||
expires: Date.now() + TVDB_TOKEN_TTL
|
expires: Date.now() + TVDB_TOKEN_TTL
|
||||||
};
|
};
|
||||||
return token;
|
return token;
|
||||||
} catch (err) {
|
|
||||||
console.warn(`⚠️ TVDB login hatası: ${err.message}`);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
console.warn("⚠️ TVDB login yanıtında token bulunamadı, API key'e düşülüyor.");
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
`⚠️ TVDB login başarısız (${resp.status}); API key ile devam edilecek.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(
|
||||||
|
`⚠️ TVDB login hatası (${err.message}); API key ile devam edilecek.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tvdbAuthState = {
|
||||||
|
token: TVDB_API_KEY,
|
||||||
|
expires: Date.now() + TVDB_TOKEN_TTL
|
||||||
|
};
|
||||||
|
console.log("📺 TVDB token (API key) kullanılıyor.");
|
||||||
|
return tvdbAuthState.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tvdbFetch(pathname, options = {}, retry = true) {
|
async function tvdbFetch(pathname, options = {}, retry = true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user