Skip to content

Commit

Permalink
remove id mapping json due to mistakes in it
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Sep 11, 2024
1 parent 992187e commit 720c4b1
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions lib/id_convert.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
const axios = require('axios');
const { cacheWrapIdMapping } = require('./cache');

const ID_MAPPING_URL = 'https://1fe84bc728af-stremio-anime-catalogs.baby-beamup.club/map.json';
const VALID_FOR = 12 * 60 * 60 * 1000; // 12 hours
let fetchedAt;
let mapping = {}

async function mapToKitsuId(fullId) {
const idType = fullId.split(":")[0];
const id = fullId.split(":")[1];
if (idType === 'kitsu') {
return id;
}
if (!fetchedAt || new Date() - fetchedAt > VALID_FOR) {
mapping = await getMappingJson();
fetchedAt = new Date()
console.log(`Refreshed id mapping list at ${fetchedAt.toISOString()}`)
}
return cacheWrapIdMapping(fullId, () => queryIdMapping(idType, id).catch(() => mapping[idType]?.[id]))

return cacheWrapIdMapping(fullId, () => queryIdMapping(idType, id));
}

async function queryIdMapping(idType, id) {
Expand All @@ -30,16 +21,4 @@ async function queryIdMapping(idType, id) {
: Promise.reject(`No kitsu id found for: ${idType}:${id}`))
}

async function getMappingJson(retry = 2) {
return axios.get(ID_MAPPING_URL, { timeout: 30000 })
.then(response => response.data)
.catch(error => {
if (retry === 0) {
console.log(`Failed retrieving id mapping list: ${error.message}`);
throw error;
}
return getMappingJson(retry - 1);
});
}

module.exports = { mapToKitsuId, queryIdMapping };

0 comments on commit 720c4b1

Please sign in to comment.