@luckylillia-dev/plugin-aiimgdetector 1.0.5 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/synthid.ts CHANGED
@@ -3,7 +3,7 @@ import { mkdir, readFile, realpath, rename, rm, unlink, writeFile } from 'node:f
3
3
  import { dirname, join, resolve } from 'node:path'
4
4
  import { setTimeout as delay } from 'node:timers/promises'
5
5
  import type { Context, Http } from '@luckylillia-dev/plugin-sdk'
6
- import type { Image } from './image.js'
6
+ import { MAX_SIZE, type Image } from './image.js'
7
7
  import { launchSynthIdBrowser, type SynthIdBrowserSession } from './synthid-browser.js'
8
8
  import { HttpSynthIdClient, type HttpSynthIdOptions } from './synthid-http.js'
9
9
  import { describeSynthIdFailure, SynthIdError, type SynthIdResult } from './synthid-result.js'
@@ -33,7 +33,7 @@ interface CapturedCredentials {
33
33
  // All entries in one instance share a profile and queue. The last owner closes
34
34
  // the browser and removes this entry, including during plugin reload.
35
35
  const sessions = new Map<string, ManagedSession>()
36
- const supported = /^image\/(?:jpeg|png|webp|gif|bmp|avif|heic|heif|tiff)$/
36
+ const supported = /^(?:image\/(?:jpeg|png|webp|gif|bmp|avif|heic|heif|tiff)|video\/(?:mp4|quicktime|webm))$/
37
37
  const cancelled = () => new SynthIdError('cancelled', 'SynthID operation was cancelled')
38
38
 
39
39
  class ManagedSession {
@@ -420,8 +420,9 @@ export class SynthIdClient {
420
420
  async detect(image: Image): Promise<SynthIdResult> {
421
421
  if (this.disposed) throw cancelled()
422
422
  const mime = image.type.split(';')[0].trim().toLowerCase()
423
- if (!supported.test(mime) || !image.data.byteLength || image.data.byteLength > 20 * 1024 * 1024) {
424
- throw new SynthIdError('request', 'SynthID needs a supported image of at most 20 MB')
423
+ const kind = mime.startsWith('video/') ? 'video' : 'image'
424
+ if (!supported.test(mime) || !image.data.byteLength || image.data.byteLength > MAX_SIZE[kind]) {
425
+ throw new SynthIdError('request', `SynthID needs a supported ${kind} of at most ${MAX_SIZE[kind] / 1024 / 1024} MB`)
425
426
  }
426
427
  // Snapshot before either context initialization or the shared queue waits.
427
428
  // An update affects only subsequent requests, including credential identity.
@@ -475,7 +476,7 @@ function safeInitializationError(error: unknown): SynthIdError | undefined {
475
476
  }
476
477
 
477
478
  function safeError(error: unknown): string {
478
- return error instanceof SynthIdError ? describeSynthIdFailure(error) : '无法启动或保存 SynthID 登录,请检查浏览器、网络和插件数据目录。'
479
+ return error instanceof SynthIdError ? describeSynthIdFailure(error, '图片', 'login') : '无法启动或保存 SynthID 登录,请检查浏览器、网络和插件数据目录。'
479
480
  }
480
481
 
481
482
  function validCredentials(value: unknown): value is SynthIdCredentials {