版本号修改

This commit is contained in:
CJACK
2026-04-27 20:12:33 +08:00
parent 0378d8c0a9
commit fb43bd92f5
6 changed files with 223 additions and 49 deletions

View File

@@ -3,14 +3,17 @@
const fs = require('fs');
const path = require('path');
const DEFAULT_CLIENT = Object.freeze({
name: 'DeepSeek',
platform: 'android',
androidApiLevel: '35',
locale: 'zh_CN',
});
const DEFAULT_BASE_HEADERS = Object.freeze({
Host: 'chat.deepseek.com',
'User-Agent': 'DeepSeek/1.8.0 Android/35',
Accept: 'application/json',
'Content-Type': 'application/json',
'x-client-platform': 'android',
'x-client-version': '1.8.0',
'x-client-locale': 'zh_CN',
'accept-charset': 'UTF-8',
});
@@ -29,38 +32,96 @@ const DEFAULT_SKIP_EXACT_PATHS = Object.freeze([
'response/search_status',
]);
function loadSharedConstants() {
const sharedPath = path.resolve(__dirname, '../../internal/deepseek/constants_shared.json');
try {
const raw = fs.readFileSync(sharedPath, 'utf8');
const parsed = JSON.parse(raw);
const baseHeaders = parsed && typeof parsed.base_headers === 'object' && !Array.isArray(parsed.base_headers)
? { ...DEFAULT_BASE_HEADERS, ...parsed.base_headers }
: { ...DEFAULT_BASE_HEADERS };
const skipPatterns = Array.isArray(parsed && parsed.skip_contains_patterns)
? parsed.skip_contains_patterns.filter((v) => typeof v === 'string' && v !== '')
: [...DEFAULT_SKIP_PATTERNS];
const skipExactPaths = Array.isArray(parsed && parsed.skip_exact_paths)
? parsed.skip_exact_paths.filter((v) => typeof v === 'string' && v !== '')
: [...DEFAULT_SKIP_EXACT_PATHS];
return {
baseHeaders,
skipPatterns,
skipExactPaths,
};
} catch (_err) {
return {
baseHeaders: { ...DEFAULT_BASE_HEADERS },
skipPatterns: [...DEFAULT_SKIP_PATTERNS],
skipExactPaths: [...DEFAULT_SKIP_EXACT_PATHS],
};
function asNonEmptyString(value) {
return typeof value === 'string' && value !== '' ? value : '';
}
function normalizeClient(raw) {
const client = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
return {
name: asNonEmptyString(client.name) || DEFAULT_CLIENT.name,
platform: asNonEmptyString(client.platform) || DEFAULT_CLIENT.platform,
version: asNonEmptyString(client.version),
androidApiLevel: asNonEmptyString(client.android_api_level) || DEFAULT_CLIENT.androidApiLevel,
locale: asNonEmptyString(client.locale) || DEFAULT_CLIENT.locale,
};
}
function buildBaseHeaders(parsed, client) {
const rawBaseHeaders = parsed && typeof parsed.base_headers === 'object' && !Array.isArray(parsed.base_headers)
? parsed.base_headers
: {};
const baseHeaders = { ...DEFAULT_BASE_HEADERS, ...rawBaseHeaders };
if (client.name && client.version) {
const androidSuffix = client.platform === 'android' && client.androidApiLevel
? ` Android/${client.androidApiLevel}`
: '';
baseHeaders['User-Agent'] = `${client.name}/${client.version}${androidSuffix}`;
}
if (client.platform) {
baseHeaders['x-client-platform'] = client.platform;
}
if (client.version) {
baseHeaders['x-client-version'] = client.version;
}
if (client.locale) {
baseHeaders['x-client-locale'] = client.locale;
}
return baseHeaders;
}
function sharedConstantsPaths() {
return [
path.resolve(__dirname, '../../deepseek/protocol/constants_shared.json'),
path.resolve(process.cwd(), 'internal/deepseek/protocol/constants_shared.json'),
];
}
function readSharedConstants() {
try {
return require('../../deepseek/protocol/constants_shared.json');
} catch (_err) {
// Fall through to filesystem candidates for test and local execution variants.
}
for (const sharedPath of sharedConstantsPaths()) {
try {
const raw = fs.readFileSync(sharedPath, 'utf8');
return JSON.parse(raw);
} catch (_err) {
// Try the next candidate path; fall back to in-file structural defaults below.
}
}
return {};
}
function loadSharedConstants() {
const parsed = readSharedConstants();
const client = normalizeClient(parsed && parsed.client);
const skipPatterns = Array.isArray(parsed && parsed.skip_contains_patterns)
? parsed.skip_contains_patterns.filter((v) => typeof v === 'string' && v !== '')
: [...DEFAULT_SKIP_PATTERNS];
const skipExactPaths = Array.isArray(parsed && parsed.skip_exact_paths)
? parsed.skip_exact_paths.filter((v) => typeof v === 'string' && v !== '')
: [...DEFAULT_SKIP_EXACT_PATHS];
return {
client,
baseHeaders: buildBaseHeaders(parsed, client),
skipPatterns,
skipExactPaths,
};
}
const shared = loadSharedConstants();
module.exports = {
CLIENT: Object.freeze({ ...shared.client }),
CLIENT_VERSION: shared.client.version,
BASE_HEADERS: Object.freeze(shared.baseHeaders),
SKIP_PATTERNS: Object.freeze(shared.skipPatterns),
SKIP_EXACT_PATHS: new Set(shared.skipExactPaths),
__test: {
buildBaseHeaders,
normalizeClient,
sharedConstantsPaths,
},
};