update library sync and client to support new hydrus api

This commit is contained in:
2026-04-23 13:38:16 -07:00
parent 886db2d904
commit d58686bce9
2 changed files with 86 additions and 10 deletions
+15 -4
View File
@@ -32,6 +32,17 @@ export type HydrusFileDetails = HydrusMediaInfo & {
tags: string[]
}
function sanitizeApiKey(value?: string) {
return (value || '').replace(/\s+/g, '')
}
function sanitizePort(value?: string | number) {
if (value == null) return undefined
if (typeof value === 'number') return Number.isFinite(value) ? value : undefined
const trimmed = value.trim()
return trimmed ? trimmed : undefined
}
export function makeId() {
return Date.now().toString() + '-' + Math.random().toString(36).slice(2, 9)
}
@@ -54,10 +65,10 @@ export class HydrusClient {
constructor(cfg: Partial<ServerConfig> = {}) {
this.cfg = {
id: (cfg.id as string) || makeId(),
name: cfg.name || '',
host: cfg.host || '',
port: cfg.port,
apiKey: cfg.apiKey,
name: (cfg.name || '').trim(),
host: (cfg.host || '').trim(),
port: sanitizePort(cfg.port),
apiKey: sanitizeApiKey(cfg.apiKey),
ssl: !!cfg.ssl,
forceApiKeyInQuery: !!cfg.forceApiKeyInQuery
}