Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list-cmd-flow): check if server support some command
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
); | ||
} | ||
} |