212dbc4e1d
这是一次大型重构和功能新增: 1. 将原 zen_box 工具重命名为 web_zen_box,调整所有相关路径与配置 2. 新增 web_order_box 原生Web应用的完整资源与部署脚本 3. 新增私人剪贴板后端技能与配套测试脚本 4. 修复订单盒子APP的API地址配置,避免路径重复拼接 5. 新增本地开发跨域白名单支持localhost 6. 清理旧版zen_box的冗余文件
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
// 重置 rateLimitMap(通过重启服务或等待)
|
|
// 这里直接测试单个请求
|
|
const http = require('http')
|
|
const BASE = 'http://localhost:8976'
|
|
const API = `${BASE}/api/v1/ingest/private_clipboard`
|
|
|
|
function post(path, body) {
|
|
return new Promise((resolve, reject) => {
|
|
const data = JSON.stringify(body)
|
|
const req = http.request(`${API}${path}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-API-Id': 'private_clipboard',
|
|
'X-API-Key': 'pcb_nuS0qf-W63qcvAPsrG5ePA',
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
'Content-Length': Buffer.byteLength(data)
|
|
}
|
|
}, (res) => {
|
|
let b = ''
|
|
res.on('data', d => b += d)
|
|
res.on('end', () => resolve({ status: res.statusCode, body: b }))
|
|
})
|
|
req.on('error', reject)
|
|
req.write(data)
|
|
req.end()
|
|
})
|
|
}
|
|
|
|
async function sleep(ms) { return new Promise(r => setTimeout(r, ms)) }
|
|
|
|
async function run() {
|
|
console.log('等待 32 秒让速率限制重置...')
|
|
await sleep(32000)
|
|
|
|
// 1. 英文
|
|
console.log('\n--- Test 1: 英文 ---')
|
|
const r1 = await post('/text', { text: 'hello world' })
|
|
console.log(`Status: ${r1.status}, Body: ${r1.body}`)
|
|
|
|
// 2. 中文
|
|
console.log('\n--- Test 2: 中文 ---')
|
|
const r2 = await post('/text', { text: '你好世界' })
|
|
console.log(`Status: ${r2.status}, Body: ${r2.body}`)
|
|
|
|
// 3. XSS
|
|
console.log('\n--- Test 3: XSS ---')
|
|
const r3 = await post('/text', { text: '<script>alert(1)</script>' })
|
|
console.log(`Status: ${r3.status}, Body: ${r3.body}`)
|
|
|
|
// 4. 特殊字符
|
|
console.log('\n--- Test 4: 特殊字符 & < > ---')
|
|
const r4 = await post('/text', { text: 'Tom & Jerry <best> "movie"' })
|
|
console.log(`Status: ${r4.status}, Body: ${r4.body}`)
|
|
|
|
// 5. 查询验证
|
|
console.log('\n--- Test 5: 查询最近 4 条 ---')
|
|
await new Promise((resolve, reject) => {
|
|
http.get(`${API}/latest?limit=4`, {
|
|
headers: {
|
|
'X-API-Id': 'private_clipboard',
|
|
'X-API-Key': 'pcb_nuS0qf-W63qcvAPsrG5ePA'
|
|
}
|
|
}, (res) => {
|
|
let b = ''
|
|
res.on('data', d => b += d)
|
|
res.on('end', () => {
|
|
try {
|
|
const data = JSON.parse(b)
|
|
data.items.forEach((item, i) => {
|
|
console.log(` [${i}] text_content: "${item.text_content}"`)
|
|
})
|
|
} catch { console.log(`Body: ${b}`) }
|
|
resolve()
|
|
})
|
|
}).on('error', reject)
|
|
})
|
|
}
|
|
|
|
run().catch(console.error)
|