-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2245ce5
commit 9ed9446
Showing
9 changed files
with
133 additions
and
1 deletion.
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
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
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,43 @@ | ||
import { PhotoEntry, Response } from './response'; | ||
|
||
export class VideoMatch { | ||
private readonly _e: PhotoEntry; | ||
|
||
public constructor(x: PhotoEntry) { | ||
this._e = x; | ||
} | ||
|
||
public get archive(): string { | ||
return this._e.foto as string; | ||
} | ||
|
||
public get archiveAsBuffer(): Buffer { | ||
return Buffer.from(this._e.foto as string, 'base64'); | ||
} | ||
} | ||
|
||
// ans_type = 245 | ||
export class VideoResult extends Response { | ||
private _idx = 0; | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public isCacheable(): boolean { | ||
return true; | ||
} | ||
|
||
public [Symbol.iterator](): Iterator<VideoMatch, undefined> { | ||
return { | ||
next: (): IteratorResult<VideoMatch, undefined> => { | ||
if (this._idx < this._raw.data.fotos.length) { | ||
return { | ||
value: new VideoMatch(this._raw.data.fotos[this._idx++]), | ||
done: false, | ||
}; | ||
} | ||
|
||
this._idx = 0; | ||
return { value: undefined, done: true }; | ||
}, | ||
}; | ||
} | ||
} |
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,24 @@ | ||
import { Response } from './response'; | ||
|
||
// ans_type = 243 | ||
export class VideoStatus extends Response { | ||
public isError(): boolean { | ||
return this.resultCode < 0; | ||
} | ||
|
||
public isAccepted(): boolean { | ||
return this.resultCode === 1; | ||
} | ||
|
||
public isInProgress(): boolean { | ||
return this.resultCode === 2; | ||
} | ||
|
||
public isCompleted(): boolean { | ||
return this.resultCode === 3; | ||
} | ||
|
||
public description(): string { | ||
return this.comment; | ||
} | ||
} |
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,8 @@ | ||
import { Response } from './response'; | ||
|
||
// ans_type = 241 | ||
export class VideoUploadAck extends Response { | ||
public isError(): boolean { | ||
return this.resultCode < 0; | ||
} | ||
} |
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,29 @@ | ||
import { ClientBase } from './clientbase'; | ||
import { IFaceXRequestBuilder, IRemoteTransport } from './interfaces'; | ||
import { SvcClientRequestEncoder } from './encoders/svcclient'; | ||
import { VideoCommands } from './request/commands'; | ||
import * as R from './responses'; | ||
|
||
type VideoType = Buffer | string | NodeJS.ReadableStream; | ||
|
||
export class VideoClient extends ClientBase { | ||
public constructor(url: string, transport: IRemoteTransport, requestBuilder: IFaceXRequestBuilder) { | ||
super(url, transport, new SvcClientRequestEncoder(), requestBuilder); | ||
} | ||
|
||
public async uploadVideo(video: VideoType): Promise<R.VideoUploadAck> { | ||
const builder = await this._requestBuilder.reset(VideoCommands.VIDEO_UPLOAD).setVideo(video); | ||
return this._sendRequest(await builder.get()); | ||
} | ||
|
||
public async getVideoStatus(guid: string): Promise<R.VideoStatus> { | ||
const builder = this._requestBuilder.reset(VideoCommands.VIDEO_STATUS, guid); | ||
return this._sendRequest(await builder.get()); | ||
} | ||
|
||
public async getVideoResult(guid: string, type: 'detect' | 'match', archiveNumber = 1): Promise<R.VideoResult> { | ||
const builder = this._requestBuilder.reset(VideoCommands.VIDEO_RESULT, guid); | ||
builder.setParams(type === 'detect' ? 1 : 2, archiveNumber); | ||
return this._sendRequest(await builder.get()); | ||
} | ||
} |