1+ import "dotenv/config" ;
2+
13import express , { Application , Request , Response } from "express" ;
24import axios from "axios" ;
5+ import { env } from "process" ;
6+
7+ // Env setup
8+ const apiKey = env [ "apiKey" ] ;
39
10+ // Express server
411const app : Application = express ( ) ;
512const port = 3001 ;
613
14+ // Axios setup
15+ axios . defaults . headers . common [ "X-API-KEY" ] = apiKey ;
16+
717// Body parsing Middleware
818app . use ( express . json ( ) ) ;
919app . use ( express . urlencoded ( { extended : true } ) ) ;
1020app . use ( express . static ( __dirname + "/../public" ) ) ;
1121
22+ type NFT = {
23+ img : string ;
24+ id : number ;
25+ } ;
26+
27+ type NFTs = { [ contract : string ] : NFT [ ] } ;
28+
1229type Collection = {
1330 name : string ;
1431 contract : string ;
@@ -28,23 +45,6 @@ const DROPS = [
2845 } ,
2946] ;
3047
31- const fakeAnswer = {
32- Sublimes : [
33- {
34- id : 825 ,
35- img : "https://lh3.googleusercontent.com/iUN-rqbSEW97A_YNFiUeKuIoQRtIP08w8st9GnBqsQiydLaiF68pGDP4gx-URYmEph_SqXumjZj3TRGxPIFQBR9ZWxDZicur50a8hA=s0" ,
36- } ,
37- {
38- id : 437 ,
39- img : "https://lh3.googleusercontent.com/nlO5vgcrUqgqPlHHrQHrlA5ZsXg2hIxkJkzr72oK9KU9cNojTO8HAxWCOH06xNw0R5_ZocxNuXhLHwbHC282uz63pNnjfQd-mABKEA=s0" ,
40- } ,
41- {
42- id : 108 ,
43- img : "https://lh3.googleusercontent.com/-JDl1IBKkvQtOJKApygolCMXCV09SDAftc5IhqO585oFXvV-XhpaOFEI_WJFJdTJT6l8ypxMb-FlkQGPRNNPN4enIFJoAIpDA2Y7=s0" ,
44- } ,
45- ] ,
46- } ;
47-
4848app . get ( "/drop/:drop" , async ( req : Request , res : Response ) : Promise < Response > => {
4949 const drop = DROPS [ req . params . drop ] ;
5050
@@ -57,19 +57,25 @@ app.get("/drop/:drop/:address", async (req: Request, res: Response): Promise<Res
5757 const drop = DROPS [ req . params . drop as any as number ] ;
5858 const address = req . params . address ;
5959
60- // let data = {};
61- // for (let collection of drop.collections) {
62- // const resq = await axios.get(
63- // `https://api.opensea.io/api/v1/assets?owner=${address}&asset_contract_address=${collection.contract}&order_direction=desc&offset=0&limit=20`
64- // );
60+ let nftsForDropByAddress : NFTs = { } ;
61+
62+ for ( let collection of drop . collections ) {
63+ const resq = await axios . get (
64+ `https://api.opensea.io/api/v1/assets?owner=${ address } &asset_contract_address=${ collection . contract } &order_direction=desc&offset=0&limit=50`
65+ ) ;
66+
67+ let nfts : NFT [ ] = [ ] ;
68+ for ( let asset of resq . data . assets ) {
69+ nfts . push ( {
70+ img : asset . image_url ,
71+ id : asset . token_id ,
72+ } ) ;
73+ }
6574
66- // data[collection.name] = {
67- // ...data[collection.name],
68- // ...resq.data.assets,
69- // };
70- // }
75+ nftsForDropByAddress [ collection . contract ] = nfts ;
76+ }
7177
72- return res . status ( 200 ) . send ( fakeAnswer ) ;
78+ return res . status ( 200 ) . send ( nftsForDropByAddress ) ;
7379} ) ;
7480
7581app . get ( "/" , async ( req : Request , res : Response ) : Promise < Response > => {
0 commit comments