update library sync and client to support new hydrus api
This commit is contained in:
+15
-4
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user