Junaidb commited on
Commit
2a70fa3
·
verified ·
1 Parent(s): 3f7882d

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +75 -0
index.js CHANGED
@@ -1,15 +1,90 @@
1
  import express from 'express';
 
 
2
 
3
 
4
  const app = express();
5
  app.use(express.json());
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  //Routes
8
 
9
  app.get('/', (req, res) => {
10
  res.json({ status: 'ok' });
11
  });
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  app.post('/route', (req, res) => {
14
  const { name, value } = req.body;
15
  res.json({ success: true });
 
1
  import express from 'express';
2
+ import { PinataSDK } from "pinata";
3
+
4
 
5
 
6
  const app = express();
7
  app.use(express.json());
8
 
9
+
10
+
11
+
12
+
13
+ async function getcreds() {
14
+
15
+ let request=await fetch("https://immutablehub-creds.hf.space/creds",{
16
+ mode:"cors",
17
+ method:"get",
18
+ headers:{
19
+ "content-type":"application/json"
20
+ }
21
+ })
22
+ let response=await request.json()
23
+ return {"jwt":response.jwt,"gateway":response.gateway}
24
+
25
+ }
26
+
27
+
28
+ async function getToken(){
29
+
30
+ let request=await fetch("https://immutablehub-creds.hf.space/hft",{
31
+ mode:"cors",
32
+ method:"get",
33
+ headers:{
34
+ "content-type":"application/json"
35
+ }
36
+ })
37
+ let response=await request.json()
38
+ return {"hft":response.hft}
39
+
40
+ }
41
+
42
+
43
+
44
+ async function getRuntime() {
45
+
46
+ const { jwt, gateway } = await getcreds();
47
+ const pinata = new PinataSDK({ pinataJwt: jwt, pinataGateway: gateway });
48
+
49
+
50
+
51
+ const client = provideClient();
52
+ return { pinata, client };
53
+
54
+ }
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
  //Routes
68
 
69
  app.get('/', (req, res) => {
70
  res.json({ status: 'ok' });
71
  });
72
 
73
+
74
+
75
+ app.get('/hft',(req,res)=>{
76
+
77
+
78
+ let result=await getToken()
79
+ res.json({"hft":result.hft})
80
+
81
+ });
82
+
83
+
84
+
85
+
86
+
87
+
88
  app.post('/route', (req, res) => {
89
  const { name, value } = req.body;
90
  res.json({ success: true });