Skip to content

Commit 668b5e8

Browse files
committed
env file + add os api
1 parent 2e28553 commit 668b5e8

File tree

4 files changed

+1012
-3404
lines changed

4 files changed

+1012
-3404
lines changed

packages/server/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
.env

packages/server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
},
99
"devDependencies": {
1010
"api": "^4.2.0",
11-
"opensea-js": "^1.2.7",
11+
"opensea-js": "^3.0.4",
1212
"typescript": "^4.5.4"
1313
},
1414
"dependencies": {
1515
"@types/express": "^4.17.13",
1616
"@types/node": "^17.0.8",
1717
"axios": "^0.24.0",
18+
"dotenv": "^16.0.0",
1819
"express": "^4.17.2",
1920
"ts-node-dev": "^1.1.8",
2021
"web3": "^1.6.1"

packages/server/src/index.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
import "dotenv/config";
2+
13
import express, { Application, Request, Response } from "express";
24
import axios from "axios";
5+
import { env } from "process";
6+
7+
// Env setup
8+
const apiKey = env["apiKey"];
39

10+
// Express server
411
const app: Application = express();
512
const port = 3001;
613

14+
// Axios setup
15+
axios.defaults.headers.common["X-API-KEY"] = apiKey;
16+
717
// Body parsing Middleware
818
app.use(express.json());
919
app.use(express.urlencoded({ extended: true }));
1020
app.use(express.static(__dirname + "/../public"));
1121

22+
type NFT = {
23+
img: string;
24+
id: number;
25+
};
26+
27+
type NFTs = { [contract: string]: NFT[] };
28+
1229
type 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-
4848
app.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

7581
app.get("/", async (req: Request, res: Response): Promise<Response> => {

0 commit comments

Comments
 (0)