Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Sep 8, 2022
1 parent 93f46ac commit 6eda4ca
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 50 deletions.
7 changes: 3 additions & 4 deletions src/main/core/ipfs/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions src/main/core/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand All @@ -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)
}
Expand All @@ -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..')
Expand All @@ -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) => {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/render/core/app/components/Input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Input = (props) => {
}

return (
<InputWrapper className={'input-wrapper'}>
<InputWrapper className='input-wrapper'>
{props.icon && <InputIcon className={props.icon} />}
<InputElement
value={value}
Expand Down
41 changes: 19 additions & 22 deletions src/render/core/app/components/Login/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global FormData */
import React, { useState, useCallback } from 'react'
import styled from 'styled-components'
import Alert from '@components/Alert/'
Expand All @@ -12,28 +11,25 @@ const pb = process.env.WATCHIT_PUBLIC_KEY
const runtime = process.env.RUNTIME
const isWeb = runtime === 'web'


const LoginForm = () => {
const [submitted, setSubmitted] = useState(false)
const [error, setError] = useState(false)
const [ingest, setValue] = useState('')
const [node, setNode] = useState('')
const [showLocalNode, setShowLocalNode] = useState(false)


const handleSubmit = useCallback((e) => {
// Avoid trigger default event
e.preventDefault()
// Set first state
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)) {
Expand Down Expand Up @@ -70,16 +66,17 @@ const LoginForm = () => {
<span>Connect</span>
</Button>
</LoginButtonContainer>
<SmallButtonContainer size={isWeb ? "50%" : null} onClick={() => setValue(pb)}>
<SmallButtonContainer size={isWeb ? '50%' : null} onClick={() => setValue(pb)}>
<Button clicked={submitted} type='button'>
<span>Last Key</span>
</Button>
</SmallButtonContainer>
{
!isWeb ?
{!isWeb
? (
<SmallButtonContainer>
{
showLocalNode ? (
showLocalNode
? (
<>
<Input
placeholder='Port'
Expand All @@ -88,31 +85,32 @@ const LoginForm = () => {
value={node}
onChange={(e) => setNode(e.target.value)}
/>
<div className={'cancel-button'} onClick={() => setShowLocalNode(false)}>
<div className='cancel-button' onClick={() => setShowLocalNode(false)}>
<i className='icon-cross white-text' />
</div>
</>
) : (
)
: (
<div onClick={() => setShowLocalNode(true)}>
<Button clicked={submitted} type='button'>
<span>Local Node</span>
</Button>
</div>
)
}
)
}
</SmallButtonContainer>
: <></>
}
)
: <></>}
</ButtonsContainer>
</FormRow>

{
error &&
<FormRow>
<Alert color={setting.styles.colors.danger}>
{error}
</Alert>
</FormRow>
<FormRow>
<Alert color={setting.styles.colors.danger}>
{error}
</Alert>
</FormRow>
}
</form>
</FormWrapper>
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -203,5 +201,4 @@ const SmallButtonContainer = styled.div`
}
`


export default React.memo(LoginForm)
7 changes: 4 additions & 3 deletions src/render/core/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ 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) => {
o[i] = k[index]
return o
}, {})
},
get available() {
get available () {
return Object.keys(this.hash)
}
},
Expand Down

0 comments on commit 6eda4ca

Please sign in to comment.