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

feat: support for go-ipfs 0.5 #1392

Merged
merged 5 commits into from
Apr 23, 2020
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ init:
- git config --global core.autocrlf input

install:
- ps: Install-Product node 10 x64
- ps: Install-Product node 12 x64
- npm install

build_script:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "cross-env NODE_ENV=development electron src/index.js",
"lint": "standard",
"test": "cross-env NODE_ENV=test mocha test/unit/**/*.spec.js",
"test:e2e": "xvfb-maybe cross-env NODE_ENV=test mocha test/e2e/**/*.e2e.js --exit",
"test:e2e": "xvfb-maybe cross-env NODE_ENV=test LIBP2P_ALLOW_WEAK_RSA_KEYS=1 mocha test/e2e/**/*.e2e.js --exit",
"postinstall": "run-s install-app-deps build:webui",
"install-app-deps": "electron-builder install-app-deps",
"clean:webui": "shx rm -rf assets/webui/",
Expand Down Expand Up @@ -102,6 +102,6 @@
"yargs": "^15.3.1"
},
"go-ipfs": {
"version": "v0.4.23"
"version": "v0.5.0-rc3"
}
}
2 changes: 1 addition & 1 deletion src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const parseCfgMultiaddr = (addr) => (addr.includes('/http')

async function checkIfAddrIsDaemon (addr) {
const options = {
method: 'GET',
method: 'POST',
host: addr.address,
port: addr.port,
path: '/api/v0/refs?arg=/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
Expand Down
16 changes: 15 additions & 1 deletion src/webui/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { screen, BrowserWindow, ipcMain, app, session } = require('electron')
const { join } = require('path')
const { URL } = require('url')
const toUri = require('multiaddr-to-uri')
const serve = require('electron-serve')
const os = require('os')
const openExternal = require('./open-external')
const logger = require('../common/logger')
const store = require('../common/store')
const dock = require('../utils/dock')
const { VERSION } = require('../common/consts')

serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })

Expand Down Expand Up @@ -59,6 +61,16 @@ const createWindow = () => {
return window
}

// Converts a Multiaddr to a valid value for Origin HTTP header
const apiOrigin = (apiMultiaddr) => {
// Return opaque origin when there is no API yet
// https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque
if (!apiMultiaddr) return 'null'
// Return the Origin of HTTP API
const apiUri = toUri(apiMultiaddr, { assumeHttp: true })
return new URL(apiUri).origin
}

module.exports = async function (ctx) {
openExternal()

Expand Down Expand Up @@ -109,7 +121,9 @@ module.exports = async function (ctx) {
})

session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
delete details.requestHeaders.Origin
// Avoid setting CORS by acting like /webui loaded from API port
details.requestHeaders.Origin = apiOrigin(apiAddress)
details.requestHeaders['User-Agent'] = `ipfs-desktop/${VERSION}`
callback({ cancel: false, requestHeaders: details.requestHeaders }) // eslint-disable-line
})

Expand Down