-
Notifications
You must be signed in to change notification settings - Fork 44
/
mounts.service.ts
94 lines (84 loc) · 2.69 KB
/
mounts.service.ts
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
import { Injectable } from '@angular/core';
import { Subject, Observable, combineLatest } from 'rxjs';
import {
ListMountsFlow,
IRcloneServer,
MountMountFlowParamsNode,
MountMountFlow,
MountMountFlowInNode,
MountUnmountFlow,
MountUnmountFlowInNode,
MountUnmountFlowParamsNode,
MountUnmountAllFlow,
} from '../../@dataflow/rclone';
import { CombErr } from '../../@dataflow/core';
import { ConnectionService } from '../connection.service';
@Injectable({
providedIn: 'root',
})
export class MountsService {
private listTrigger = new Subject<number>();
list$: ListMountsFlow;
private addTrigger = new Subject<MountMountFlowParamsNode>();
add$: MountMountFlow;
private unmountTrigger = new Subject<MountUnmountFlowParamsNode>();
unmount$: MountUnmountFlow;
private unmountAllTrigger = new Subject<number>();
unmountAll$: MountUnmountAllFlow;
constructor(private connectService: ConnectionService) {
const outer = this;
this.list$ = new (class extends ListMountsFlow {
public prerequest$: Observable<CombErr<IRcloneServer>> = combineLatest(
[outer.listTrigger, outer.connectService.listCmd$.verify(this.cmd)],
(_, node) => node
);
})();
this.list$.deploy();
this.add$ = new (class extends MountMountFlow {
public prerequest$: Observable<CombErr<MountMountFlowInNode>> = combineLatest(
[outer.addTrigger, outer.connectService.listCmd$.verify(this.cmd)],
(params, cmdNode) => [{ ...cmdNode[0], ...params }, cmdNode[1]]
);
})();
this.add$.deploy();
this.add$.getOutput().subscribe(node => {
if (node[1].length !== 0) return;
this.refreshList();
});
this.unmount$ = new (class extends MountUnmountFlow {
public prerequest$: Observable<CombErr<MountUnmountFlowInNode>> = combineLatest(
[outer.unmountTrigger, outer.connectService.listCmd$.verify(this.cmd)],
(params, cmdNode) => [{ ...cmdNode[0], ...params }, cmdNode[1]]
);
})();
this.unmount$.deploy();
this.unmount$.getOutput().subscribe(node => {
if (node[1].length !== 0) return;
this.refreshList();
});
this.unmountAll$ = new (class extends MountUnmountAllFlow {
public prerequest$: Observable<CombErr<IRcloneServer>> = combineLatest(
[outer.unmountAllTrigger, outer.connectService.listCmd$.verify(this.cmd)],
(_, node) => node
);
})();
this.unmountAll$.deploy();
this.unmountAll$.getOutput().subscribe(node => {
if (node[1].length !== 0) return;
this.refreshList();
});
}
refreshList() {
this.list$.clearCache();
this.listTrigger.next(1);
}
mount(params: MountMountFlowParamsNode) {
this.addTrigger.next(params);
}
unmount(params: MountUnmountFlowParamsNode) {
this.unmountTrigger.next(params);
}
unmountAll() {
this.unmountAllTrigger.next(1);
}
}