diff --git a/src/main/core/ipfs/node/index.js b/src/main/core/ipfs/node/index.js index 2908dc210..3591cf4c0 100644 --- a/src/main/core/ipfs/node/index.js +++ b/src/main/core/ipfs/node/index.js @@ -18,14 +18,14 @@ const KILL_TIMEOUT = 15 * 1000 const DEFAULT_SWARM_TCP = 4010 const DEFAULT_SWARM_WS = 4011 const resolveIpfsPaths = () => require('go-ipfs').path() - .replace('app.asar', 'app.asar.unpacked'); + .replace('app.asar', 'app.asar.unpacked') const forceKill = async (isInstance) => { log.info('Forcing stop') await isInstance.stop() log.warn('Cleaning bad repo') await removeFiles(ROOT_IPFS_DIR) -}; +} const initIpfsNode = async (isInstance) => { // Check if running time dir exists @@ -38,10 +38,9 @@ const initIpfsNode = async (isInstance) => { } return isInstance.start() -}; +} const ipfsFactory = async (conf = {}) => { - // Link to current local node if ('node' in conf) { log.info('Using provided node on port:', conf.node) diff --git a/src/main/core/node.js b/src/main/core/node.js index e0a1a7c05..c5bc7cf83 100644 --- a/src/main/core/node.js +++ b/src/main/core/node.js @@ -13,7 +13,7 @@ const log = require('logplease') const DEFAULT_HOLD = 10 * 1000 module.exports = class Node extends EventEmitter { - constructor(conf = {}) { + constructor (conf = {}) { super() this.conf = conf this.seedMode = false @@ -25,11 +25,11 @@ module.exports = class Node extends EventEmitter { this.db = null // Current opened db } - get [Symbol.toStringTag]() { + get [Symbol.toStringTag] () { return 'Node' } - static getInstance(conf) { + static getInstance (conf) { return new Node(conf) } @@ -40,7 +40,7 @@ module.exports = class Node extends EventEmitter { * @param {*} [settings={}] * @return {*} */ - open(address, settings = {}) { + open (address, settings = {}) { return this.orbit.open(address, { ...{ replicate: true, @@ -58,30 +58,30 @@ module.exports = class Node extends EventEmitter { * * @param {boolean} [isRunningSeed=false] */ - setInSeedMode(isRunningSeed = false) { + setInSeedMode (isRunningSeed = false) { this.seedMode = isRunningSeed } - async getIngestKey() { + async getIngestKey () { return this.resolveKey( this.rawIngestKey ) } - sanitizeKey(address) { + sanitizeKey (address) { return key.sanitizedKey(address) } - get rawIngestKey() { + get rawIngestKey () { return key.getIngestKey() } - get hasValidCache() { + get hasValidCache () { const [validCache] = this.cache return validCache } - get cache() { + get cache () { const cache = key.readFromStorage() const validCache = cache && 'tmp' in cache return [validCache, cache] @@ -104,7 +104,7 @@ module.exports = class Node extends EventEmitter { * @param ipns {string} IPNS hash * @return {string} Orbit address resolver key from ipns */ - async resolveKey(ipns) { + async resolveKey (ipns) { if (!ipns) return false if (~ipns.indexOf('zd')) return ipns @@ -129,7 +129,7 @@ module.exports = class Node extends EventEmitter { * @param key: orbit address * @param res: callback */ - async run(key, res) { + async run (key, res) { log.info('Starting movies db:', key) this.db = await this.open(key).catch(async (e) => { console.log(e) @@ -165,13 +165,13 @@ module.exports = class Node extends EventEmitter { /** * Kill all - party all */ - async party(msg = 'Invalid Key') { + async party (msg = 'Invalid Key') { log.warn('Party rock') this.emit('node-chaos', msg) await this.close(true) } - get pubsub() { + get pubsub () { if (!this.orbit) return {} return this.orbit._pubsub } @@ -182,7 +182,7 @@ module.exports = class Node extends EventEmitter { * and get providers for db * @param res: callback */ - async nodeReady(res) { + async nodeReady (res) { log.info('Node ready') log.info('Loading db..') const raw = await this.getIngestKey() @@ -202,7 +202,7 @@ module.exports = class Node extends EventEmitter { /** * Orbit db factory */ - instanceOB() { + instanceOB () { return (this.orbit && Promise.resolve(this.orbit)) || OrbitDB.createInstance(this.node, this.conf.orbit) } @@ -212,7 +212,7 @@ module.exports = class Node extends EventEmitter { * try keep node alive if cannot do it after MAX_RETRIES * app get killed :( */ - instanceNode() { + instanceNode () { return new Promise(async (resolve) => { // If fail to much.. get fuck out log.info('Setting up node..') @@ -226,7 +226,7 @@ module.exports = class Node extends EventEmitter { }) } - start() { + start () { this.closed = false // Restore closed state if (this.ready) return Promise.resolve(this.db) return new Promise(async (resolve) => { @@ -237,7 +237,7 @@ module.exports = class Node extends EventEmitter { }) } - async close(forceDrop = false) { + async close (forceDrop = false) { // Keep this states on top to avoid // run any event while nodes get closed this.closed = true // Closed already @@ -276,7 +276,7 @@ module.exports = class Node extends EventEmitter { this.peers.clear() } - async get(hash) { + async get (hash) { const oplog = (this.db.oplog || this.db._oplog) const result = oplog.values.find(v => v.hash === hash) if (!result || !hash) return false diff --git a/src/render/core/app/components/Input/index.jsx b/src/render/core/app/components/Input/index.jsx index 27e4bfeea..defae7f9e 100644 --- a/src/render/core/app/components/Input/index.jsx +++ b/src/render/core/app/components/Input/index.jsx @@ -63,7 +63,7 @@ const Input = (props) => { } return ( - + {props.icon && } { const [submitted, setSubmitted] = useState(false) const [error, setError] = useState(false) @@ -20,7 +18,6 @@ const LoginForm = () => { const [node, setNode] = useState('') const [showLocalNode, setShowLocalNode] = useState(false) - const handleSubmit = useCallback((e) => { // Avoid trigger default event e.preventDefault() @@ -28,12 +25,11 @@ const LoginForm = () => { setError(false) setSubmitted(true) - let dataToStore = { + const dataToStore = { ...node && { node }, ...{ ingest } } - // This validation should be skip because we can use orbit or ipns address // Check if stored key its valid // if (!key.isValidKey(pb)) { @@ -70,16 +66,17 @@ const LoginForm = () => { Connect - setValue(pb)}> + setValue(pb)}> - { - !isWeb ? + {!isWeb + ? ( { - showLocalNode ? ( + showLocalNode + ? ( <> { value={node} onChange={(e) => setNode(e.target.value)} /> -
setShowLocalNode(false)}> +
setShowLocalNode(false)}>
- ) : ( + ) + : (
setShowLocalNode(true)}>
- ) - } + ) + } - : <> - } + ) + : <>} { error && - - - {error} - - + + + {error} + + } @@ -175,7 +173,7 @@ const LoginButtonContainer = styled.div` ` const SmallButtonContainer = styled.div` - width: ${props => `calc(${props.size ? props.size : "25%"} - 0.5rem)`}; + width: ${props => `calc(${props.size ? props.size : '25%'} - 0.5rem)`}; position: relative; .input-wrapper { @@ -203,5 +201,4 @@ const SmallButtonContainer = styled.div` } ` - export default React.memo(LoginForm) diff --git a/src/render/core/settings.js b/src/render/core/settings.js index ecc3d9651..443075840 100755 --- a/src/render/core/settings.js +++ b/src/render/core/settings.js @@ -13,14 +13,15 @@ export default { 'https://gateway.ipfs.io', 'https://ipfs.io', ...process.env.RUNTIME !== 'web' - ? [`http://localhost:8080`] : [] + ? ['http://localhost:8080'] + : [] ], subs: { hash: { spanish: 'es', english: 'en' }, - get revHash() { + get revHash () { const v = Object.values(this.hash) const k = Object.keys(this.hash) return v.reduce((o, i, index) => { @@ -28,7 +29,7 @@ export default { return o }, {}) }, - get available() { + get available () { return Object.keys(this.hash) } },