feat(teacher): 连接 Yuxi 老师并提供项目与会话只读工具
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
isCurrentWorksSquareAccountBinding,
|
||||
type WorksSquareAccountBinding,
|
||||
} from '../services/works-square-session';
|
||||
import type { TeacherAvailability, TeacherDefinition } from '../../shared/coding-teacher';
|
||||
import type { TeacherAvailability, TeacherDefinition, TeacherCatalog } from '../../shared/coding-teacher';
|
||||
|
||||
export class TeacherError extends Error {
|
||||
constructor(
|
||||
@@ -27,7 +27,8 @@ export function assertTeacherAccount(account: TeacherAccount) {
|
||||
}
|
||||
export async function teacherCloudRequest<T>(
|
||||
account: TeacherAccount,
|
||||
pathname: string
|
||||
pathname: string,
|
||||
method: 'GET' | 'POST' = 'GET'
|
||||
): Promise<T> {
|
||||
assertTeacherAccount(account);
|
||||
const token = await getValidWorksSquareAccessToken();
|
||||
@@ -36,6 +37,7 @@ export async function teacherCloudRequest<T>(
|
||||
const response = await proxyAwareFetch(
|
||||
WORKS_SQUARE_CONFIG.apiBaseUrl.replace(/\/+$/, '') + pathname,
|
||||
{
|
||||
method,
|
||||
headers: { Authorization: 'Bearer ' + token },
|
||||
signal: AbortSignal.timeout(30000),
|
||||
}
|
||||
@@ -69,6 +71,8 @@ export async function currentTeacherAccount(): Promise<TeacherAccount> {
|
||||
}
|
||||
export const teacherAvailability = (account: TeacherAccount) =>
|
||||
teacherCloudRequest<TeacherAvailability>(account, '/api/coding-teacher/config');
|
||||
export const teacherCatalog = (account: TeacherAccount) =>
|
||||
teacherCloudRequest<TeacherCatalog>(account, '/api/coding-teacher/teachers');
|
||||
export const teacherVersion = (account: TeacherAccount, version: number) =>
|
||||
teacherCloudRequest<{ version: number; payload: TeacherDefinition }>(
|
||||
account,
|
||||
|
||||
Reference in New Issue
Block a user