chore: update public repo

This commit is contained in:
desu-bot 2025-08-14 09:21:11 +00:00
parent ccc5f98f34
commit 728699b3ec
No known key found for this signature in database
8 changed files with 1990 additions and 95 deletions

View file

@ -1,87 +0,0 @@
import { sleep } from '@fuman/utils'
import { z } from 'zod'
import { ffetch } from './fetch.ts'
import { getEnv } from './misc.ts'
const CreateTaskResponse = z.object({
errorId: z.number(),
errorCode: z.string().optional().nullable(),
taskId: z.number(),
})
const GetTaskResultResponse = z.object({
errorId: z.number(),
errorCode: z.string().optional().nullable(),
status: z.enum(['ready', 'processing']),
solution: z.unknown().optional(),
})
export async function solveCaptcha(task: unknown) {
const res = await ffetch.post('https://api.capmonster.cloud/createTask', {
json: {
clientKey: getEnv('CAPMONSTER_API_TOKEN'),
task,
},
}).parsedJson(CreateTaskResponse)
if (res.errorId) {
throw new Error(`createTask error ${res.errorId}: ${res.errorCode}`)
}
const taskId = res.taskId
await sleep(5_000)
let requestCount = 0
while (true) {
requestCount += 1
if (requestCount > 100) {
// "Limit: 120 requests per task. If the limit is exceeded, the user's account may be temporarily locked."
// just to be safe
throw new Error('captcha request count exceeded')
}
const res = await ffetch.post('https://api.capmonster.cloud/getTaskResult', {
json: {
clientKey: getEnv('CAPMONSTER_API_TOKEN'),
taskId,
},
}).parsedJson(GetTaskResultResponse)
if (res.errorId) {
throw new Error(`getTaskResult error ${res.errorId}: ${res.errorCode}`)
}
if (res.status === 'ready') {
return res.solution
}
await sleep(2_000)
}
}
export async function solveRecaptcha(params?: {
url: string
siteKey: string
s?: string
userAgent?: string
cookies?: string
isInvisible?: boolean
}) {
const res = await solveCaptcha({
type: 'RecaptchaV2TaskProxyless',
websiteURL: params?.url,
websiteKey: params?.siteKey,
recaptchaDataSValue: params?.s,
userAgent: params?.userAgent,
cookies: params?.cookies,
isInvisible: params?.isInvisible,
})
if (typeof res !== 'object' || !res || !('gRecaptchaResponse' in res) || typeof res.gRecaptchaResponse !== 'string') {
throw new Error('invalid recaptcha response')
}
return res.gRecaptchaResponse
}

View file

@ -33,6 +33,16 @@ export const NavidromeSong = z.object({
libraryPath: z.string(),
duration: z.number(),
size: z.number(),
participants: z.object({
artist: z.object({
id: z.string(),
name: z.string(),
}).array().optional(),
}).optional(),
mbzRecordingID: z.string().optional(),
mbzReleaseTrackId: z.string().optional(),
mbzAlbumId: z.string().optional(),
mbzReleaseGroupId: z.string().optional(),
})
export type NavidromeSong = z.infer<typeof NavidromeSong>
@ -43,7 +53,7 @@ export async function fetchSongs(offset: number, pageSize: number) {
_start: offset,
_end: offset + pageSize,
_order: 'ASC',
_sort: 'title',
_sort: 'path',
},
}).parsedJson(z.array(NavidromeSong))
}