File size: 9,362 Bytes
cd872f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <link rel="icon" type="image/x-icon" href="data:image/x-icon;,">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>配置管理</title>
  <!-- 引入共享样式 -->
  <link rel="stylesheet" href="/static/shared-styles.css">
  <script src="/static/shared.js"></script>
</head>

<body>
  <h1>配置管理</h1>

  <div class="container">
    <div class="form-group">
      <label>路径:</label>
      <select id="path">
        <option value="/">根路径 (/)</option>
        <option value="/logs">日志页面 (/logs)</option>
        <option value="/config">配置页面 (/config)</option>
        <option value="/tokeninfo">Token 信息页面 (/tokeninfo)</option>
        <option value="/static/shared-styles.css">共享样式 (/static/shared-styles.css)</option>
        <option value="/static/shared.js">共享脚本 (/static/shared.js)</option>
        <option value="/about">关于页面 (/about)</option>
        <option value="/readme">ReadMe文档 (/readme)</option>
        <option value="/api">api调用 (/api)</option>
      </select>
    </div>

    <div class="form-group">
      <label>内容类型:</label>
      <select id="content_type">
        <option value="default">默认</option>
        <option value="text">纯文本</option>
        <option value="html">HTML</option>
      </select>
    </div>

    <div class="form-group">
      <label>内容:</label>
      <textarea id="content"></textarea>
    </div>

    <div class="form-group">
      <label>流第一个块检查:</label>
      <select id="enable_stream_check">
        <option value="">保持不变</option>
        <option value="true">启用</option>
        <option value="false">禁用</option>
      </select>
    </div>

    <div class="form-group">
      <label>包含停止流:</label>
      <select id="include_stop_stream">
        <option value="">保持不变</option>
        <option value="true">启用</option>
        <option value="false">禁用</option>
      </select>
    </div>

    <div class="form-group">
      <label>图片处理能力:</label>
      <select id="vision_ability">
        <option value="">保持不变</option>
        <option value="disabled">禁用</option>
        <option value="base64-only">仅 Base64</option>
        <option value="base64-http">Base64 + HTTP</option>
      </select>
    </div>

    <div class="form-group">
      <label>慢速池:</label>
      <select id="enable_slow_pool">
        <option value="">保持不变</option>
        <option value="true">启用</option>
        <option value="false">禁用</option>
      </select>
    </div>

    <div class="form-group">
      <label>允许所有Claude模型:</label>
      <select id="enable_all_claude">
        <option value="">保持不变</option>
        <option value="true">启用</option>
        <option value="false">禁用</option>
      </select>
    </div>

    <div class="form-group">
      <label>使用量检查模型规则:</label>
      <select id="check_usage_models_type">
        <option value="">保持不变</option>
        <option value="none">禁用</option>
        <option value="default">默认</option>
        <option value="all">所有</option>
        <option value="list">自定义列表</option>
      </select>
      <input type="text" id="check_usage_models_list" placeholder="模型列表,以逗号分隔" style="display: none;">
    </div>

    <div class="form-group">
      <label>认证令牌:</label>
      <input type="password" id="authToken">
    </div>

    <div class="button-group">
      <button onclick="updateConfig('get')">获取配置</button>
      <button onclick="updateConfig('update')">更新配置</button>
      <button onclick="updateConfig('reset')" class="secondary">重置配置</button>
    </div>
  </div>

  <div id="result" class="message"></div>

  <script>
    async function fetchConfig() {
      const path = document.getElementById('path').value;
      const data = await makeAuthenticatedRequest('/config', {
        body: JSON.stringify({ action: 'get', path })
      });

      if (data) {
        let content = '';

        // 获取当前路径的页面内容
        const pageContent = data.data.page_content;

        // 如果是 default 类型,需要从路径获取内容
        if (pageContent?.type === 'default') {
          // 直接从路径获取内容
          const response = await fetch(path);
          content = await response.text();
        } else if (pageContent?.type === 'text' || pageContent?.type === 'html') {
          content = pageContent.content;
        }

        // 更新表单
        document.getElementById('content').value = content || '';
        document.getElementById('content_type').value = pageContent?.type || 'default';
        let visionValue = data.data.vision_ability || '';
        // 标准化 vision_ability 的值
        switch (visionValue) {
          case 'none':
            visionValue = 'disabled';
            break;
          case 'base64':
            visionValue = 'base64-only';
            break;
          case 'all':
            visionValue = 'base64-http';
            break;
        }
        document.getElementById('enable_stream_check').value =
          parseStringFromBoolean(data.data.enable_stream_check, '');
        document.getElementById('include_stop_stream').value =
          parseStringFromBoolean(data.data.include_stop_stream, '');
        document.getElementById('vision_ability').value = visionValue;
        document.getElementById('enable_slow_pool').value =
          parseStringFromBoolean(data.data.enable_slow_pool, '');
        document.getElementById('enable_all_claude').value =
          parseStringFromBoolean(data.data.enable_all_claude, '');
        document.getElementById('check_usage_models_type').value = data.data.check_usage_models?.type || '';
        document.getElementById('check_usage_models_list').value = data.data.check_usage_models?.type === 'list' ? data.data.check_usage_models?.content || '' : document.getElementById('check_usage_models_list').value;
      }
    }

    async function updateConfig(action) {
      if (action === 'get') {
        await fetchConfig();
        return;
      }

      const contentType = document.getElementById('content_type').value;
      const content = document.getElementById('content').value;

      // 根据内容类型构造 content 对象
      let contentObj = { type: 'default' };
      if (action === 'update' && contentType !== 'default') {
        contentObj = {
          type: contentType,
          content: content
        };
      }

      const data = {
        action,
        path: document.getElementById('path').value,
        ...(contentObj && { content: contentObj }),
        ...(document.getElementById('enable_stream_check').value && {
          enable_stream_check: parseBooleanFromString(document.getElementById('enable_stream_check').value)
        }),
        ...(document.getElementById('include_stop_stream').value && {
          include_stop_stream: parseBooleanFromString(document.getElementById('include_stop_stream').value)
        }),
        ...(document.getElementById('vision_ability').value && {
          vision_ability: document.getElementById('vision_ability').value
        }),
        ...(document.getElementById('enable_slow_pool').value && {
          enable_slow_pool: parseBooleanFromString(document.getElementById('enable_slow_pool').value)
        }),
        ...(document.getElementById('enable_all_claude').value && {
          enable_all_claude: parseBooleanFromString(document.getElementById('enable_all_claude').value)
        }),
        ...(document.getElementById('check_usage_models_type').value && {
          check_usage_models: {
            type: document.getElementById('check_usage_models_type').value,
            ...(document.getElementById('check_usage_models_type').value === 'list' && {
              content: document.getElementById('check_usage_models_list').value
            })
          }
        })
      };

      const result = await makeAuthenticatedRequest('/config', {
        body: JSON.stringify(data)
      });

      if (result) {
        showMessage('result', result.message, false);
        if (action === 'update' || action === 'reset') {
          await fetchConfig();
        }
      }
    }

    function showSuccess(message) {
      showMessage('result', message, false);
    }

    function showError(message) {
      showMessage('result', message, true);
    }

    // 添加按钮事件监听
    document.getElementById('path').addEventListener('change', fetchConfig);

    // 更新内容类型变更处理
    document.getElementById('content_type').addEventListener('change', function () {
      const textarea = document.getElementById('content');
      textarea.disabled = this.value === 'default';
    });

    // 初始化 token 处理
    initializeTokenHandling('authToken');

    // 添加使用量检查模型类型变更处理
    document.getElementById('check_usage_models_type').addEventListener('change', function() {
      const input = document.getElementById('check_usage_models_list');
      input.style.display = this.value === 'list' ? 'inline-block' : 'none';
    });
  </script>
</body>

</html>