Skip to content

Commit

Permalink
feat(noop-auth): implement command: rc/noopauth
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 13, 2020
1 parent 4a10502 commit 77fb72b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/@dataflow/noop-auth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NoopAuthTimer } from './noop-auth';

describe('Noopauth', () => {
it('should create an instance', () => {
expect(new NoopAuthTimer()).toBeTruthy();
});
});
53 changes: 53 additions & 0 deletions src/app/@dataflow/noop-auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { DataFlowNode, RcloneAuth } from './generic';
import { Observable, interval, Subject } from 'rxjs';
import { AjaxRequest, AjaxResponse } from 'rxjs/ajax';
import { map } from 'rxjs/operators';

export abstract class NoopAuth extends RcloneAuth {
protected cmd: string = 'rc/noopauth';
protected params: object = {};
protected cacheSupport: boolean = false;

protected generateSuperset(current: DataFlowNode, previous: DataFlowNode): DataFlowNode {
return [previous[0], [].concat(current[1], previous[1])];
}
}

export class NoopAuthTimer extends NoopAuth {
public url: string = 'http://localhost:5572';
public user: string = '';
public password: string = '';
public interval: number = 5000;

protected request(x: DataFlowNode): AjaxRequest {
let ans = super.request(x);
ans['body'] = {
timestamp: new Date().getTime(),
};
return ans;
}
protected reconstruct(rsp: Observable<DataFlowNode>): Observable<DataFlowNode> {
return rsp.pipe(
map((x) => {
if (x[1].length !== 0) return x;
const rspjson = (x[0] as AjaxResponse).response;
const rst = new Date().getTime() - rspjson.timestamp;
return [{ 'response-time': rst }, x[1]];
})
);
}
protected prerequest(): Observable<DataFlowNode> {
return interval(this.interval).pipe(
map(() => [{ url: this.url, user: this.user, password: this.password }, []])
);
}
}

export class NoopAuthEmitter extends NoopAuthTimer {
public emitter = new Subject<number>();
protected prerequest(): Observable<DataFlowNode> {
return this.emitter.pipe(
map(() => [{ url: this.url, user: this.user, password: this.password }, []])
);
}
}

0 comments on commit 77fb72b

Please sign in to comment.