Skip to content

Commit 6cd369e

Browse files
committed
♻️ 重构导入导出
1 parent a4263fb commit 6cd369e

6 files changed

Lines changed: 270 additions & 114 deletions

File tree

src/apps/script/controller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { ResourceManager } from '../resource';
4444
import { compileScriptCode } from '@App/pkg/sandbox/compile';
4545
import { SubscribeModel } from '@App/model/subscribe';
4646
import { Subscribe, SUBSCRIBE_STATUS_DISABLE, SUBSCRIBE_STATUS_ENABLE } from '@App/model/do/subscribe';
47-
import { File } from '@App/model/do/backup';
47+
import { ExportFile } from '@App/model/do/backup';
4848

4949
// 脚本控制器,发送或者接收来自管理器的消息,并不对脚本数据做实际的处理
5050
export class ScriptController {
@@ -180,10 +180,10 @@ export class ScriptController {
180180
});
181181
}
182182

183-
public getImportFile(uuid: string): Promise<File> {
183+
public getImportFile(uuid: string): Promise<ExportFile> {
184184
return new Promise(resolve => {
185185
MsgCenter.sendMessage(RequestImportFile, uuid, resp => {
186-
resolve(<File>resp);
186+
resolve(<ExportFile>resp);
187187
});
188188
});
189189
}
@@ -565,8 +565,8 @@ export class ScriptController {
565565
})
566566
}
567567

568-
public parseBackFile(str: string): { data?: File, err?: string } {
569-
const data = <File>JSON.parse(str);
568+
public parseBackFile(str: string): { data?: ExportFile, err?: string } {
569+
const data = <ExportFile>JSON.parse(str);
570570
if (!data.created_by) {
571571
return { err: '错误的格式' };
572572
}
@@ -576,7 +576,7 @@ export class ScriptController {
576576
return { data: data };
577577
}
578578

579-
public openImportFileWindow(file: File): Promise<any> {
579+
public openImportFileWindow(file: ExportFile): Promise<any> {
580580
return new Promise(resolve => {
581581
MsgCenter.sendMessage(OpenImportFileWindow, file, (resp) => {
582582
resolve(resp);

src/apps/script/manager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Subscribe } from '@App/model/do/subscribe';
1919
import { SubscribeModel } from '@App/model/subscribe';
2020
import { SyncModel } from '@App/model/sync';
2121
import { SyncAction, SyncData } from '@App/model/do/sync';
22-
import { File } from '@App/model/do/backup';
22+
import { ExportFile } from '@App/model/do/backup';
2323
import { v4 as uuidv4 } from 'uuid';
2424
import { Manager } from '@App/pkg/apps/manager';
2525

@@ -196,7 +196,7 @@ export class ScriptManager extends Manager {
196196
});
197197
}
198198

199-
public openImportFileWindow(file: File): Promise<any> {
199+
public openImportFileWindow(file: ExportFile): Promise<any> {
200200
return new Promise(resolve => {
201201
// 打开导入窗口
202202
const uuid = uuidv4()
@@ -209,15 +209,15 @@ export class ScriptManager extends Manager {
209209
});
210210
}
211211

212-
public importFile(file: File): Promise<any> {
212+
public importFile(file: ExportFile): Promise<any> {
213213
return new Promise(resolve => {
214214

215215

216216
resolve(true);
217217
});
218218
}
219219

220-
public requestImportFile(uuid: string): Promise<File> {
220+
public requestImportFile(uuid: string): Promise<ExportFile> {
221221
return new Promise(resolve => {
222222
const file = App.Cache.get('import:info:' + uuid);
223223
resolve(file);

src/model/do/backup.ts

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,51 @@
11
// 使用tampermonkey的备份模式
2-
3-
import { ResourceHash } from './resource';
42
import { Metadata, Script as InstallScript } from './script';
53
import { SubscribeScript, Subscribe as InstallSubscribe } from './subscribe';
64

7-
export interface File {
8-
created_by: string
9-
version: string
10-
scripts: Script[];
11-
subscribes: Subscribe[];
12-
settings: Settings
13-
}
14-
15-
export interface Settings {
16-
17-
}
18-
19-
export interface Script {
5+
export interface ExportScript {
206
name: string
21-
options: Options
7+
script: InstallScript
228
storage: Storage
239
enabled: boolean
2410
position: number
25-
uuid: string
26-
file_url?: string
27-
source: string
28-
requires: Resource[]
29-
requires_css: Resource[]
30-
resources: Resource[]
31-
self_metadata: Metadata
32-
subscribe_url?: string
33-
modified: number
34-
// 导入用,需要解析source获得
35-
metadata?: Metadata
36-
script?: InstallScript
37-
old?: InstallScript
38-
error?: string
39-
background?: boolean
11+
requires: ExportResource[]
12+
requires_css: ExportResource[]
13+
resources: ExportResource[]
4014
}
4115

42-
export interface Subscribe {
43-
name: string
44-
url: string
16+
export interface ImportScript {
17+
source: string
4518
enabled: boolean
19+
position: number
20+
storage?: Storage
21+
requires?: ImportResource[]
22+
requires_css?: ImportResource[]
23+
resources?: ImportResource[]
24+
}
25+
26+
export interface ImportResource {
27+
meta: { name: string, url: string, ts: number, mimetype: string }
4628
source: string
47-
scripts: { [key: string]: SubscribeScript };
48-
modified: number
49-
// 导入用,解析source获得
50-
metadata?: Metadata
51-
subscribe?: InstallSubscribe
52-
old?: InstallSubscribe
53-
error?: string
29+
base64: string
5430
}
5531

56-
export interface Options {
5732

33+
export interface ExportSubscribe {
34+
name: string
35+
subscribe: InstallSubscribe
36+
enabled: boolean
37+
}
38+
39+
export interface ImportSubscribe {
40+
source: string
41+
enabled: boolean
42+
scripts: { [key: string]: SubscribeScript };
5843
}
5944

60-
export interface Resource {
45+
export interface ExportResource {
6146
meta: { name: string, url: string, ts: number, mimetype: string }
6247
source: string
63-
base64?: string
64-
hash: ResourceHash
48+
base64: string
6549
}
6650

6751
export interface Storage {

0 commit comments

Comments
 (0)