Update micUploadRoutes.js via upload script - 2026-09-21 00:31:09
This commit is contained in:
parent
6de65b6cfc
commit
e266e14f1e
|
|
@ -6,11 +6,13 @@
|
||||||
// const { registerMicUpload } = require('./mic-upload/micUploadRoutes');
|
// const { registerMicUpload } = require('./mic-upload/micUploadRoutes');
|
||||||
// registerMicUpload(app, server, {
|
// registerMicUpload(app, server, {
|
||||||
// requireAuth, readData, writeData, callDeepSeekWithRetry, loadAiConfig,
|
// requireAuth, readData, writeData, callDeepSeekWithRetry, loadAiConfig,
|
||||||
|
// encrypt, decrypt,
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// (这几个名字要跟 server.js 里已有的函数对上:requireAuth/readData/writeData/
|
// (这几个名字要跟 server.js 里已有的函数对上:requireAuth/readData/writeData/
|
||||||
// callDeepSeekWithRetry/loadAiConfig 都是 server.js 里已经定义好的,直接传引用
|
// callDeepSeekWithRetry/loadAiConfig/encrypt/decrypt 都是 server.js 里已经定义
|
||||||
// 过来即可,不用改动它们本身。)
|
// 好的,直接传引用过来即可,不用改动它们本身。encrypt/decrypt 是给保存的MIC账号
|
||||||
|
// 密码加密用的,跟 ai-config.json 那套是同一份 AES-256-GCM 实现。)
|
||||||
//
|
//
|
||||||
// 需要 `npm install playwright ws`,并在VPS上跑一次
|
// 需要 `npm install playwright ws`,并在VPS上跑一次
|
||||||
// `npx playwright install --with-deps chromium`(无头浏览器本体,体积较大,
|
// `npx playwright install --with-deps chromium`(无头浏览器本体,体积较大,
|
||||||
|
|
@ -92,7 +94,7 @@ async function generateKeywords(ctx, title, model, log) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerMicUpload(app, server, ctx) {
|
function registerMicUpload(app, server, ctx) {
|
||||||
const { requireAuth, readData, writeData } = ctx;
|
const { requireAuth, readData, writeData, encrypt, decrypt } = ctx;
|
||||||
|
|
||||||
// sessionId -> { session, token, wsClients: Set<ws>, createdAt }
|
// sessionId -> { session, token, wsClients: Set<ws>, createdAt }
|
||||||
const sessions = new Map();
|
const sessions = new Map();
|
||||||
|
|
@ -122,6 +124,34 @@ function registerMicUpload(app, server, ctx) {
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---- MIC账号/密码(加密存储,跟ai-config.json同一套AES-256-GCM)----
|
||||||
|
// GET只返回是否已保存,从不回传明文;密码只在 autofill 接口里解密,且直接
|
||||||
|
// 由后端打进Playwright页面,不经过前端网络请求。
|
||||||
|
|
||||||
|
app.get('/api/mic-upload/credentials', requireAuth, (req, res) => {
|
||||||
|
const data = readData();
|
||||||
|
const cred = data['crm:micCredentials'] || {};
|
||||||
|
res.json({ hasEmail: !!cred.emailEnc, hasPassword: !!cred.passwordEnc });
|
||||||
|
});
|
||||||
|
|
||||||
|
app.put('/api/mic-upload/credentials', requireAuth, (req, res) => {
|
||||||
|
const { email, password } = req.body || {};
|
||||||
|
const data = readData();
|
||||||
|
const cred = data['crm:micCredentials'] || {};
|
||||||
|
if (typeof email === 'string' && email) cred.emailEnc = encrypt(email);
|
||||||
|
if (typeof password === 'string' && password) cred.passwordEnc = encrypt(password);
|
||||||
|
data['crm:micCredentials'] = cred;
|
||||||
|
writeData(data);
|
||||||
|
res.json({ ok: true, hasEmail: !!cred.emailEnc, hasPassword: !!cred.passwordEnc });
|
||||||
|
});
|
||||||
|
|
||||||
|
app.delete('/api/mic-upload/credentials', requireAuth, (req, res) => {
|
||||||
|
const data = readData();
|
||||||
|
delete data['crm:micCredentials'];
|
||||||
|
writeData(data);
|
||||||
|
res.json({ ok: true });
|
||||||
|
});
|
||||||
|
|
||||||
// ---- 会话生命周期 ----
|
// ---- 会话生命周期 ----
|
||||||
|
|
||||||
app.post('/api/mic-upload/sessions', requireAuth, async (req, res) => {
|
app.post('/api/mic-upload/sessions', requireAuth, async (req, res) => {
|
||||||
|
|
@ -156,6 +186,31 @@ function registerMicUpload(app, server, ctx) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 把已保存的账号/密码填进"当前在远程页面里被点中、处于聚焦状态"的输入框。
|
||||||
|
// 密码全程只在服务端解密+发送keydown/insertText,不经过前端网络请求。
|
||||||
|
app.post('/api/mic-upload/sessions/:id/autofill', requireAuth, async (req, res) => {
|
||||||
|
const entry = sessions.get(req.params.id);
|
||||||
|
if (!entry) return res.status(404).json({ error: '会话不存在或已关闭' });
|
||||||
|
const { field } = req.body || {};
|
||||||
|
if (field !== 'email' && field !== 'password') {
|
||||||
|
return res.status(400).json({ error: 'field 必须是 email 或 password' });
|
||||||
|
}
|
||||||
|
const data = readData();
|
||||||
|
const cred = data['crm:micCredentials'] || {};
|
||||||
|
const encKey = field === 'email' ? 'emailEnc' : 'passwordEnc';
|
||||||
|
if (!cred[encKey]) {
|
||||||
|
return res.status(400).json({ error: `还没保存过${field === 'email' ? '账号' : '密码'},先在左侧填好并点保存` });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const value = decrypt(cred[encKey]);
|
||||||
|
await entry.session.typeText(value);
|
||||||
|
entry.session.log(`已填入保存的${field === 'email' ? '账号' : '密码'}`);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (e) {
|
||||||
|
res.status(500).json({ error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 从产品库读数据 -> 生成参数 -> 进入仿造发布页 -> 自动填表(不提交)
|
// 从产品库读数据 -> 生成参数 -> 进入仿造发布页 -> 自动填表(不提交)
|
||||||
app.post('/api/mic-upload/sessions/:id/publish', requireAuth, async (req, res) => {
|
app.post('/api/mic-upload/sessions/:id/publish', requireAuth, async (req, res) => {
|
||||||
const entry = sessions.get(req.params.id);
|
const entry = sessions.get(req.params.id);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue