Skip to content

Commit 015a4a0

Browse files
committed
refactoring transfer module
1 parent 789b74b commit 015a4a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2594
-3238
lines changed

src/common/const/qiniu.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/common/ipc-actions/common.ts

Whitespace-only changes.

src/common/ipc-actions/download.ts

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
import {IpcRenderer} from "electron";
2+
import {NatureLanguage} from "kodo-s3-adapter-sdk/dist/uplog";
3+
import {Domain} from "kodo-s3-adapter-sdk/dist/adapter";
4+
5+
import {ClientOptions} from "@common/qiniu";
6+
import {Status} from "@common/models/job/types";
7+
import DownloadJob from "@common/models/job/download-job";
8+
import StorageClass from "@common/models/storage-class";
9+
10+
export interface RemoteObject {
11+
name: string,
12+
region: string,
13+
bucket: string,
14+
key: string,
15+
size: number,
16+
mtime: number,
17+
isDirectory: boolean,
18+
isFile: boolean,
19+
}
20+
21+
//
22+
// export interface FromInfo {
23+
// regionId: string,
24+
// bucketName: string,
25+
// objectList: RemoteObject[],
26+
// }
27+
28+
export interface DownloadOptions {
29+
region: string,
30+
bucket: string,
31+
32+
domain?: Domain,
33+
34+
isOverwrite: boolean,
35+
storageClasses: StorageClass[],
36+
userNatureLanguage: NatureLanguage
37+
}
38+
39+
export enum DownloadAction {
40+
UpdateConfig = "UpdateConfig",
41+
LoadPersistJobs = "LoadPersistJobs",
42+
AddJobs = "AddJobs",
43+
StopJob = "StopJob",
44+
WaitJob = "WaitJob",
45+
StartJob = "StartJob",
46+
RemoveJob = "RemoveJob",
47+
CleanupJobs = "CleanupJobs",
48+
StartAllJobs = "StartAllJobs",
49+
StopAllJobs = "StopAllJobs",
50+
RemoveAllJobs = "RemoveAllJobs",
51+
52+
// common
53+
UpdateUiData = "UpdateUiData",
54+
55+
// reply only
56+
AddedJobs = "AddedJobs",
57+
JobCompleted = "JobCompleted",
58+
}
59+
60+
export interface UpdateConfigMessage {
61+
action: DownloadAction.UpdateConfig,
62+
data: Partial<{
63+
resumable: boolean,
64+
maxConcurrency: number,
65+
multipartSize: number,
66+
multipartThreshold: number,
67+
speedLimit: number,
68+
isDebug: boolean,
69+
persistPath: string,
70+
71+
isOverwrite: boolean,
72+
}>
73+
}
74+
75+
export interface LoadPersistJobsMessage {
76+
action: DownloadAction.LoadPersistJobs,
77+
data: {
78+
clientOptions: Pick<ClientOptions, "accessKey" | "secretKey" | "ucUrl" | "regions">
79+
downloadOptions: Pick<DownloadOptions, "userNatureLanguage">,
80+
}
81+
}
82+
83+
export interface AddJobsMessage {
84+
action: DownloadAction.AddJobs,
85+
data: {
86+
remoteObjects: RemoteObject[],
87+
destPath: string,
88+
downloadOptions: DownloadOptions,
89+
clientOptions: ClientOptions,
90+
}
91+
}
92+
93+
export interface AddedJobsReplyMessage {
94+
action: DownloadAction.AddedJobs,
95+
data: {
96+
remoteObjects: RemoteObject[],
97+
destPath: string,
98+
},
99+
}
100+
101+
export interface UpdateUiDataMessage {
102+
action: DownloadAction.UpdateUiData,
103+
data: {
104+
pageNum: number,
105+
count: number,
106+
query?: {
107+
status?: Status,
108+
name?: string,
109+
},
110+
},
111+
}
112+
113+
export interface UpdateUiDataReplyMessage {
114+
action: DownloadAction.UpdateUiData,
115+
data: {
116+
list: (DownloadJob["uiData"] | undefined)[],
117+
total: number,
118+
finished: number,
119+
running: number,
120+
failed: number,
121+
stopped: number,
122+
},
123+
}
124+
125+
export interface StopJobMessage {
126+
action: DownloadAction.StopJob,
127+
data: {
128+
jobId: string,
129+
},
130+
}
131+
132+
export interface WaitJobMessage {
133+
action: DownloadAction.WaitJob,
134+
data: {
135+
jobId: string,
136+
},
137+
}
138+
139+
export interface StartJobMessage {
140+
action: DownloadAction.StartJob,
141+
data: {
142+
jobId: string,
143+
forceOverwrite?: boolean,
144+
},
145+
}
146+
147+
export interface RemoveJobMessage {
148+
action: DownloadAction.RemoveJob,
149+
data: {
150+
jobId: string,
151+
},
152+
}
153+
154+
export interface CleanupJobMessage {
155+
action: DownloadAction.CleanupJobs,
156+
data?: {},
157+
}
158+
159+
160+
export interface StartAllJobsMessage {
161+
action: DownloadAction.StartAllJobs,
162+
data?: {},
163+
}
164+
165+
export interface StopAllJobsMessage {
166+
action: DownloadAction.StopAllJobs,
167+
data?: {},
168+
}
169+
170+
export interface RemoveAllJobsMessage {
171+
action: DownloadAction.RemoveAllJobs,
172+
data?: {},
173+
}
174+
175+
export interface JobCompletedReplyMessage {
176+
action: DownloadAction.JobCompleted,
177+
data: {
178+
jobsId: string,
179+
jobUiData: DownloadJob["uiData"],
180+
}
181+
}
182+
183+
export type DownloadMessage = UpdateConfigMessage
184+
| LoadPersistJobsMessage
185+
| AddJobsMessage
186+
| UpdateUiDataMessage
187+
| StopJobMessage
188+
| WaitJobMessage
189+
| StartJobMessage
190+
| RemoveJobMessage
191+
| CleanupJobMessage
192+
| StartAllJobsMessage
193+
| StopAllJobsMessage
194+
| RemoveAllJobsMessage
195+
196+
export type DownloadReplyMessage = UpdateUiDataReplyMessage
197+
| AddedJobsReplyMessage
198+
| JobCompletedReplyMessage
199+
200+
export class DownloadActionFns {
201+
constructor(
202+
private readonly ipc: IpcRenderer,
203+
private readonly channel: string,
204+
) {
205+
}
206+
207+
updateConfig(data: UpdateConfigMessage["data"]) {
208+
this.ipc.send(this.channel, {
209+
action: DownloadAction.UpdateConfig,
210+
data: data,
211+
});
212+
}
213+
214+
loadPersistJobs(data: LoadPersistJobsMessage["data"]) {
215+
this.ipc.send(this.channel, {
216+
action: DownloadAction.LoadPersistJobs,
217+
data,
218+
})
219+
}
220+
221+
addJobs(data: AddJobsMessage["data"]) {
222+
this.ipc.send(this.channel, {
223+
action: DownloadAction.AddJobs,
224+
data,
225+
});
226+
}
227+
228+
updateUiData(data: UpdateUiDataMessage["data"]) {
229+
this.ipc.send(this.channel, {
230+
action: DownloadAction.UpdateUiData,
231+
data,
232+
});
233+
}
234+
235+
waitJob(data: WaitJobMessage["data"]) {
236+
this.ipc.send(this.channel, {
237+
action: DownloadAction.WaitJob,
238+
data,
239+
});
240+
}
241+
242+
startJob(data: StartJobMessage["data"]) {
243+
this.ipc.send(this.channel, {
244+
action: DownloadAction.StartJob,
245+
data,
246+
});
247+
}
248+
249+
stopJob(data: StopJobMessage["data"]) {
250+
this.ipc.send(this.channel, {
251+
action: DownloadAction.StopJob,
252+
data,
253+
});
254+
}
255+
256+
removeJob(data: RemoveJobMessage["data"]) {
257+
this.ipc.send(this.channel, {
258+
action: DownloadAction.RemoveJob,
259+
data,
260+
});
261+
}
262+
263+
cleanUpJobs() {
264+
this.ipc.send(this.channel, {
265+
action: DownloadAction.CleanupJobs,
266+
data: {},
267+
});
268+
}
269+
270+
startAllJobs() {
271+
this.ipc.send(this.channel, {
272+
action: DownloadAction.StartAllJobs,
273+
data: {},
274+
});
275+
}
276+
277+
stopAllJobs() {
278+
this.ipc.send(this.channel, {
279+
action: DownloadAction.StopAllJobs,
280+
data: {},
281+
});
282+
}
283+
284+
removeAllJobs() {
285+
this.ipc.send(this.channel, {
286+
action: DownloadAction.RemoveAllJobs,
287+
data: {},
288+
});
289+
}
290+
}

src/common/ipc-actions/upload.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {IpcRenderer} from "electron";
2-
import {Region} from "kodo-s3-adapter-sdk";
32
import {NatureLanguage} from "kodo-s3-adapter-sdk/dist/uplog";
4-
import {BackendMode} from "@common/const/qiniu";
5-
import {Status} from "@common/models/job/types";
3+
4+
import {ClientOptions} from "@common/qiniu";
65
import StorageClass from "@common/models/storage-class";
76
import {UploadJob} from "@common/models/job";
7+
import {Status} from "@common/models/job/types";
88

99
// some types maybe should in models
1010
export interface DestInfo {
@@ -20,15 +20,6 @@ export interface UploadOptions {
2020
userNatureLanguage: NatureLanguage,
2121
}
2222

23-
// TODO: merge with `RequiredOptions['clientOptions']` in upload-job.ts
24-
export interface ClientOptions {
25-
accessKey: string,
26-
secretKey: string,
27-
ucUrl: string,
28-
regions: Region[],
29-
backendMode: BackendMode,
30-
}
31-
3223
// action names
3324
export enum UploadAction {
3425
UpdateConfig = "UpdateConfig",
@@ -56,11 +47,11 @@ export enum UploadAction {
5647
export interface UpdateConfigMessage {
5748
action: UploadAction.UpdateConfig,
5849
data: Partial<{
59-
resumeUpload: boolean,
50+
resumable: boolean,
6051
maxConcurrency: number,
61-
multipartUploadSize: number, // Bytes
62-
multipartUploadThreshold: number, // Bytes
63-
uploadSpeedLimit: number, // Bytes/s
52+
multipartSize: number, // Bytes
53+
multipartThreshold: number, // Bytes
54+
speedLimit: number, // Bytes/s
6455
isDebug: boolean,
6556
isSkipEmptyDirectory: boolean,
6657
persistPath: string,
@@ -85,6 +76,14 @@ export interface AddJobsMessage {
8576
},
8677
}
8778

79+
export interface AddedJobsReplyMessage {
80+
action: UploadAction.AddedJobs,
81+
data: {
82+
filePathnameList: string[],
83+
destInfo: DestInfo,
84+
},
85+
}
86+
8887
export interface UpdateUiDataMessage {
8988
action: UploadAction.UpdateUiData,
9089
data: {
@@ -124,7 +123,9 @@ export interface StartJobMessage {
124123
action: UploadAction.StartJob,
125124
data: {
126125
jobId: string,
127-
forceOverwrite?: boolean,
126+
options?: {
127+
forceOverwrite: boolean,
128+
},
128129
},
129130
}
130131

@@ -155,14 +156,6 @@ export interface RemoveAllJobsMessage {
155156
data?: {},
156157
}
157158

158-
export interface AddedJobsReplyMessage {
159-
action: UploadAction.AddedJobs,
160-
data: {
161-
filePathnameList: string[],
162-
destInfo: DestInfo,
163-
},
164-
}
165-
166159
export interface JobCompletedReplyMessage {
167160
action: UploadAction.JobCompleted,
168161
data: {
@@ -192,6 +185,11 @@ export type UploadMessage = UpdateConfigMessage
192185
| StopAllJobsMessage
193186
| RemoveAllJobsMessage
194187

188+
export type UploadReplyMessage = UpdateUiDataReplyMessage
189+
| AddedJobsReplyMessage
190+
| JobCompletedReplyMessage
191+
| CreatedDirectoryReplyMessage
192+
195193
// send actions functions
196194
export class UploadActionFns {
197195
constructor(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// TODO: merge with src/renderer/components/services/qiniu-client/_mock-helpers_/auth.ts
2+
export const QINIU_ACCESS_KEY = "NgKd0BmebvsFERFEBfKVVZGeGn7VsZQe_H_AunOC";
3+
export const QINIU_SECRET_KEY = "lp4Zv3Gi_7CHtxNTcJx2Pum5hUJB3gHROcg4vp0i";
4+
export const QINIU_UC = "http://fake.qiniu.com";

0 commit comments

Comments
 (0)