This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
/
getCustomIpfsApi.js
67 lines (60 loc) · 1.81 KB
/
getCustomIpfsApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { call, put } from 'redux-saga/effects'
import { eventChannel } from 'redux-saga'
import { ipcRenderer } from 'electron'
import { IS_OFFLINE } from '#config'
import {
IPC_IPFS_SHARE_OBJECT,
IPC_IPFS_SHARE_FS_FILE,
IPC_IPFS_CACHE_CIDS,
IPC_IPFS_GET_INFO,
IPC_IPFS_CID_CACHE_FAILED,
IPC_IPFS_CID_CACHE_SUCCEED,
IPC_IPFS_OPEN_CACHED_CIDS_STREAM,
IPC_IPFS_GET_STATS
} from '~data/ipcTypes'
import { rendererCalls } from '~utils/ipcRenderer'
import { systemIpfsInfoRecieved } from '~actions/system'
function * getCustomIpfsApi () {
const ipfsInfo = yield call(rendererCalls, IPC_IPFS_GET_INFO)
yield put(systemIpfsInfoRecieved({
...ipfsInfo,
isOffline: IS_OFFLINE
}))
const shareObjectToIpfs = obj => {
return rendererCalls(IPC_IPFS_SHARE_OBJECT, obj)
}
const shareFsFileToIpfs = filePath => {
return rendererCalls(IPC_IPFS_SHARE_FS_FILE, filePath)
}
const cacheIPFSFilesByCIDs = cids => {
return rendererCalls(IPC_IPFS_CACHE_CIDS, cids)
}
const openCachedIPFSFilesStream = () => {
return rendererCalls(IPC_IPFS_OPEN_CACHED_CIDS_STREAM)
}
const getCachedIPFSFilesChannel = () => {
return eventChannel(emit => {
const handleMessage = (e, arg) => {
emit(arg)
}
ipcRenderer.on(IPC_IPFS_CID_CACHE_SUCCEED, handleMessage)
ipcRenderer.on(IPC_IPFS_CID_CACHE_FAILED, handleMessage)
return () => {
ipcRenderer.removeListener(IPC_IPFS_CID_CACHE_SUCCEED, handleMessage)
ipcRenderer.removeListener(IPC_IPFS_CID_CACHE_FAILED, handleMessage)
}
})
}
const getIPFSStats = () => {
return rendererCalls(IPC_IPFS_GET_STATS)
}
return {
shareFsFileToIpfs,
shareObjectToIpfs,
cacheIPFSFilesByCIDs,
openCachedIPFSFilesStream,
getCachedIPFSFilesChannel,
getIPFSStats
}
}
export default getCustomIpfsApi