Skip to content

Commit

Permalink
Add gateway for internal
Browse files Browse the repository at this point in the history
  • Loading branch information
undyingwraith committed May 8, 2024
1 parent 42bd9d0 commit f29ddd3
Show file tree
Hide file tree
Showing 4 changed files with 524 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"recommendations": [
"arcanis.vscode-zipfs"
]
"recommendations": [
"arcanis.vscode-zipfs",
"github.vscode-github-actions",
"dsznajder.es7-react-js-snippets",
"ecmel.vscode-html-css"
]
}
2 changes: 2 additions & 0 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"blockstore-fs": "^1.1.10",
"datastore-level": "^10.1.8",
"electron-updater": "6.2.1",
"express": "^4.19.2",
"helia": "^4.1.1",
"ipmc-core": "workspace:^",
"kubo-rpc-client": "^4.1.1",
Expand All @@ -52,6 +53,7 @@
"@electron-toolkit/tsconfig": "^1.0.1",
"@preact/signals-react-transform": "^0.3.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@types/express": "^4",
"@types/node": "^20.12.10",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
Expand Down
12 changes: 11 additions & 1 deletion packages/desktop/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { create } from 'kubo-rpc-client';
import fs from 'fs';

import { IConfigurationService, INodeService, IInternalProfile, IProfile, IIpfsService, IFileInfo } from 'ipmc-core';
import express from 'express';

function getProfileFolder(name: string): string {
return `./profiles/${name}`
Expand Down Expand Up @@ -63,6 +64,15 @@ const nodeService: INodeService = {

const fs = unixfs(helia);

const app = express();
app.get('/:cid', async (request, response) => {
for await (const buf of fs.cat(CID.parse(request.params.cid))) {
response.write(buf)
}
response.end()
});
await new Promise<void>((resolve) => app.listen(8090, () => resolve()));

return ({
async ls(cid: string) {
const files: IFileInfo[] = [];
Expand All @@ -81,7 +91,7 @@ const nodeService: INodeService = {
await datastore.close();
},
toUrl(cid: string) {
return `TODO ${cid}`;
return `http://127.0.0.1:8090/${cid}`;
},
peers() {
return Promise.resolve(helia.libp2p.getPeers().map(p => p.toString()));
Expand Down
Loading

0 comments on commit f29ddd3

Please sign in to comment.