forked from virgaux/USBpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
44 lines (42 loc) · 3 KB
/
user.js
File metadata and controls
44 lines (42 loc) · 3 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fetch = require("cross-fetch");
const basicCards = require('./data/basicCards'); //phantom cards available for the players but not visible in the api endpoint
getPlayerCards = async (username, oneDayAgo) => (await 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 => basicCards.concat(advanced))
.catch(async (e)=> {
console.log('Error: api.splinterlands did not respond trying game-api.slinterlands... '); //2nd try
await fetch(`https://game-api.splinterlands.io/cards/collection/${username}`)
.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 => basicCards.concat(advanced))
.catch(async (e)=> {
console.log('Error: game-api.splinterlands did not respond trying api.slinterlands... '); //3rd try
await fetch(`https://api.steemmonsters.io/cards/collection/${username}`)
.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 => basicCards.concat(advanced))
.catch(async (e)=> {
console.log('Error: api.steemmonsters did not respond trying api2.slinterlands... '); //4th try
await fetch(`https://api2.splinterlands.com/cards/collection/${username}`)
.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 => basicCards.concat(advanced))
.catch(e => {
console.log('Using only basic cards due to error when getting user collection from splinterlands: ',e);
return basicCards
})
})
})
})
)
module.exports.getPlayerCards = getPlayerCards;