优化了一些文件 增加多店铺

This commit is contained in:
yml
2026-04-09 01:31:47 +08:00
parent c2ec3aa6d2
commit e4ab1f559e
43 changed files with 1839 additions and 91 deletions
+60
View File
@@ -0,0 +1,60 @@
import { createHttpError } from './http.js'
const LARGE_INTEGER_PATTERN = /(:\s*)(-?\d{16,})(\s*[,}\]])/g
export function parseJsonObject(rawText, { preserveLargeIntegers = false, throwOnError = false } = {}) {
const normalized = String(rawText || '').trim()
if (!normalized) {
return {}
}
try {
const prepared = preserveLargeIntegers ? wrapLargeIntegerLiterals(normalized) : normalized
const parsed = JSON.parse(prepared)
return isPlainObject(parsed) ? parsed : {}
} catch (error) {
if (!throwOnError) {
return {}
}
throw createHttpError('json 参数不是合法 JSON', {
statusCode: 400,
errorCode: 'invalid_json_payload',
cause: error,
})
}
}
export function wrapLargeIntegerLiterals(rawText) {
return String(rawText || '').replace(LARGE_INTEGER_PATTERN, (_match, prefix, digits, suffix) => {
if (!shouldPreserveIntegerToken(digits)) {
return `${prefix}${digits}${suffix}`
}
return `${prefix}"${digits}"${suffix}`
})
}
function shouldPreserveIntegerToken(rawDigits) {
const digits = String(rawDigits || '').trim()
const unsigned = digits.startsWith('-') ? digits.slice(1) : digits
if (!/^\d+$/.test(unsigned)) {
return false
}
if (unsigned.length > 16) {
return true
}
if (unsigned.length < 16) {
return false
}
return unsigned > '9007199254740991'
}
function isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]'
}