File size: 1,787 Bytes
1c7f2e1
c511d53
1c7f2e1
0bf5c85
1c7f2e1
 
 
 
 
 
 
 
3f45635
 
 
 
 
 
 
 
 
1c7f2e1
c511d53
 
 
 
 
 
1c7f2e1
 
c511d53
 
 
1c7f2e1
 
 
 
3f45635
c511d53
 
 
0bf5c85
3f45635
 
 
c511d53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c7f2e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import axios from 'axios';
import type { OptionsResponse, GradeRequest, GradeResponse, FindAssistantsResponse } from '../types/index';

const API_BASE_URL = import.meta.env.VITE_API_URL || '/api';

const api = axios.create({
  baseURL: API_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
  },
});

// Add password verification interceptor
api.interceptors.request.use((config) => {
  const passwordVerified = sessionStorage.getItem('app_password_verified');
  if (passwordVerified === 'true') {
    config.headers['X-Password-Verified'] = 'true';
  }
  return config;
});

export const gradingApi = {
  /**
   * 取得前端下拉選單選項
   */
  async getOptions(): Promise<OptionsResponse> {
    const response = await api.get<OptionsResponse>('/options');
    return response.data;
  },

  /**
   * 送出批改請求
   */
  async gradeText(request: GradeRequest): Promise<GradeResponse> {
    const response = await api.post<GradeResponse>('/grade', request);
    return response.data;
  },

  /**
   * 驗證密碼
   */
  async verifyPassword(password: string): Promise<{ success: boolean, message?: string }> {
    const response = await axios.post(`${API_BASE_URL}/verify-password`, { password });
    return response.data;
  },

  /**
   * 除錯用:查看所有配置的助手
   */
  async getAssistants(): Promise<any> {
    const response = await api.get('/assistants');
    return response.data;
  },

  /**
   * 根據條件查找匹配的機器人
   */
  async findAssistants(params: {
    language?: string;
    age_group?: string;
    category?: string;
    grading_mode?: string;
  }): Promise<FindAssistantsResponse> {
    const response = await api.get<FindAssistantsResponse>('/find-assistants', { params });
    return response.data;
  },
};