Compare commits

..

6 Commits

4 changed files with 50 additions and 9 deletions

5
package-lock.json generated
View File

@ -1,12 +1,13 @@
{ {
"name": "sati", "name": "sati",
"version": "1.0.0", "version": "0.3.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "sati", "name": "sati",
"version": "1.0.0", "version": "0.3.2",
"license": "MIT",
"dependencies": { "dependencies": {
"@types/node": "^20.1.1", "@types/node": "^20.1.1",
"@types/ws": "^8.5.4", "@types/ws": "^8.5.4",

View File

@ -1,6 +1,6 @@
{ {
"name": "sati", "name": "sati",
"version": "0.2.3", "version": "0.3.3",
"description": "next generation anti-captcha", "description": "next generation anti-captcha",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
@ -37,7 +37,7 @@
"types": "./dist/src/index.d.ts", "types": "./dist/src/index.d.ts",
"exports": { "exports": {
".": { ".": {
"import": "./dist/sati.node.esm.js", "import": "./dist/sati.node.esm.mjs",
"require": "./dist/sati.node.cjs.js", "require": "./dist/sati.node.cjs.js",
"types": "./dist/src/index.d.ts" "types": "./dist/src/index.d.ts"
}, },

View File

@ -22,6 +22,8 @@ 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 projectId: number | undefined
private awaitedTasks: { private awaitedTasks: {
[ index: number ]: { [ index: number ]: {
resolve(data: any): void, resolve(data: any): void,
@ -30,8 +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 }: { token: string }) { constructor({
token,
shortLogging = false,
projectId
}: {
token: string,
shortLogging?: boolean,
projectId?: number
}) {
super() super()
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)
@ -63,7 +75,11 @@ export class Sati extends EventEmitter<events> {
const awaited = this.awaitedTasks[task.id] const awaited = this.awaitedTasks[task.id]
if(task.state === 'error') { if(task.state === 'error') {
awaited.reject(new SatiError(`unable to solve ${task.type} task #${task.id}`)) let message = `unable to solve ${task.type} task`
if(!this.shortLogging) {
message += ` #${task.id}`
}
awaited.reject(new SatiError(message))
} else if(task.state === 'success') { } else if(task.state === 'success') {
awaited.resolve(task) awaited.resolve(task)
} }
@ -96,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 }

View File

@ -25,13 +25,36 @@ export type tasks = {
params: { params: {
siteKey: string, siteKey: string,
pageUrl: string, pageUrl: string,
data: Record<string, string> data?: Record<string, string>
serviceUrl?: string, serviceUrl?: string,
proxy?: string proxy?: string
}, },
result: { result: {
token: string token: string
} }
},
GeeTest3: {
params: {
siteKey: string,
pageUrl: string,
challenge: string,
apiServer?: string,
proxy?: string
},
result: {
challenge: string,
validate: string,
seccode: string
}
},
ImageToText: {
params: {
image: string,
type?: string,
},
result: {
result: string
}
} }
} }
@ -45,7 +68,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
}, },