-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.js
More file actions
27 lines (25 loc) · 1.94 KB
/
user.js
File metadata and controls
27 lines (25 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fetch = require("node-fetch");
const basicCards = require('./data/basicCards'); //phantom cards available for the players but not visible in the api endpoint
getPlayerCards = (username, oneDayAgo) => (fetch(`https://game-api.splinterlands.io/cards/collection/${username}`,
{ "credentials": "omit", "headers": { "accept": "application/json, text/javascript, */*; q=0.01" }, "referrer": `https://splinterlands.com/?p=collection&a=${username}`, "referrerPolicy": "no-referrer-when-downgrade", "body": null, "method": "GET", "mode": "cors" })
.then(x => x && x.json())
.then(x => x['cards'] ? x['cards'].filter(x=>(x.delegated_to === null || x.delegated_to === username)
&& (x.market_listing_type === null || x.delegated_to === username)
&& (!(x.last_used_player !== username && Date.parse(x.last_used_date) > oneDayAgo))).map(card => card.card_detail_id) : '')
.then(advanced => advanced.concat(basicCards))
.catch(e=> {
console.log('Error: game-api.splinterlands did not respond trying api.slinterlands... ');
fetch(`https://api.splinterlands.io/cards/collection/${username}`,
{ "credentials": "omit", "headers": { "accept": "application/json, text/javascript, */*; q=0.01" }, "referrer": `https://splinterlands.com/?p=collection&a=${username}`, "referrerPolicy": "no-referrer-when-downgrade", "body": null, "method": "GET", "mode": "cors" })
.then(x => x && x.json())
.then(x => x['cards'] ? x['cards'].filter(x=>(x.delegated_to === null || x.delegated_to === username)
&& (x.market_listing_type === null || x.delegated_to === username)
&& (!(x.last_used_player !== username && Date.parse(x.last_used_date) > oneDayAgo))).map(card => card.card_detail_id) : '')
.then(advanced => advanced.concat(basicCards))
.catch(e => {
console.log('Using only basic cards due to error when getting user collection from splinterlands: ',e);
return basicCards
})
})
)
module.exports.getPlayerCards = getPlayerCards;