feat: integrate pixel teacher presence and resilient classroom preview

This commit is contained in:
鲨鱼辣椒
2026-09-23 18:23:53 +08:00
parent 12d800ec51
commit 7951cca700
60 changed files with 3313 additions and 180 deletions

View File

@@ -8,7 +8,7 @@ import {
} from '../route-utils';
import { TeacherError } from '../../coding-teacher/config-client';
import type { TeacherScope } from '../../coding-teacher/service';
import type { TeacherSend } from '../../../shared/coding-teacher';
import type { TeacherCheckInInput, TeacherSend } from '../../../shared/coding-teacher';
import { takeTeacherPreviewRevision } from '../../main/app-deep-link';
export async function handleCodingTeacherRoutes(
@@ -26,11 +26,12 @@ export async function handleCodingTeacherRoutes(
const projectTopics = url.pathname.match(
/^\/api\/coding\/projects\/([^/]+)\/(teacher|friend)-topics(?:\/([^/]+))?(?:\/(messages|events|save|requests\/([^/]+)\/cancel))?$/
);
const checkIn = url.pathname.match(/^\/api\/coding\/projects\/([^/]+)\/teacher-check-in$/);
const role = projectTopics?.[2] === 'friend' || url.pathname === '/api/coding/friend/config' ? 'friend' : 'teacher';
const config = url.pathname === '/api/coding/teacher/config' || url.pathname === '/api/coding/friend/config';
const draft = url.pathname === '/api/coding/teacher-preview';
const pending = url.pathname === '/api/coding/teacher-preview/pending-link';
if (!source && !preview && !projectTopics && !config && !draft && !pending) return false;
if (!source && !preview && !projectTopics && !checkIn && !config && !draft && !pending) return false;
if ((config || draft || pending) && req.method !== 'GET') {
sendJson(res, 405, { error: '不支持此操作。' });
return true;
@@ -45,6 +46,14 @@ export async function handleCodingTeacherRoutes(
return true;
}
try {
if (checkIn) {
if (req.method !== 'POST') sendJson(res, 405, { error: '不支持此操作。' });
else sendJson(res, 200, await service.checkIn(
{ projectId: decodeURIComponent(checkIn[1]), sourceId: 'project', role: 'teacher' },
await parseJsonBody<TeacherCheckInInput>(req)
));
return true;
}
if (config && req.method === 'GET') {
sendJson(res, 200, await service.definition(role));
return true;
@@ -74,7 +83,7 @@ export async function handleCodingTeacherRoutes(
return true;
}
if (id && !action && req.method === 'GET') {
sendJson(res, 200, await service.read(scope, id));
sendJson(res, 200, await service.read(scope, id, url.searchParams.get('select') !== 'false'));
return true;
}
if (id && action === 'messages' && req.method === 'POST') {