Skip to content

Commit

Permalink
chore: switch to standard v12
Browse files Browse the repository at this point in the history
Tried to delay it for too long.  This commit updates to v12 and applies
standard --fix to entire codebase.

It also removed babel-eslint parser, because v12 is able to parse new
language features on its own now.
  • Loading branch information
lidel committed Aug 30, 2018
1 parent 3db746a commit 53cfa83
Show file tree
Hide file tree
Showing 30 changed files with 461 additions and 396 deletions.
22 changes: 11 additions & 11 deletions add-on/src/contentScripts/linkifyDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const browser = require('webextension-polyfill')
const PQueue = require('p-queue')

/*
/*
* This content script is responsible for performing the logic of replacing
* plain text with IPFS addresses with clickable links.
* Loosely based on https://github.com/mdn/webextensions-examples/blob/master/emoji-substitution/substitute.js
Expand Down Expand Up @@ -50,16 +50,16 @@ const PQueue = require('p-queue')
const linkifyJobs = new PQueue({ concurrency: 1 })
// console.log('[ipfs-companion] running Linkify experiment')
linkifyContainer(document.body, linkifyJobs)
.then(() => {
// console.log('[ipfs-companion] registering MutationObserver for Linkify experiment')
new MutationObserver(function (mutations) {
mutations.forEach(async (mutation) => linkifyMutation(mutation, linkifyJobs))
}).observe(document.body, {
characterData: true,
childList: true,
subtree: true
.then(() => {
// console.log('[ipfs-companion] registering MutationObserver for Linkify experiment')
new MutationObserver(function (mutations) {
mutations.forEach(async (mutation) => linkifyMutation(mutation, linkifyJobs))
}).observe(document.body, {
characterData: true,
childList: true,
subtree: true
})
})
})
}

async function linkifyMutation (mutation, linkifyJobs) {
Expand Down Expand Up @@ -130,7 +130,7 @@ const PQueue = require('p-queue')
}
try {
// Callback wrapped in promise -- Chrome compatibility
const checkResult = await browser.runtime.sendMessage({pubGwUrlForIpfsOrIpnsPath: path})
const checkResult = await browser.runtime.sendMessage({ pubGwUrlForIpfsOrIpnsPath: path })
window.ipfsCompanionLinkifyValidationCache.set(path, checkResult.pubGwUrlForIpfsOrIpnsPath)
} catch (error) {
window.ipfsCompanionLinkifyValidationCache.set(path, null)
Expand Down
12 changes: 6 additions & 6 deletions add-on/src/lib/context-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function findUrlForContext (context) {
}
}
// falback to the url of current tab
const currentTab = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
const currentTab = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
return currentTab.url
}

Expand Down Expand Up @@ -87,15 +87,15 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddToIpfs
async update (changedTabId) {
try {
const canUpload = getState().peerCount > 0
await browser.contextMenus.update(contextMenuAddToIpfsRawCid, {enabled: canUpload})
await browser.contextMenus.update(contextMenuAddToIpfsKeepFilename, {enabled: canUpload})
await browser.contextMenus.update(contextMenuAddToIpfsRawCid, { enabled: canUpload })
await browser.contextMenus.update(contextMenuAddToIpfsKeepFilename, { enabled: canUpload })
if (changedTabId) {
// recalculate tab-dependant menu items
const currentTab = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
const currentTab = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
if (currentTab && currentTab.id === changedTabId) {
const ipfsContext = ipfsPathValidator.isIpfsPageActionsContext(currentTab.url)
browser.contextMenus.update(contextMenuCopyCanonicalAddress, {enabled: ipfsContext})
browser.contextMenus.update(contextMenuCopyAddressAtPublicGw, {enabled: ipfsContext})
browser.contextMenus.update(contextMenuCopyCanonicalAddress, { enabled: ipfsContext })
browser.contextMenus.update(contextMenuCopyAddressAtPublicGw, { enabled: ipfsContext })
}
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/lib/copier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { safeIpfsPath } = require('./ipfs-path')
const { findUrlForContext } = require('./context-menus')

async function copyTextToClipboard (copyText) {
const currentTab = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
const currentTab = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
const tabId = currentTab.id
// Lets take a moment and ponder on the state of copying a string in 2017:
const copyToClipboardIn2017 = `function copyToClipboardIn2017(text) {
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/lib/dnslink.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const { offlinePeerCount } = require('./state')

module.exports = function createDnslinkResolver (getState) {
// DNSLink lookup result cache
const cacheOptions = {max: 1000, maxAge: 1000 * 60 * 60 * 12}
const cacheOptions = { max: 1000, maxAge: 1000 * 60 * 60 * 12 }
const cache = new LRU(cacheOptions)
// upper bound for concurrent background lookups done by preloadDnslink(url)
const lookupQueue = new PQueue({concurrency: 8})
const lookupQueue = new PQueue({ concurrency: 8 })

const dnslinkResolver = {

Expand Down
2 changes: 1 addition & 1 deletion add-on/src/lib/ipfs-client/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.init = async function (opts) {
console.log('[ipfs-companion] External ipfs init', opts.apiURLString)

const url = opts.apiURL
const api = IpfsApi({host: url.hostname, port: url.port, procotol: url.protocol})
const api = IpfsApi({ host: url.hostname, port: url.port, procotol: url.protocol })
return api
}

Expand Down
38 changes: 19 additions & 19 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = async function init () {
ipfsPathValidator = createIpfsPathValidator(getState, dnslinkResolver)
contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, {
onAddToIpfsRawCid: addFromURL,
onAddToIpfsKeepFilename: (info) => addFromURL(info, {wrapWithDirectory: true}),
onAddToIpfsKeepFilename: (info) => addFromURL(info, { wrapWithDirectory: true }),
onCopyCanonicalAddress: () => copier.copyCanonicalAddress(),
onCopyAddressAtPublicGw: () => copier.copyAddressAtPublicGw()
})
Expand Down Expand Up @@ -90,10 +90,10 @@ module.exports = async function init () {
}

function registerListeners () {
browser.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: ['<all_urls>']}, ['blocking', 'requestHeaders'])
browser.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ['<all_urls>']}, ['blocking'])
browser.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ['<all_urls>']}, ['blocking', 'responseHeaders'])
browser.webRequest.onErrorOccurred.addListener(onErrorOccurred, {urls: ['<all_urls>']})
browser.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, { urls: ['<all_urls>'] }, ['blocking', 'requestHeaders'])
browser.webRequest.onBeforeRequest.addListener(onBeforeRequest, { urls: ['<all_urls>'] }, ['blocking'])
browser.webRequest.onHeadersReceived.addListener(onHeadersReceived, { urls: ['<all_urls>'] }, ['blocking', 'responseHeaders'])
browser.webRequest.onErrorOccurred.addListener(onErrorOccurred, { urls: ['<all_urls>'] })
browser.storage.onChanged.addListener(onStorageChange)
browser.webNavigation.onCommitted.addListener(onNavigationCommitted)
browser.tabs.onUpdated.addListener(onUpdatedTab)
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = async function init () {
const newHandle = await browser.contentScripts.register({
matches: ['<all_urls>'],
js: [
{file: '/dist/bundles/ipfsProxyContentScript.bundle.js'}
{ file: '/dist/bundles/ipfsProxyContentScript.bundle.js' }
],
allFrames: true,
runAt: 'document_start'
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = async function init () {
if (request.pubGwUrlForIpfsOrIpnsPath) {
const path = request.pubGwUrlForIpfsOrIpnsPath
const result = ipfsPathValidator.validIpfsOrIpnsPath(path) ? urlAtPublicGw(path, state.pubGwURLString) : null
return Promise.resolve({pubGwUrlForIpfsOrIpnsPath: result})
return Promise.resolve({ pubGwUrlForIpfsOrIpnsPath: result })
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ module.exports = async function init () {
peerCount: state.peerCount,
gwURLString: state.gwURLString,
pubGwURLString: state.pubGwURLString,
currentTab: await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
currentTab: await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
}
try {
let v = await ipfs.version()
Expand All @@ -222,7 +222,7 @@ module.exports = async function init () {
}
// Still here?
if (browserActionPort) {
browserActionPort.postMessage({statusUpdate: info})
browserActionPort.postMessage({ statusUpdate: info })
}
}

Expand Down Expand Up @@ -296,25 +296,25 @@ module.exports = async function init () {
return
}

return uploadResultHandler({result, openRootInNewTab: true})
return uploadResultHandler({ result, openRootInNewTab: true })
}

// TODO: feature detect and push to client type specific modules.
function getIpfsPathAndNativeAddress (hash) {
const path = `/ipfs/${hash}`
if (runtime.hasNativeProtocolHandler) {
return {path, url: `ipfs://${hash}`}
return { path, url: `ipfs://${hash}` }
} else {
// open at public GW (will be redirected to local elsewhere, if enabled)
const url = new URL(path, state.pubGwURLString).toString()
return {path, url: url}
return { path, url: url }
}
}

async function uploadResultHandler ({result, openRootInNewTab = false}) {
async function uploadResultHandler ({ result, openRootInNewTab = false }) {
for (let file of result) {
if (file && file.hash) {
const {path, url} = getIpfsPathAndNativeAddress(file.hash)
const { path, url } = getIpfsPathAndNativeAddress(file.hash)
preloadAtPublicGateway(path)
console.info('[ipfs-companion] successfully stored', file)
// open the wrapping directory (or the CID if wrapping was disabled)
Expand Down Expand Up @@ -472,16 +472,16 @@ module.exports = async function init () {
badgeIcon = '/icons/ipfs-logo-off.svg'
}
try {
await browser.browserAction.setBadgeBackgroundColor({color: badgeColor})
await browser.browserAction.setBadgeText({text: badgeText})
await browser.browserAction.setBadgeBackgroundColor({ color: badgeColor })
await browser.browserAction.setBadgeText({ text: badgeText })
await setBrowserActionIcon(badgeIcon)
} catch (error) {
console.error('Unable to update browserAction badge due to error', error)
}
}

async function setBrowserActionIcon (iconPath) {
let iconDefinition = {path: iconPath}
let iconDefinition = { path: iconPath }
try {
// Try SVG first -- Firefox supports it natively
await browser.browserAction.setIcon(iconDefinition)
Expand Down Expand Up @@ -534,10 +534,10 @@ module.exports = async function init () {
// TODO: use `node.isOnline()` if available (js-ipfs)
if (state.automaticMode && state.ipfsNodeType !== 'embedded') {
if (oldPeerCount === offlinePeerCount && newPeerCount > offlinePeerCount && !state.redirect) {
browser.storage.local.set({useCustomGateway: true})
browser.storage.local.set({ useCustomGateway: true })
.then(() => notify('notify_apiOnlineTitle', 'notify_apiOnlineAutomaticModeMsg'))
} else if (newPeerCount === offlinePeerCount && state.redirect) {
browser.storage.local.set({useCustomGateway: false})
browser.storage.local.set({ useCustomGateway: false })
.then(() => notify('notify_apiOfflineTitle', 'notify_apiOfflineAutomaticModeMsg'))
}
}
Expand Down
8 changes: 4 additions & 4 deletions add-on/src/lib/ipfs-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ exports.createIpfsUrlProtocolHandler = (getIpfs) => {
const ipfs = getIpfs()

try {
const {data, mimeType, charset} = await getDataAndGuessMimeType(ipfs, path)
const { data, mimeType, charset } = await getDataAndGuessMimeType(ipfs, path)
console.log(`[ipfs-companion] returning ${path} as mime ${mimeType} and charset ${charset}`)
reply({mimeType, data, charset})
reply({ mimeType, data, charset })
} catch (err) {
console.error('[ipfs-companion] failed to get data', err)
reply({mimeType: 'text/html', data: `Error ${err.message}`})
reply({ mimeType: 'text/html', data: `Error ${err.message}` })
}

console.timeEnd('[ipfs-companion] IpfsUrlProtocolHandler')
Expand All @@ -38,7 +38,7 @@ async function getDataAndGuessMimeType (ipfs, path) {
}

const mimeType = mimeSniff(data, path) || 'text/plain'
return {mimeType, data: data.toString('utf8'), charset: 'utf8'}
return { mimeType, data: data.toString('utf8'), charset: 'utf8' }
}

async function getDirectoryListingOrIndexData (ipfs, path) {
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/lib/ipfs-proxy/request-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function createRequestAccess (browser, screen) {
} else {
// fallback: opening dialog as a new active tab
// (runtimes without browser.windows.create, eg. Andorid)
dialogTabId = (await browser.tabs.create({active: true, url: url})).id
dialogTabId = (await browser.tabs.create({ active: true, url: url })).id
}

// Resolves with { allow, wildcard }
Expand Down
8 changes: 4 additions & 4 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const { urlAtPublicGw } = require('./ipfs-path')
const redirectOptOutHint = 'x-ipfs-companion-no-redirect'
const recoverableErrors = new Set([
// Firefox
'NS_ERROR_NET_TIMEOUT', // eg. httpd is offline
'NS_ERROR_NET_RESET', // failed to load because the server kept reseting the connection
'NS_ERROR_NET_ON_RESOLVED', // no network
'NS_ERROR_NET_TIMEOUT', // eg. httpd is offline
'NS_ERROR_NET_RESET', // failed to load because the server kept reseting the connection
'NS_ERROR_NET_ON_RESOLVED', // no network
// Chrome
'net::ERR_CONNECTION_TIMED_OUT', // eg. httpd is offline
'net::ERR_INTERNET_DISCONNECTED' // no network
Expand Down Expand Up @@ -195,7 +195,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
// TODO: add tests and demo
if (dnslinkRedirect) {
console.log(`[ipfs-companion] onErrorOccurred: recovering using dnslink for ${request.url}`, dnslinkRedirect)
const currentTabId = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0].id)
const currentTabId = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0].id)
await browser.tabs.create({
active: true,
openerTabId: currentTabId,
Expand Down
74 changes: 37 additions & 37 deletions add-on/src/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,48 @@ module.exports = function optionsPage (state, emit) {
// when global toggle is in "suspended" state
return html`
<div class="sans-serif">
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
</div>
`
}
return html`
<div class="sans-serif">
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
${ipfsNodeForm({
ipfsNodeType: state.options.ipfsNodeType,
ipfsNodeConfig: state.options.ipfsNodeConfig,
onOptionChange
})}
${gatewaysForm({
ipfsNodeType: state.options.ipfsNodeType,
customGatewayUrl: state.options.customGatewayUrl,
useCustomGateway: state.options.useCustomGateway,
publicGatewayUrl: state.options.publicGatewayUrl,
onOptionChange
})}
${state.options.ipfsNodeType === 'external' ? apiForm({
ipfsApiUrl: state.options.ipfsApiUrl,
ipfsApiPollMs: state.options.ipfsApiPollMs,
automaticMode: state.options.automaticMode,
onOptionChange
}) : null}
${experimentsForm({
displayNotifications: state.options.displayNotifications,
preloadAtPublicGateway: state.options.preloadAtPublicGateway,
catchUnhandledProtocols: state.options.catchUnhandledProtocols,
linkify: state.options.linkify,
dnslinkPolicy: state.options.dnslinkPolicy,
detectIpfsPathHeader: state.options.detectIpfsPathHeader,
ipfsProxy: state.options.ipfsProxy,
onOptionChange,
onOptionsReset
})}
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
${ipfsNodeForm({
ipfsNodeType: state.options.ipfsNodeType,
ipfsNodeConfig: state.options.ipfsNodeConfig,
onOptionChange
})}
${gatewaysForm({
ipfsNodeType: state.options.ipfsNodeType,
customGatewayUrl: state.options.customGatewayUrl,
useCustomGateway: state.options.useCustomGateway,
publicGatewayUrl: state.options.publicGatewayUrl,
onOptionChange
})}
${state.options.ipfsNodeType === 'external' ? apiForm({
ipfsApiUrl: state.options.ipfsApiUrl,
ipfsApiPollMs: state.options.ipfsApiPollMs,
automaticMode: state.options.automaticMode,
onOptionChange
}) : null}
${experimentsForm({
displayNotifications: state.options.displayNotifications,
preloadAtPublicGateway: state.options.preloadAtPublicGateway,
catchUnhandledProtocols: state.options.catchUnhandledProtocols,
linkify: state.options.linkify,
dnslinkPolicy: state.options.dnslinkPolicy,
detectIpfsPathHeader: state.options.detectIpfsPathHeader,
ipfsProxy: state.options.ipfsProxy,
onOptionChange,
onOptionsReset
})}
</div>
`
}
Loading

0 comments on commit 53cfa83

Please sign in to comment.