-
Notifications
You must be signed in to change notification settings - Fork 44
/
list-cmd-flow.ts
39 lines (36 loc) · 1.32 KB
/
list-cmd-flow.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
import { PostFlow } from './post-flow';
import { IRcloneServer } from '../extra';
import { AjaxFlowInteralNode, CombErr } from '../core';
import { Observable } from 'rxjs';
import { map, distinctUntilChanged } from 'rxjs/operators';
export interface IRcloneCmd {
Path: string;
Title: string;
AuthRequired: boolean;
Help: string;
}
export interface ListCmdFlowOutNode {
commands: IRcloneCmd[];
}
export abstract class ListCmdFlow extends PostFlow<IRcloneServer, ListCmdFlowOutNode> {
// public prerequest$: Observable<CombErr<IRcloneServer>>;
protected cmd = 'rc/list';
protected params = {};
protected cacheSupport = false;
protected reconstructAjaxResult(x: AjaxFlowInteralNode): CombErr<ListCmdFlowOutNode> {
if (x[1].length !== 0) return [{}, x[1]] as any;
const rsp = x[0].ajaxRsp.response;
return [{ commands: rsp['commands'] }, []];
}
public verify(cmd: string): Observable<CombErr<IRcloneServer>> {
return this.getSupersetOutput().pipe(
map((sup) => {
if (sup[1].length !== 0) return [{}, sup[1]] as any;
if (-1 === sup[0].commands.findIndex((x) => x.Path == cmd))
return [{}, [new Error(`not support command: ${cmd}`)]];
else return [{ url: sup[0].url, password: sup[0].password, user: sup[0].user }, []];
}),
distinctUntilChanged((x, y) => JSON.stringify(x) === JSON.stringify(y))
);
}
}