Update micUploadRoutes.js via upload script - 2026-09-21 00:49:00
This commit is contained in:
parent
c98c027fea
commit
839d799451
|
|
@ -157,7 +157,7 @@ function registerMicUpload(app, server, ctx) {
|
||||||
app.post('/api/mic-upload/sessions', requireAuth, async (req, res) => {
|
app.post('/api/mic-upload/sessions', requireAuth, async (req, res) => {
|
||||||
const id = crypto.randomBytes(8).toString('hex');
|
const id = crypto.randomBytes(8).toString('hex');
|
||||||
const token = crypto.randomBytes(24).toString('hex');
|
const token = crypto.randomBytes(24).toString('hex');
|
||||||
const entry = { session: null, token, wsClients: new Set(), createdAt: Date.now() };
|
const entry = { session: null, token, wsClients: new Set(), createdAt: Date.now(), phase: 'browsing' };
|
||||||
sessions.set(id, entry);
|
sessions.set(id, entry);
|
||||||
|
|
||||||
const session = new MicBrowserSession(id, {
|
const session = new MicBrowserSession(id, {
|
||||||
|
|
@ -175,6 +175,23 @@ function registerMicUpload(app, server, ctx) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 页面刷新/切换菜单后,前端用这个查一下之前的会话还在不在、走到哪一步了,
|
||||||
|
// 在的话直接重连WebSocket接回去,不用重新走一遍登录流程。
|
||||||
|
app.get('/api/mic-upload/sessions/:id', requireAuth, (req, res) => {
|
||||||
|
const entry = sessions.get(req.params.id);
|
||||||
|
if (!entry) return res.status(404).json({ error: '会话不存在或已关闭' });
|
||||||
|
res.json({ ok: true, phase: entry.phase });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 前端点了"已登录,继续"之后调一下,把状态记在后端,这样刷新页面/重连时
|
||||||
|
// 才知道该恢复到"已登录"还是"还在登录页"。
|
||||||
|
app.post('/api/mic-upload/sessions/:id/mark-ready', requireAuth, (req, res) => {
|
||||||
|
const entry = sessions.get(req.params.id);
|
||||||
|
if (!entry) return res.status(404).json({ error: '会话不存在或已关闭' });
|
||||||
|
entry.phase = 'ready';
|
||||||
|
res.json({ ok: true });
|
||||||
|
});
|
||||||
|
|
||||||
app.post('/api/mic-upload/sessions/:id/login', requireAuth, async (req, res) => {
|
app.post('/api/mic-upload/sessions/:id/login', requireAuth, async (req, res) => {
|
||||||
const entry = sessions.get(req.params.id);
|
const entry = sessions.get(req.params.id);
|
||||||
if (!entry) return res.status(404).json({ error: '会话不存在或已关闭' });
|
if (!entry) return res.status(404).json({ error: '会话不存在或已关闭' });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue