feat(integrations,classisland,server,web,desktop): ClassIsland 联动插件——上报课表与上课状态、下发提醒并回执、教室端推送通道

教室机器上的 ClassIsland 现在可以直接和班级小助手互通:插件走 /api/integrations/classisland/*,用设备令牌(X-ClassIsland-Token,库里只存 sha256)独立鉴权,不占用 JWT 通道。

- 服务端:新增 integrations 模块(上报 / 待弹出 / 回执 / 课表镜像 / 回写),两个迁移(设备令牌表、Class.notificationChannel);通知、叫人、联动页下发统一复用 pushToClassIsland,避免"某个页面发的通知不联动"
- 插件:packages/classisland-plugin(.NET 8,独立于 pnpm workspace)——BridgeService 上报与提醒轮询、ScheduleMapper/ClassPlanWriter 课表镜像、Avalonia 设置页、ClassHelperNotificationProvider 在 ClassIsland 上弹出提醒;本地/内网地址强制直连,躲开系统代理返回的假 404
- 客户端:设置页可选提醒通道(both / client / classisland),并订阅相应实时事件
- Web 端:新增「ClassIsland 联动」页(设备管理与提醒下发)
- 校验与打包:verify:classisland(需后端)、verify:classisland-plugin(静态契约 54 项)、build/dist:classisland-plugin 产出 .cipx
- 文档:README 与 AGENTS.md 同步新增联动说明,docs/screenshots/classisland 留三张真机截图

门禁:pnpm lint 0 error、pnpm typecheck 四包通过、verify:classisland-plugin 54/54 通过。运行期仍需在装了 ClassIsland 的机器上实测(步骤见 AGENTS.md §8)。
This commit is contained in:
LoveChengke committed 2026-09-27 14:59:12 +08:00
1 parent fe41ebb7d6
commit d0830f6830
61 files changed
+7026 -93

No files matched your search

@@ -0,0 +1,124 @@
import { z } from 'zod';
import {
WEEK_PARITY_VALUES,
CLASSISLAND_NOTIFICATION_MAX_DURATION,
CLASSISLAND_NOTIFICATION_DEFAULT_DURATION,
} from '@classhelper/shared';
import { booleanFlagSchema, timeSchema } from '../../lib/schemas.js';
/** 1=周一 … 7=周日 */
const dayOfWeekSchema = z.coerce.number().int().min(1).max(7);
export const integrationModeSchema = z.enum(['plugin', 'import']);
export const weekParitySchema = z.enum(WEEK_PARITY_VALUES as unknown as [string, ...string[]]);
/* ------------------------------------------------------------------ Web 管理端 */
export const listDevicesQuerySchema = z.object({
classId: z.string().min(1).optional(),
});
export const createDeviceSchema = z.object({
classId: z.string().min(1, '请选择班级'),
name: z.string().trim().max(40).optional(),
mode: integrationModeSchema.optional(),
/** 是否允许插件把 ClassIsland 的课表回传到本服务 */
syncScheduleToServer: z.boolean().optional(),
/** 是否允许把本班课表镜像回 ClassIsland */
mirrorScheduleToClassIsland: z.boolean().optional(),
});
export const updateDeviceSchema = z.object({
name: z.string().trim().max(40).optional(),
enabled: z.boolean().optional(),
mode: integrationModeSchema.optional(),
syncScheduleToServer: z.boolean().optional(),
mirrorScheduleToClassIsland: z.boolean().optional(),
});
export const deviceIdParamSchema = z.object({ id: z.string().min(1, '缺少设备 id') });
export const sendNotificationSchema = z.object({
classId: z.string().min(1, '请选择班级'),
title: z.string().trim().min(1, '请输入提醒标题').max(120),
content: z.string().trim().min(1, '请输入提醒内容').max(2000),
durationSeconds: z.coerce.number().int().min(1).max(CLASSISLAND_NOTIFICATION_MAX_DURATION).optional(),
speech: booleanFlagSchema,
speechContent: z.string().trim().max(500).optional(),
saveToNotifications: z.boolean().optional(),
priority: z.enum(['LOW', 'NORMAL', 'HIGH', 'URGENT']).optional(),
});
/* ------------------------------------------------------------------ 插件侧(设备令牌鉴权) */
export const reportScheduleEntrySchema = z.object({
dayOfWeek: dayOfWeekSchema,
startTime: timeSchema,
endTime: timeSchema,
subject: z.string().trim().min(1, '科目不能为空').max(40),
teacherName: z.string().trim().max(40).nullish(),
weekParity: weekParitySchema.optional(),
weekCountDiv: z.coerce.number().int().min(0).max(30).optional(),
weekCountDivTotal: z.coerce.number().int().min(0).max(30).optional(),
planName: z.string().trim().max(60).optional(),
});
export const reportTimeLayoutItemSchema = z.object({
index: z.coerce.number().int().min(0).max(200).optional(),
name: z.string().trim().max(40).optional(),
startTime: timeSchema,
endTime: timeSchema,
type: z.enum(['class', 'break', 'divider', 'action']).optional(),
skipped: z.boolean().optional(),
});
export const classIslandReportSchema = z.object({
pluginVersion: z.string().trim().max(40).optional(),
classIslandVersion: z.string().trim().max(40).optional(),
state: z
.object({
inClass: z.boolean().optional(),
subject: z.string().trim().max(40).nullish(),
nextSubject: z.string().trim().max(40).nullish(),
timeState: z.string().trim().max(40).nullish(),
periodStart: timeSchema.nullish(),
periodEnd: timeSchema.nullish(),
week: z.coerce.number().int().min(1).max(60).nullish(),
classPlanLoaded: z.boolean().optional(),
clientTime: z.string().trim().max(40).optional(),
})
.optional(),
schedule: z
.object({
mode: z.enum(['replace', 'merge']).optional(),
entries: z.array(reportScheduleEntrySchema).max(500, '单次上报的课程条目过多'),
})
.nullish(),
timeLayout: z
.object({
name: z.string().trim().max(60).optional(),
mode: z.enum(['replace', 'merge']).optional(),
items: z.array(reportTimeLayoutItemSchema).max(200, '单次上报的节次过多'),
})
.nullish(),
});
/** 插件确认某条提醒已弹出(避免重连后重复补发) */
export const ackNotificationSchema = z.object({
id: z.string().min(1, '缺少提醒 id'),
});
/** 插件上报的默认值集中在这里,避免散落在 service 里 */
export const REPORT_DEFAULTS = {
scheduleMode: 'merge',
timeLayoutMode: 'merge',
timeLayoutName: 'ClassIsland 时间表',
notificationDuration: CLASSISLAND_NOTIFICATION_DEFAULT_DURATION,
} as const;
export type CreateDeviceInput = z.infer<typeof createDeviceSchema>;
export type UpdateDeviceInput = z.infer<typeof updateDeviceSchema>;
export type SendNotificationInput = z.infer<typeof sendNotificationSchema>;
export type ClassIslandReportInput = z.infer<typeof classIslandReportSchema>;
export type ReportScheduleEntry = z.infer<typeof reportScheduleEntrySchema>;
export type ReportTimeLayoutItem = z.infer<typeof reportTimeLayoutItemSchema>;