-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathprotocol.ts
More file actions
143 lines (119 loc) · 2.89 KB
/
protocol.ts
File metadata and controls
143 lines (119 loc) · 2.89 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import type { CID } from 'multiformats/cid'
import { Perform, Spawn } from "../task"
export type { Perform, Spawn }
type Pin = {
cid: CID
}
type Model = {
pageContent: null | PageContent
pins: string[]
sorting: Sorting
mfsSize: number
pending: PendingJob<any, any>[]
finished: FinishedJob<any>[]
failed: FailedJob[]
}
interface JobInfo {
type: Message['type']
id: Symbol
start: number
}
interface PendingJob<M, I> extends JobInfo {
status: 'Pending'
init: I
message?: M
}
interface FailedJob extends JobInfo {
status: 'Failed'
error: Error
end: number
}
interface FinishedJob<T> extends JobInfo {
status: 'Done'
value: T
end: number
}
type Sorting = {
by: SortBy,
asc: boolean
}
type SortBy = 'name' | 'size'
type Message =
| { type: 'FILES_CLEAR_ALL' }
| { type: 'FILES_DISMISS_ERRORS' }
| { type: 'FILES_UPDATE_SORT', payload: Sorting }
| Perform<'FILES_FETCH', Error, PageContent, void>
| MakeDir
| Delete
| Move
| Write
| AddByPath
| BulkCidImport
| DownloadLink
| Perform<'FILES_SHARE_LINK', Error, string, void>
| Perform<'FILES_COPY', Error, void, void>
| Perform<'FILES_PIN_ADD', Error, Pin[], void>
| Perform<'FILES_PIN_REMOVE', Error, Pin[], void>
| Perform<'FILES_PIN_LIST', Error, { pins: CID[] }, void>
| Perform<'FILES_SIZE_GET', Error, { size: number }, void>
| Perform<'FILES_PINS_SIZE_GET', Error, { pinsSize: number, numberOfPins: number }, void>
type MakeDir = Perform<'FILES_MAKEDIR', Error, void, void>
type WriteProgress = { paths: string[], progress: number }
type Write = Spawn<'FILES_WRITE', WriteProgress, Error, void, void>
type AddByPath = Perform<'FILES_ADDBYPATH', Error, void, void>
type BulkCidImport = Perform<'FILES_BULK_CID_IMPORT', Error, void, void>
type Move = Perform<'FILES_MOVE', Error, void, void>
type Delete = Perform<'FILES_DELETE', Error, void, void>
type DownloadLink = Perform<'FILES_DOWNLOADLINK', Error, FileDownload, void>
type FileDownload = {
url: string
filename: string
}
type FileType = 'directory' | 'file' | 'unknown'
type Time = number
type FileStat = {
size: number,
type: FileType,
cid: CID,
name: string,
path: string,
pinned: boolean
isParent: boolean | void
}
type PageContent =
| UnknownContent
| FileContent
| DirectoryContent
type UnknownContent = {
type: 'unknown',
fetched: Time,
path: string,
cid: CID,
size: 0
}
type FileContent = {
type: 'file',
fetched: Time,
path: string,
cid: CID,
size: number,
name: string,
pinned: boolean
}
type DirectoryContent = {
type: 'directory',
fetched: Time,
path: string,
cid: CID,
content: FileStat[]
upper: void | FileStat,
}
type Job<K, P, X, T> = {
type: K,
job: JobState<P, X, T>
}
type JobState<P, X, T> =
| { status: 'Idle', id: Symbol }
| { status: 'Active', id: Symbol, state: P }
| { status: 'Failed', id: Symbol, error: X }
| { status: 'Done', id: Symbol, value: T }