@luckylillia-dev/plugin-aiimgdetector 1.1.0 → 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/lib/synthid-http.js +10 -3
- package/lib/synthid-manual.js +5 -4
- package/lib/synthid-result.js +8 -3
- package/package.json +1 -1
- package/src/synthid-http.ts +10 -3
- package/src/synthid-manual.ts +4 -3
- package/src/synthid-result.ts +8 -4
package/lib/synthid-http.js
CHANGED
|
@@ -4,6 +4,8 @@ import { SynthIdTokenStore } from './synthid-auth.js';
|
|
|
4
4
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
5
5
|
import { connectionCode, networkCodeOf, parseSynthIdResponse, SynthIdError } from './synthid-result.js';
|
|
6
6
|
const ORIGIN = 'https://synthid.com';
|
|
7
|
+
const RPC_ID = 'vZ4jac';
|
|
8
|
+
const VIDEO_DEFAULT_FPS = 30;
|
|
7
9
|
const TOKEN = 'https://securetoken.googleapis.com/v1/token?key=AIzaSyCjADz3UffE3DF5HZ--7MgVEXrbt6Bgcck';
|
|
8
10
|
const CREATE = 'https://waa-pa.clients6.google.com/$rpc/google.internal.waa.v1.Waa/Create';
|
|
9
11
|
const UPLOAD = 'https://content-push.googleapis.com/upload/';
|
|
@@ -199,7 +201,8 @@ export class HttpSynthIdClient {
|
|
|
199
201
|
await response.body?.cancel();
|
|
200
202
|
const status = response.status;
|
|
201
203
|
const kind = status === 429 ? 'rate-limit' : status === 401 || stage === 'auth' && status === 400 ? 'auth'
|
|
202
|
-
: status === 403 ? 'permission' : status
|
|
204
|
+
: status === 403 ? 'permission' : status === 400 && stage === 'detect' ? 'response'
|
|
205
|
+
: status >= 500 ? 'server' : 'request';
|
|
203
206
|
throw new SynthIdError(kind, `SynthID ${stage} returned HTTP ${status}`, stage === 'detect' && status === 401 ? 16 : status, status === 429 ? retryAfter(response.headers.get('retry-after')) : undefined);
|
|
204
207
|
}
|
|
205
208
|
const limit = stage === 'page' || stage === 'challenge' ? 4 * 1024 * 1024 : 1024 * 1024;
|
|
@@ -319,12 +322,16 @@ export class HttpSynthIdClient {
|
|
|
319
322
|
headers: { ...headers, 'X-Goog-Upload-Command': 'upload, finalize', 'X-Goog-Upload-Offset': '0' } }, 'upload, finalize');
|
|
320
323
|
if (uploaded.headers.get('x-goog-upload-status') !== 'final' || (await uploaded.text()).trim() !== blobref)
|
|
321
324
|
throw new SynthIdError('response', 'SynthID upload did not finalize at the generated path');
|
|
325
|
+
const video = mime.startsWith('video/');
|
|
322
326
|
const endpoint = new URL('/_/WatermarkApp/data/batchexecute', ORIGIN);
|
|
323
327
|
if (typeof session.config.cfb2h !== 'string' || !session.config.cfb2h || typeof session.config.FdrFJe !== 'string' || !session.config.FdrFJe)
|
|
324
328
|
throw new SynthIdError('response', 'SynthID page metadata is incomplete');
|
|
325
|
-
endpoint.search = new URLSearchParams({ rpcids:
|
|
329
|
+
endpoint.search = new URLSearchParams({ rpcids: RPC_ID, 'source-path': video ? '/video-detection' : '/image-detection', bl: session.config.cfb2h,
|
|
326
330
|
'f.sid': session.config.FdrFJe, hl: session.config.hl || 'en-US', _reqid: session.nextRequestId(), rt: 'c' }).toString();
|
|
327
|
-
const
|
|
331
|
+
const requestPayload = video
|
|
332
|
+
? [[null, [[[mime, null, null, null, null, null, blobref]]], 0, null, null, null, VIDEO_DEFAULT_FPS]]
|
|
333
|
+
: [[null, [[[mime, null, null, null, null, null, blobref]]], 0]];
|
|
334
|
+
const form = entry.attachWebXsrf(new URLSearchParams({ 'f.req': JSON.stringify([[[RPC_ID, JSON.stringify(requestPayload), null, 'generic']]]) }), session.config);
|
|
328
335
|
const response = await session.request(endpoint.href, { method: 'POST', body: form.toString() + '&', headers: {
|
|
329
336
|
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', 'X-Same-Domain': '1',
|
|
330
337
|
'X-Goog-Ext-525006476-Jspb': JSON.stringify([auth.idToken, null, null, null, null, generated.bgToken]),
|
package/lib/synthid-manual.js
CHANGED
|
@@ -24,7 +24,7 @@ function manualError(error) {
|
|
|
24
24
|
const ORIGIN = 'https://synthid.com';
|
|
25
25
|
const UPLOAD = 'https://content-push.googleapis.com/upload/';
|
|
26
26
|
const TOKEN = 'https://securetoken.googleapis.com/v1/token?key=AIzaSyCjADz3UffE3DF5HZ--7MgVEXrbt6Bgcck';
|
|
27
|
-
const DETECT = ORIGIN + '/_/WatermarkApp/data/batchexecute?rpcids=
|
|
27
|
+
const DETECT = ORIGIN + '/_/WatermarkApp/data/batchexecute?rpcids=vZ4jac&source-path=%2Fimage-detection&hl=en-US&rt=c';
|
|
28
28
|
const DROPZONE = '/synthid-demo-drop-zone/ttl_1d/';
|
|
29
29
|
const WEB_HEADERS = {
|
|
30
30
|
Origin: ORIGIN,
|
|
@@ -207,9 +207,9 @@ export class ManualSynthIdClient {
|
|
|
207
207
|
const blob = await this.upload(image, mime, auth);
|
|
208
208
|
try {
|
|
209
209
|
const media = [mime, null, null, null, null, null, blob];
|
|
210
|
-
const request = JSON.stringify([null, [[media]], 0]);
|
|
210
|
+
const request = JSON.stringify([[null, [[media]], 0]]);
|
|
211
211
|
const result = await this.post(DETECT, {
|
|
212
|
-
body: new URLSearchParams({ 'f.req': JSON.stringify([[['
|
|
212
|
+
body: new URLSearchParams({ 'f.req': JSON.stringify([[['vZ4jac', request, null, 'generic']]]) }),
|
|
213
213
|
headers: {
|
|
214
214
|
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
|
|
215
215
|
'X-Same-Domain': '1',
|
|
@@ -271,7 +271,8 @@ export class ManualSynthIdClient {
|
|
|
271
271
|
const kind = status === 429 ? 'rate-limit'
|
|
272
272
|
: status === 403 ? 'permission'
|
|
273
273
|
: status === 401 || status === 400 && stage === 'auth' ? 'auth'
|
|
274
|
-
: status
|
|
274
|
+
: status === 400 && stage === 'detect' ? 'response'
|
|
275
|
+
: status >= 500 ? 'server' : 'request';
|
|
275
276
|
throw new ManualSynthIdError(kind, `SynthID ${stage} returned HTTP ${status}`, stage === 'detect' && status === 401 ? 16 : status, status === 429 ? retryAfter(response.headers.get('retry-after')) : undefined);
|
|
276
277
|
}
|
|
277
278
|
return { headers: response.headers, text: await response.text() };
|
package/lib/synthid-result.js
CHANGED
|
@@ -106,7 +106,7 @@ export function parseSynthIdResponse(text) {
|
|
|
106
106
|
// after our complete RPC frame so a footer cannot mask a real auth result.
|
|
107
107
|
let frame;
|
|
108
108
|
for (const value of frames(text)) {
|
|
109
|
-
if (Array.isArray(value) && value[0] === 'wrb.fr' && value[1] === '
|
|
109
|
+
if (Array.isArray(value) && value[0] === 'wrb.fr' && value[1] === 'vZ4jac') {
|
|
110
110
|
frame = value;
|
|
111
111
|
break;
|
|
112
112
|
}
|
|
@@ -124,7 +124,10 @@ export function parseSynthIdResponse(text) {
|
|
|
124
124
|
}
|
|
125
125
|
if (typeof frame[2] !== 'string')
|
|
126
126
|
return invalid();
|
|
127
|
-
const
|
|
127
|
+
const outer = json(frame[2]);
|
|
128
|
+
if (!Array.isArray(outer))
|
|
129
|
+
return invalid();
|
|
130
|
+
const payload = outer[0];
|
|
128
131
|
if (!Array.isArray(payload))
|
|
129
132
|
return invalid();
|
|
130
133
|
if (Array.isArray(payload[6]) && payload[6].length) {
|
|
@@ -164,12 +167,14 @@ export function formatSynthId(result, noun = '图片') {
|
|
|
164
167
|
1: `${noun}为空`,
|
|
165
168
|
2: `${noun}分辨率过低`,
|
|
166
169
|
3: `${noun}细节不足`,
|
|
170
|
+
4: `${noun}帧率过低`,
|
|
167
171
|
5: `${noun}质量过低`,
|
|
168
172
|
6: `${noun}可能经过修改,或只在局部使用了 AI`,
|
|
173
|
+
7: `${noun}时长过长`,
|
|
169
174
|
};
|
|
170
175
|
return `无法判断是否为 AI 生成:${reasons[result.reason ?? 0] ?? '没有足够的信息'}。`;
|
|
171
176
|
}
|
|
172
|
-
const sources = { google: 'Google',
|
|
177
|
+
const sources = { apple: 'Apple', google: 'Google', heygen: 'HeyGen', kakao: 'Kakao', nvidia: 'NVIDIA', openai: 'OpenAI' };
|
|
173
178
|
const source = result.source && (Object.hasOwn(sources, result.source.toLowerCase()) ? sources[result.source.toLowerCase()] : result.source);
|
|
174
179
|
return `${noun}是 ${source || 'AI'} 生成`;
|
|
175
180
|
}
|
package/package.json
CHANGED
package/src/synthid-http.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { connectionCode, networkCodeOf, parseSynthIdResponse, SynthIdError, type
|
|
|
7
7
|
import type { LifecycleClient, RequestReference } from './synthid-http-runtime/entry.mjs'
|
|
8
8
|
|
|
9
9
|
const ORIGIN = 'https://synthid.com'
|
|
10
|
+
const RPC_ID = 'vZ4jac'
|
|
11
|
+
const VIDEO_DEFAULT_FPS = 30
|
|
10
12
|
const TOKEN = 'https://securetoken.googleapis.com/v1/token?key=AIzaSyCjADz3UffE3DF5HZ--7MgVEXrbt6Bgcck'
|
|
11
13
|
const CREATE = 'https://waa-pa.clients6.google.com/$rpc/google.internal.waa.v1.Waa/Create'
|
|
12
14
|
const UPLOAD = 'https://content-push.googleapis.com/upload/'
|
|
@@ -190,7 +192,8 @@ export class HttpSynthIdClient {
|
|
|
190
192
|
await response.body?.cancel()
|
|
191
193
|
const status = response.status
|
|
192
194
|
const kind = status === 429 ? 'rate-limit' : status === 401 || stage === 'auth' && status === 400 ? 'auth'
|
|
193
|
-
: status === 403 ? 'permission' : status
|
|
195
|
+
: status === 403 ? 'permission' : status === 400 && stage === 'detect' ? 'response'
|
|
196
|
+
: status >= 500 ? 'server' : 'request'
|
|
194
197
|
throw new SynthIdError(kind, `SynthID ${stage} returned HTTP ${status}`, stage === 'detect' && status === 401 ? 16 : status,
|
|
195
198
|
status === 429 ? retryAfter(response.headers.get('retry-after')) : undefined)
|
|
196
199
|
}
|
|
@@ -293,11 +296,15 @@ export class HttpSynthIdClient {
|
|
|
293
296
|
const uploaded = await request(uploadUrl.href, { method: 'POST', body: image.data,
|
|
294
297
|
headers: { ...headers, 'X-Goog-Upload-Command': 'upload, finalize', 'X-Goog-Upload-Offset': '0' } }, 'upload, finalize')
|
|
295
298
|
if (uploaded.headers.get('x-goog-upload-status') !== 'final' || (await uploaded.text()).trim() !== blobref) throw new SynthIdError('response', 'SynthID upload did not finalize at the generated path')
|
|
299
|
+
const video = mime.startsWith('video/')
|
|
296
300
|
const endpoint = new URL('/_/WatermarkApp/data/batchexecute', ORIGIN)
|
|
297
301
|
if (typeof session.config.cfb2h !== 'string' || !session.config.cfb2h || typeof session.config.FdrFJe !== 'string' || !session.config.FdrFJe) throw new SynthIdError('response', 'SynthID page metadata is incomplete')
|
|
298
|
-
endpoint.search = new URLSearchParams({ rpcids:
|
|
302
|
+
endpoint.search = new URLSearchParams({ rpcids: RPC_ID, 'source-path': video ? '/video-detection' : '/image-detection', bl: session.config.cfb2h,
|
|
299
303
|
'f.sid': session.config.FdrFJe, hl: session.config.hl || 'en-US', _reqid: session.nextRequestId(), rt: 'c' }).toString()
|
|
300
|
-
const
|
|
304
|
+
const requestPayload = video
|
|
305
|
+
? [[null, [[[mime, null, null, null, null, null, blobref]]], 0, null, null, null, VIDEO_DEFAULT_FPS]]
|
|
306
|
+
: [[null, [[[mime, null, null, null, null, null, blobref]]], 0]]
|
|
307
|
+
const form = entry.attachWebXsrf(new URLSearchParams({ 'f.req': JSON.stringify([[[RPC_ID, JSON.stringify(requestPayload), null, 'generic']]]) }), session.config)
|
|
301
308
|
const response = await session.request(endpoint.href, { method: 'POST', body: form.toString() + '&', headers: {
|
|
302
309
|
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', 'X-Same-Domain': '1',
|
|
303
310
|
'X-Goog-Ext-525006476-Jspb': JSON.stringify([auth.idToken, null, null, null, null, generated.bgToken]),
|
package/src/synthid-manual.ts
CHANGED
|
@@ -38,7 +38,7 @@ function manualError(error: unknown): ManualSynthIdError {
|
|
|
38
38
|
const ORIGIN = 'https://synthid.com'
|
|
39
39
|
const UPLOAD = 'https://content-push.googleapis.com/upload/'
|
|
40
40
|
const TOKEN = 'https://securetoken.googleapis.com/v1/token?key=AIzaSyCjADz3UffE3DF5HZ--7MgVEXrbt6Bgcck'
|
|
41
|
-
const DETECT = ORIGIN + '/_/WatermarkApp/data/batchexecute?rpcids=
|
|
41
|
+
const DETECT = ORIGIN + '/_/WatermarkApp/data/batchexecute?rpcids=vZ4jac&source-path=%2Fimage-detection&hl=en-US&rt=c'
|
|
42
42
|
const DROPZONE = '/synthid-demo-drop-zone/ttl_1d/'
|
|
43
43
|
const WEB_HEADERS = {
|
|
44
44
|
Origin: ORIGIN,
|
|
@@ -242,9 +242,9 @@ export class ManualSynthIdClient {
|
|
|
242
242
|
const blob = await this.upload(image, mime, auth)
|
|
243
243
|
try {
|
|
244
244
|
const media = [mime, null, null, null, null, null, blob]
|
|
245
|
-
const request = JSON.stringify([null, [[media]], 0])
|
|
245
|
+
const request = JSON.stringify([[null, [[media]], 0]])
|
|
246
246
|
const result = await this.post(DETECT, {
|
|
247
|
-
body: new URLSearchParams({ 'f.req': JSON.stringify([[['
|
|
247
|
+
body: new URLSearchParams({ 'f.req': JSON.stringify([[['vZ4jac', request, null, 'generic']]]) }),
|
|
248
248
|
headers: {
|
|
249
249
|
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
|
|
250
250
|
'X-Same-Domain': '1',
|
|
@@ -304,6 +304,7 @@ export class ManualSynthIdClient {
|
|
|
304
304
|
const kind = status === 429 ? 'rate-limit'
|
|
305
305
|
: status === 403 ? 'permission'
|
|
306
306
|
: status === 401 || status === 400 && stage === 'auth' ? 'auth'
|
|
307
|
+
: status === 400 && stage === 'detect' ? 'response'
|
|
307
308
|
: status >= 500 ? 'server' : 'request'
|
|
308
309
|
throw new ManualSynthIdError(kind, `SynthID ${stage} returned HTTP ${status}`, stage === 'detect' && status === 401 ? 16 : status,
|
|
309
310
|
status === 429 ? retryAfter(response.headers.get('retry-after')) : undefined)
|
package/src/synthid-result.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Image
|
|
1
|
+
/** Image and video decoding of synthid.com's vZ4jac response. Protocol reference: docs/synthid.md. */
|
|
2
2
|
export type SynthIdResult =
|
|
3
3
|
| { status: 'detected'; source?: string; confidence?: 'very-high' | 'high' | 'medium' }
|
|
4
4
|
| { status: 'not_detected' }
|
|
@@ -104,7 +104,7 @@ export function parseSynthIdResponse(text: string): SynthIdResult {
|
|
|
104
104
|
// after our complete RPC frame so a footer cannot mask a real auth result.
|
|
105
105
|
let frame: unknown[] | undefined
|
|
106
106
|
for (const value of frames(text)) {
|
|
107
|
-
if (Array.isArray(value) && value[0] === 'wrb.fr' && value[1] === '
|
|
107
|
+
if (Array.isArray(value) && value[0] === 'wrb.fr' && value[1] === 'vZ4jac') { frame = value; break }
|
|
108
108
|
}
|
|
109
109
|
if (!frame) return invalid()
|
|
110
110
|
if (frame[2] === null) {
|
|
@@ -117,7 +117,9 @@ export function parseSynthIdResponse(text: string): SynthIdResult {
|
|
|
117
117
|
throw new SynthIdError(kind, `SynthID RPC failed (${code ?? 'unknown'})`, code, retryAfterSeconds)
|
|
118
118
|
}
|
|
119
119
|
if (typeof frame[2] !== 'string') return invalid()
|
|
120
|
-
const
|
|
120
|
+
const outer = json(frame[2])
|
|
121
|
+
if (!Array.isArray(outer)) return invalid()
|
|
122
|
+
const payload = outer[0]
|
|
121
123
|
if (!Array.isArray(payload)) return invalid()
|
|
122
124
|
if (Array.isArray(payload[6]) && payload[6].length) {
|
|
123
125
|
const quota = payload[6][0]
|
|
@@ -153,12 +155,14 @@ export function formatSynthId(result: Exclude<SynthIdResult, { status: 'quota_ex
|
|
|
153
155
|
1: `${noun}为空`,
|
|
154
156
|
2: `${noun}分辨率过低`,
|
|
155
157
|
3: `${noun}细节不足`,
|
|
158
|
+
4: `${noun}帧率过低`,
|
|
156
159
|
5: `${noun}质量过低`,
|
|
157
160
|
6: `${noun}可能经过修改,或只在局部使用了 AI`,
|
|
161
|
+
7: `${noun}时长过长`,
|
|
158
162
|
}
|
|
159
163
|
return `无法判断是否为 AI 生成:${reasons[result.reason ?? 0] ?? '没有足够的信息'}。`
|
|
160
164
|
}
|
|
161
|
-
const sources: Record<string, string> = { google: 'Google',
|
|
165
|
+
const sources: Record<string, string> = { apple: 'Apple', google: 'Google', heygen: 'HeyGen', kakao: 'Kakao', nvidia: 'NVIDIA', openai: 'OpenAI' }
|
|
162
166
|
const source = result.source && (Object.hasOwn(sources, result.source.toLowerCase()) ? sources[result.source.toLowerCase()] : result.source)
|
|
163
167
|
return `${noun}是 ${source || 'AI'} 生成`
|
|
164
168
|
}
|