remove js-ipfs in electron app, eslint to dev deps (#123)
- add ipfs:// protocol handlers, not enabled for now - use browser-side auto-js-ipfs for loading from ipfs even in electron app - deps: bump wabac.js to 2.13.0 - update CHANGES Co-authored-by: Ilya Kreymer <ikreymer@gmail.com>
This commit is contained in:
co-authored by
Ilya Kreymer
parent
43122425e5
commit
f1df02ea3c
@@ -0,0 +1,44 @@
|
||||
import { protocol, session } from "electron";
|
||||
|
||||
import fetchToHandler from "fetch-to-electron-protocol-handler";
|
||||
import makeIPFSFetch from "js-ipfs-fetch";
|
||||
import * as IPFS from "ipfs-core";
|
||||
|
||||
export const PROTOCOL_PERMISSIONS = {
|
||||
standard: true,
|
||||
secure: true,
|
||||
allowServiceWorkers: true,
|
||||
supportFetchAPI: true,
|
||||
bypassCSP: false,
|
||||
corsEnabled: true,
|
||||
stream: true
|
||||
};
|
||||
|
||||
export function registerPrivileges(privileges = PROTOCOL_PERMISSIONS) {
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{scheme: "ipfs", privileges},
|
||||
{scheme: "ipns", privileges},
|
||||
{scheme: "ipld", privileges}
|
||||
]);
|
||||
}
|
||||
|
||||
export function registerHandler(ipfsRepoPath) {
|
||||
const handler = createHandler(ipfsRepoPath);
|
||||
protocol.registerStreamProtocol("ipfs", handler);
|
||||
protocol.registerStreamProtocol("ipns", handler);
|
||||
protocol.registerStreamProtocol("ipld", handler);
|
||||
}
|
||||
|
||||
export function createHandler (ipfsRepoPath) {
|
||||
const {handler} = fetchToHandler(async () => {
|
||||
const ipfs = await IPFS.create({
|
||||
repo: ipfsRepoPath
|
||||
});
|
||||
|
||||
const fetch = await makeIPFSFetch({ ipfs });
|
||||
|
||||
return fetch;
|
||||
}, session.defaultSession);
|
||||
|
||||
return handler;
|
||||
}
|
||||
Reference in New Issue
Block a user