feat(Sati): add projectId support
This commit is contained in:
parent
54962f9db5
commit
ab8bdbbe33
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sati",
|
"name": "sati",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"description": "next generation anti-captcha",
|
"description": "next generation anti-captcha",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
14
src/Sati.ts
14
src/Sati.ts
@ -23,6 +23,7 @@ import { events, methods, tasks, Task } from './types'
|
|||||||
export class Sati extends EventEmitter<events> {
|
export class Sati extends EventEmitter<events> {
|
||||||
private socket: SatiSocket
|
private socket: SatiSocket
|
||||||
private shortLogging: boolean
|
private shortLogging: boolean
|
||||||
|
private projectId: number | undefined
|
||||||
private awaitedTasks: {
|
private awaitedTasks: {
|
||||||
[ index: number ]: {
|
[ index: number ]: {
|
||||||
resolve(data: any): void,
|
resolve(data: any): void,
|
||||||
@ -31,9 +32,18 @@ export class Sati extends EventEmitter<events> {
|
|||||||
} = Object.create(null)
|
} = Object.create(null)
|
||||||
|
|
||||||
/** @param token your api token. get it at https://sati.ac/dashboard */
|
/** @param token your api token. get it at https://sati.ac/dashboard */
|
||||||
constructor({ token, shortLogging = false }: { token: string, shortLogging?: boolean }) {
|
constructor({
|
||||||
|
token,
|
||||||
|
shortLogging = false,
|
||||||
|
projectId
|
||||||
|
}: {
|
||||||
|
token: string,
|
||||||
|
shortLogging?: boolean,
|
||||||
|
projectId?: number
|
||||||
|
}) {
|
||||||
super()
|
super()
|
||||||
this.shortLogging = shortLogging
|
this.shortLogging = shortLogging
|
||||||
|
this.projectId = projectId
|
||||||
this.socket = new SatiSocket(token)
|
this.socket = new SatiSocket(token)
|
||||||
this.socket.on('event', ({ type, data }) => {
|
this.socket.on('event', ({ type, data }) => {
|
||||||
this.emit(type as keyof events, data)
|
this.emit(type as keyof events, data)
|
||||||
@ -102,7 +112,7 @@ export class Sati extends EventEmitter<events> {
|
|||||||
* @throws {SatiError} if unable to solve
|
* @throws {SatiError} if unable to solve
|
||||||
*/
|
*/
|
||||||
public async solve<T extends keyof tasks>(type: T, data: tasks[T]['params']): Promise<Task<T, 'success'>> {
|
public async solve<T extends keyof tasks>(type: T, data: tasks[T]['params']): Promise<Task<T, 'success'>> {
|
||||||
const task = await this.call('createTask', { type, data })
|
const task = await this.call('createTask', { type, data, projectId: this.projectId })
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.awaitedTasks[task.id] = { resolve, reject }
|
this.awaitedTasks[task.id] = { resolve, reject }
|
||||||
|
@ -59,7 +59,8 @@ export type methods = {
|
|||||||
createTask: {
|
createTask: {
|
||||||
request: {
|
request: {
|
||||||
type: keyof tasks,
|
type: keyof tasks,
|
||||||
data: tasks[keyof tasks]['params']
|
data: tasks[keyof tasks]['params'],
|
||||||
|
projectId?: number
|
||||||
},
|
},
|
||||||
response: Task
|
response: Task
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user