Skip to content

Commit

Permalink
feat(list-cmd-flow): check if server support some command
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 24, 2020
1 parent 3744893 commit 8245b32
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/index.ts
Expand Up @@ -4,3 +4,4 @@ export * from './core-stats-flow';
export * from './list-remotes-flow';
export * from './operations-list-flow';
export * from './connection-flow';
export * from './list-cmd-flow';
39 changes: 39 additions & 0 deletions src/app/@dataflow/rclone/list-cmd-flow.ts
@@ -0,0 +1,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))
);
}
}

0 comments on commit 8245b32

Please sign in to comment.