diff --git a/src/app/@dataflow/rclone/index.ts b/src/app/@dataflow/rclone/index.ts index 84acf60..3e8ceeb 100644 --- a/src/app/@dataflow/rclone/index.ts +++ b/src/app/@dataflow/rclone/index.ts @@ -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'; diff --git a/src/app/@dataflow/rclone/list-cmd-flow.ts b/src/app/@dataflow/rclone/list-cmd-flow.ts new file mode 100644 index 0000000..2ebd9b9 --- /dev/null +++ b/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 { + // public prerequest$: Observable>; + protected cmd = 'rc/list'; + protected params = {}; + protected cacheSupport = false; + protected reconstructAjaxResult(x: AjaxFlowInteralNode): CombErr { + 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> { + 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)) + ); + } +}