Skip to content

Commit

Permalink
New eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EmiM committed Jun 19, 2023
1 parent f8d1b38 commit 80783cd
Show file tree
Hide file tree
Showing 596 changed files with 9,064 additions and 10,177 deletions.
4 changes: 3 additions & 1 deletion packages/backend/classic_level.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ if (!exists && process.platform === 'android') {
}

if (!exists) {
throw new Error(`Unfortunately we do not support this platform! There is no classic_level bindings binary for ${process.platform}-${process.arch}`)
throw new Error(
`Unfortunately we do not support this platform! There is no classic_level bindings binary for ${process.platform}-${process.arch}`
)
}

bindings = require(binaryPath)
Expand Down
42 changes: 22 additions & 20 deletions packages/backend/src/backendManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const log = logger('backendManager')
const program = new Command()

program
.option('-p, --platform <platform>', 'platform')
.option('-dpth, --dataPath <dataPath>', 'data directory path')
.option('-dprt, --dataPort <dataPort>', 'data port')
.option('-t, --torBinary <torBinary>', 'tor binary path')
.option('-ac, --authCookie <authCookie>', 'tor authentication cookie')
.option('-cp, --controlPort <controlPort>', 'tor control port')
.option('-htp, --httpTunnelPort <httpTunnelPort>', 'http tunnel port')
.option('-a, --appDataPath <string>', 'Path of application data directory')
.option('-d, --socketIOPort <number>', 'Socket io data server port')
.option('-r, --resourcesPath <string>', 'Application resources path')
.option('-p, --platform <platform>', 'platform')
.option('-dpth, --dataPath <dataPath>', 'data directory path')
.option('-dprt, --dataPort <dataPort>', 'data port')
.option('-t, --torBinary <torBinary>', 'tor binary path')
.option('-ac, --authCookie <authCookie>', 'tor authentication cookie')
.option('-cp, --controlPort <controlPort>', 'tor control port')
.option('-htp, --httpTunnelPort <httpTunnelPort>', 'http tunnel port')
.option('-a, --appDataPath <string>', 'Path of application data directory')
.option('-d, --socketIOPort <number>', 'Socket io data server port')
.option('-r, --resourcesPath <string>', 'Application resources path')

program.parse(process.argv)
const options = program.opts()
Expand All @@ -40,12 +40,12 @@ export const runBackendDesktop = async () => {
torResourcesPath: torDirForPlatform(resourcesPath),
options: {
env: {
appDataPath: path.join(options.appDataPath.trim(), 'Quiet')
}
}
appDataPath: path.join(options.appDataPath.trim(), 'Quiet'),
},
},
})

process.on('message', async (message) => {
process.on('message', async message => {
if (message === 'close') {
try {
await connectionsManager.closeAllServices()
Expand Down Expand Up @@ -80,10 +80,10 @@ export const runBackendMobile = async (): Promise<any> => {
torBinaryPath: options.torBinary ? options.torBinary : null,
options: {
env: {
appDataPath: options.dataPath
appDataPath: options.dataPath,
},
createPaths: false
}
createPaths: false,
},
})

await connectionsManager.init()
Expand All @@ -97,11 +97,13 @@ if (platform === 'desktop') {
throw error
})
} else if (platform === 'mobile') {
runBackendMobile().catch(async (error) => {
runBackendMobile().catch(async error => {
log.error('Error occurred while initializing backend', error)
// Prevent stopping process before getting output
await new Promise<void>((resolve) => {
setTimeout(() => { resolve() }, 10000)
await new Promise<void>(resolve => {
setTimeout(() => {
resolve()
}, 10000)
})
throw error
})
Expand Down
23 changes: 14 additions & 9 deletions packages/backend/src/common/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getPorts,
type Ports,
torBinForPlatform,
torDirForPlatform
torDirForPlatform,
} from './utils'
import crypto from 'crypto'
import logger from '../logger'
Expand All @@ -27,16 +27,21 @@ export const rootPermsData: PermsData = {
certificate:
'MIIBNjCB3AIBATAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMCYYEzIwMjEwNjIyMDkzMDEwLjAyNVoYDzIwMzAwMTMxMjMwMDAwWjASMRAwDgYDVQQDEwdaYmF5IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV5a3Czy+L7IfVX0FpJtSF5mi0GWGrtPqv5+CFSDPrHXijsxWdPTobR1wk8uCLP4sAgUbs/bIleCxQy41kSSyOaMgMB4wDwYDVR0TBAgwBgEB/wIBAzALBgNVHQ8EBAMCAAYwCgYIKoZIzj0EAwIDSQAwRgIhAPOzksuipKyBALt/o8O/XwsrVSzfSHXdAR4dOWThQ1lbAiEAmKqjhsmf50kxWX0ekhbAeCTjcRApXhjnslmJkIFGF2o=+lmBImw3BMNjA0FTlK5iRmVC+w/T6M04Es+yiYL608vOhx2slnoyAwHjAPBgNVHRMECDAGAQH/AgEDMAsGA1UdDwQEAwIABjAKBggqhkjOPQQDAgNIADBFAiEA+0kIz0ny/PLVERTcL0+KCpsztyA6Zuwzj05VW5NMdx0CICgdzf0lg0/2Ksl1AjSPYsy2w+Hn09PGlBnD7TiExBpx',
privKey:
'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgTvNuJL0blaYq6zmFS53WmmOfHshlqn+8wNHDzo4df5WgCgYIKoZIzj0DAQehRANCAARXlrcLPL4vsh9VfQWkm1IXmaLQZYau0+q/n4IVIM+sdeKOzFZ09OhtHXCTy4Is/iwCBRuz9siV4LFDLjWRJLI5+lmBImw3BMNjA0FTlK5iRmVC+w/T6M04Es+yiYL608vOhx2sln'
'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgTvNuJL0blaYq6zmFS53WmmOfHshlqn+8wNHDzo4df5WgCgYIKoZIzj0DAQehRANCAARXlrcLPL4vsh9VfQWkm1IXmaLQZYau0+q/n4IVIM+sdeKOzFZ09OhtHXCTy4Is/iwCBRuz9siV4LFDLjWRJLI5+lmBImw3BMNjA0FTlK5iRmVC+w/T6M04Es+yiYL608vOhx2sln',
}

tmp.setGracefulCleanup()

export const testBootstrapMultiaddrs = [
createLibp2pAddress('abcd.onion', 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4')
createLibp2pAddress('abcd.onion', 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4'),
]

export const spawnTorProcess = async (quietDirPath: string, ports?: Ports, extraTorProcessParams?: TorParams, binName?: string): Promise<Tor> => {
export const spawnTorProcess = async (
quietDirPath: string,
ports?: Ports,
extraTorProcessParams?: TorParams,
binName?: string
): Promise<Tor> => {
const _ports = ports || (await getPorts())
const torPath = torBinForPlatform(undefined, binName)
const libPath = torDirForPlatform()
Expand All @@ -47,11 +52,11 @@ export const spawnTorProcess = async (quietDirPath: string, ports?: Ports, extra
options: {
env: {
LD_LIBRARY_PATH: libPath,
HOME: quietDirPath
HOME: quietDirPath,
},
detached: true
detached: true,
},
extraTorProcessParams
extraTorProcessParams,
})
return tor
}
Expand All @@ -69,11 +74,11 @@ export const createLibp2p = async (peerId: PeerId): Promise<Libp2p> => {
cert: pems.userCert,
key: pems.userKey,
ca: [pems.ca],
targetPort: port
targetPort: port,
})
}

export const createTmpDir = (prefix: string = 'quietTestTmp_'): tmp.DirResult => {
export const createTmpDir = (prefix = 'quietTestTmp_'): tmp.DirResult => {
return tmp.dirSync({ mode: 0o750, prefix, unsafeCleanup: true })
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ChannelInfoResponse = Record<string, PublicChannel>
export class StorageOptions {
orbitDbDir?: string
ipfsDir?: string
createPaths: boolean = true
createPaths = true
}

export interface IPublicKey {
Expand Down
42 changes: 25 additions & 17 deletions packages/backend/src/common/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import mock from 'mock-fs'
import path from 'path'
import { beforeEach, describe, it, expect, afterEach } from '@jest/globals'
const { getFilesRecursively, removeFiles, getDirsRecursively, removeDirs, compare, getUsersAddresses, createLibp2pAddress } = await import ('./utils')
const {
getFilesRecursively,
removeFiles,
getDirsRecursively,
removeDirs,
compare,
getUsersAddresses,
createLibp2pAddress,
} = await import('./utils')

beforeEach(() => {
mock({
Quiet: {
'some-file.txt': 'file content here',
IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn: {
pins: {
LOCK: 'some data'
LOCK: 'some data',
},
'repo.lock': {}
'repo.lock': {},
},
OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn: {
LOCK: 'some data'
}
LOCK: 'some data',
},
},
'some/empty/dir': {}
'some/empty/dir': {},
})
})

Expand All @@ -33,7 +41,7 @@ describe('Get files and dirs', () => {
expect(arr).toEqual([
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/pins/LOCK',
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/LOCK',
'Quiet/some-file.txt'
'Quiet/some-file.txt',
])
})

Expand All @@ -45,7 +53,7 @@ describe('Get files and dirs', () => {
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/pins',
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/repo.lock',
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn'
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
])
})

Expand All @@ -64,15 +72,13 @@ describe('Remove files and dirs', () => {
expect(arr).toEqual([
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/pins/LOCK',
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/LOCK',
'Quiet/some-file.txt'
'Quiet/some-file.txt',
])
removeFiles('Quiet', 'LOCK')
arr = []
getFilesRecursively('Quiet', arr)
arr = arr.map(e => e.split(path.sep).join(path.posix.sep))
expect(arr).toEqual([
'Quiet/some-file.txt'
])
expect(arr).toEqual(['Quiet/some-file.txt'])
})

it('Remove directories by name', () => {
Expand All @@ -83,7 +89,7 @@ describe('Remove files and dirs', () => {
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/pins',
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/repo.lock',
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn'
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
])
removeDirs('Quiet', 'repo.lock')
arr = []
Expand All @@ -92,11 +98,13 @@ describe('Remove files and dirs', () => {
expect(arr).toEqual([
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
'Quiet/IpfsQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn/pins',
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn'
'Quiet/OrbitDBQmQ18tV1dfGsEH8sCnbnzaYpMpb1QyCEjJ2KW96YtZ2MUn',
])
})
it("No error if directory doesn't exist", () => {
expect(() => { removeFiles('LOCK', 'non/existent/dir') }).not.toThrow()
expect(() => {
removeFiles('LOCK', 'non/existent/dir')
}).not.toThrow()
})
})

Expand All @@ -120,11 +128,11 @@ describe('Compare actual and reported file size', () => {
it('Gets users addresses based on user data', async () => {
const userData = [
{ onionAddress: '12345.onion', peerId: '54321', dmPublicKey: '324530833893', username: 'Bob' },
{ onionAddress: '67890.onion', peerId: '09876', dmPublicKey: '098830987898', username: 'Alice' }
{ onionAddress: '67890.onion', peerId: '09876', dmPublicKey: '098830987898', username: 'Alice' },
]
const addresses = await getUsersAddresses(userData)
expect(addresses).toStrictEqual([
createLibp2pAddress(userData[0].onionAddress, userData[0].peerId),
createLibp2pAddress(userData[1].onionAddress, userData[1].peerId)
createLibp2pAddress(userData[1].onionAddress, userData[1].peerId),
])
})
10 changes: 5 additions & 5 deletions packages/backend/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const removeFiles = (appPath: string, filename: string) => {
if (!fs.existsSync(appPath)) return
const IpfsAndOrbitDb = fs.readdirSync(appPath).filter(i => i.startsWith('Ipfs') || i.startsWith('OrbitDB'))
const files: string[] = []
IpfsAndOrbitDb.forEach((e) => {
IpfsAndOrbitDb.forEach(e => {
const directory = path.resolve(appPath, e)
getFilesRecursively(directory, files)
})
Expand All @@ -74,7 +74,7 @@ export const removeDirs = (appPath: string, filename: string) => {
if (!fs.existsSync(appPath)) return
const IpfsAndOrbitDb = fs.readdirSync(appPath).filter(i => i.startsWith('Ipfs'))
const dirs: string[] = []
IpfsAndOrbitDb.forEach((e) => {
IpfsAndOrbitDb.forEach(e => {
const directory = path.resolve(appPath, e)
getDirsRecursively(directory, dirs)
})
Expand All @@ -96,7 +96,7 @@ export const getPorts = async (): Promise<Ports> => {
libp2pHiddenService,
controlPort,
dataServer,
httpTunnelPort
httpTunnelPort,
}
}

Expand All @@ -111,7 +111,7 @@ export class DummyIOServer extends Server {
}
}

export const torBinForPlatform = (basePath: string = '', binName: string = 'tor'): string => {
export const torBinForPlatform = (basePath = '', binName = 'tor'): string => {
if (process.env.BACKEND === 'mobile') {
return basePath
}
Expand Down Expand Up @@ -156,7 +156,7 @@ export const getUsersAddresses = async (users: User[]): Promise<string[]> => {
*
* @param tolerance In percentage (0.0 - 1.0)
*/
export const compare = (given: number, base: number, tolerance: number = 0) => {
export const compare = (given: number, base: number, tolerance = 0) => {
const margin = base * tolerance
const min = base - margin
const max = base + margin
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export enum Config {
QUIET_DIR = '.quiet',
PEER_ID_FILENAME = 'peerIdKey',
ORBIT_DB_DIR = 'OrbitDB',
IPFS_REPO_PATH = 'QuietChannels'
IPFS_REPO_PATH = 'QuietChannels',
}

export const QUIET_DIR_PATH = path.join(os.homedir(), Config.QUIET_DIR)
2 changes: 1 addition & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
Tor,
DataServer,
ConnectionsManager,
version
version,
}

export * from './common/utils'
Loading

0 comments on commit 80783cd

Please sign in to comment.