Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error and slow network #179

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions apps/box/src/file/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {FileProtocol as Protocol, SchemaProtocol as Schema} from "@functionland/file-protocol";
import config from "config";
import { create } from 'ipfs-http-client'

const IPFS_HTTP = config.get("ipfs.http")

export const registerFile = async (libp2pNode, ipfsNode) => {

Expand All @@ -11,25 +8,40 @@ export const registerFile = async (libp2pNode, ipfsNode) => {


Protocol.setMetaRetrievalMethod(async ({id}) => {
for await (const file of ipfsNode.cat(id)) {
const {meta} = Schema.File.fromBinary(file);
return meta;
try{
for await (const file of ipfsNode.cat(id)) {
const {meta} = Schema.File.fromBinary(file);
return meta;
}
}catch (e) {
console.log(e)
}

});

Protocol.setContentRetrievalMethod(async ({id}) => {
for await (const file of ipfsNode.cat(id)) {
const {contentPath} = Schema.File.fromBinary(file);
return ipfsNode.cat(contentPath);
try {
for await (const file of ipfsNode.cat(id)) {
const {contentPath} = Schema.File.fromBinary(file);
return ipfsNode.cat(contentPath);
}
}catch (e) {
console.log(e)
}

});

Protocol.incomingFiles.subscribe(async ({getContent, meta, declareId}) => {
const {cid: file} = await ipfsNode.add(
getContent()
);
const {cid} = await ipfsNode.add(Schema.File.toBinary({contentPath: file.toString(), meta}));
declareId(cid.toString());
try{
const {cid: file} = await ipfsNode.add(
getContent()
);
const {cid} = await ipfsNode.add(Schema.File.toBinary({contentPath: file.toString(), meta}));
declareId(cid.toString());
}catch (e) {
console.log(e)
}

});
}

Expand Down
54 changes: 32 additions & 22 deletions apps/box/src/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,47 @@ export const registerGraph = async (libp2pNode, ipfsNode) => {
}

setQueryResolutionMethod(async function (req: Request) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

const {query, variableValues, operationName} = Request.toJson(req)
const gqlQuery = parse(query)
const data = await executeAndSelect(gqlQuery, resolvers, variableValues, operationName, loadDB)
const s = Result.fromJson(data)
const bytes = Result.toBinary(s)
return bytes && toAsyncIterable([bytes]);
})

setSubscriptionQueryResolutionMethod(async function* (req: Request) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
try{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const {query, variableValues, operationName} = Request.toJson(req)
const gqlQuery = parse(query)
const data = await executeAndSelect(gqlQuery, resolvers, variableValues, operationName, loadDB)
const s = Result.fromJson(data)
const bytes = Result.toBinary(s)
return bytes && toAsyncIterable([bytes]);
}catch (e) {
console.log(e)
}

const {query, variableValues, operationName} = Request.toJson(req)
const gqlQuery = parse(query)
})

const [values, next, complete] = iterateLater()
setSubscriptionQueryResolutionMethod(async function* (req: Request) {
try{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

const data = await executeAndSelect(gqlQuery, resolvers, variableValues, operationName, loadDB, next, true)
const s = Result.fromJson(data)
const bytes = Result.toBinary(s)
const {query, variableValues, operationName} = Request.toJson(req)
const gqlQuery = parse(query)

yield bytes
const [values, next, complete] = iterateLater()

for await (const res of values) {
const s = Result.fromJson(res)
const data = await executeAndSelect(gqlQuery, resolvers, variableValues, operationName, loadDB, next, true)
const s = Result.fromJson(data)
const bytes = Result.toBinary(s)

yield bytes

for await (const res of values) {
const s = Result.fromJson(res)
const bytes = Result.toBinary(s)

yield bytes
}
}catch (e) {
console.log(e)
}

})
}
2 changes: 2 additions & 0 deletions common/config/rush/.npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
#
registry=https://registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
always-auth=false
timeout=60000
prefer-offline=true