Spaces:
Sleeping
Sleeping
| import express from 'express'; | |
| import { algoliasearch } from "algoliasearch"; | |
| const app = express(); | |
| app.use(express.json()); | |
| async function getcreds() { | |
| let request=await fetch("https://immutablehub-creds.hf.space/creds",{ | |
| mode:"cors", | |
| method:"get", | |
| headers:{ | |
| "content-type":"application/json" | |
| } | |
| }) | |
| let response=await request.json() | |
| return {"jwt":response.jwt,"gateway":response.gateway} | |
| } | |
| async function getToken(){ | |
| let request=await fetch("https://immutablehub-creds.hf.space/hft",{ | |
| mode:"cors", | |
| method:"get", | |
| headers:{ | |
| "content-type":"application/json" | |
| } | |
| }) | |
| let response=await request.json() | |
| return {"hft":response.hft} | |
| } | |
| const aclient = algoliasearch('D79SNO8B1R', '5e28f0f65380b998763c5251289f6d9b'); | |
| async function SavetoAlgolia(raw){ | |
| //const raw = fs.readFileSync("./package.json","utf8"); | |
| const pkg = JSON.parse(raw); | |
| const meta = { | |
| name: pkg.name, | |
| description: pkg.description, | |
| author: pkg.author, | |
| license: pkg.license, | |
| version: pkg.version, | |
| readme:`ihub op clone <mcp server name>` | |
| }; | |
| let algolia_insertion=await aclient.saveObject({ | |
| indexName: 'mcp', | |
| body: meta | |
| }); | |
| if(algolia_insertion.taskID){ | |
| return true | |
| } | |
| else { | |
| return false | |
| } | |
| } | |
| async function SavetoAlgoliaIPM(raw){ | |
| //const raw = fs.readFileSync("./package.json","utf8"); | |
| const pkg = JSON.parse(raw); | |
| const meta = { | |
| name: pkg.name, | |
| description: pkg.description, | |
| author: pkg.author, | |
| license: pkg.license, | |
| version: pkg.version, | |
| readme:`ihub op clone <mcp server name>` | |
| }; | |
| let algolia_insertion=await aclient.saveObject({ | |
| indexName: 'ipm', | |
| body: meta | |
| }); | |
| if(algolia_insertion.taskID){ | |
| return true | |
| } | |
| else { | |
| return false | |
| } | |
| } | |
| //Routes | |
| app.get('/', (req, res) => { | |
| res.json({ status: 'ok' }); | |
| }); | |
| app.get('/hft',async (req,res)=>{ | |
| let result=await getToken() | |
| res.json({"hft":result.hft}) | |
| }); | |
| app.get('/creds',async (req,res)=>{ | |
| let result=await getcreds() | |
| res.json({"jwt":result.jwt,"gateway":result.gateway}) | |
| }); | |
| app.post('/algolia',async (req,res)=>{ | |
| let {meta}=req.body | |
| let response=await SavetoAlgolia(meta) | |
| res.json({"response":response}) | |
| }) | |
| app.post('/algoliaipm',async (req,res)=>{ | |
| let {meta}=req.body | |
| let response=await SavetoAlgoliaIPM(meta) | |
| res.json({"response":response}) | |
| }) | |
| // Start | |
| app.listen(7860, () => console.log('server running on port 7860')); |