仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ admin/api/update_setting.php 1.7 KB · 51 行 原始文件
Z zfhsh first commit 1 天前
1<?php
2/**
3 * 系统更新设置(GitHub Release)
4 * setting.php 归外部 API 兼容改造占用,更新相关的配置单独走这个文件
5 */
6if($egn=='upset') {
7 include_once("../MPHX/BL.php");
8 include_once("../MPHX/github_updater.php");
9 include("../cf_up.php");
10
11 $repo = trim((string)($_POST['repo'] ?? ''));
12 if($repo==='') json_exit_error('请填写更新仓库,格式为 owner/repo');
13
14 $mirrors_raw = $_POST['mirrors'] ?? '';
15 if(is_array($mirrors_raw)) {
16 $mirrors = $mirrors_raw;
17 } else {
18 $mirrors = preg_split('/\r\n|\r|\n|,/', (string)$mirrors_raw);
19 }
20 $mirrors = array_values(array_filter(array_map('trim', (array)$mirrors), function($v){ return $v!==''; }));
21
22 // Token 留空表示保持原值,勾选清除才写空;任何场合都不回显明文
23 $token = null;
24 if(!empty($_POST['clear_token'])) {
25 $token = '';
26 } elseif(trim((string)($_POST['github_token'] ?? ''))!=='') {
27 $token = trim((string)$_POST['github_token']);
28 }
29
30 $res = mnbt_updater_save_config($repo, $mirrors, $token);
31 if(!$res['ok']) json_exit_error($res['error']);
32
33 $cfg = mnbt_updater_config();
34 logjl($user ?? '', '系统更新', '更新仓库设为 '.$cfg['repo'].',镜像 '.count($cfg['mirrors']).' 个', '保存成功', $DB);
35 json_exit('保存成功', [
36 'qk' => 1,
37 'repo' => $cfg['repo'],
38 'mirrors' => $cfg['mirrors'],
39 'has_token' => $cfg['github_token']!=='' ? 1 : 0,
40 ]);
41 return;
42}
43if($egn=='upcheck') {
44 include_once("../MPHX/BL.php");
45 include_once("../MPHX/github_updater.php");
46 include("../cf_up.php");
47 // 纯数据载荷,前端直接取字段(与 egn=mnbt 的风格一致)
48 exit(json_encode(mnbt_updater_check(!empty($_POST['force']), 60), JSON_UNESCAPED_UNICODE));
49 return;
50}
51return;