仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ user/api/cache.php 2.2 KB · 55 行 原始文件
Z zfhsh first commit 1 天前
1<?php
2if(in_array($egn, ['cacheadd','addcache','cacheedit','editcache','cacheupdate','setcache','cache'], true)) {
3 $suffix = trim($_POST['suffix'] ?? ($_POST['ext'] ?? ''));
4 $time_out = trim($_POST['time_out'] ?? ($_POST['time'] ?? '30d'));
5 $old_suffix = trim($_POST['old_suffix'] ?? '');
6 if ($suffix === '') {
7 json_exit('请输入文件后缀');
8 return;
9 }
10 if (!preg_match('/^[A-Za-z0-9_,|-]+$/', $suffix)) {
11 json_exit('文件后缀格式错误,仅允许字母、数字、逗号、竖线、中划线和下划线');
12 return;
13 }
14 if ($old_suffix !== '' && !preg_match('/^[A-Za-z0-9_,|-]+$/', $old_suffix)) {
15 json_exit('原文件后缀格式错误');
16 return;
17 }
18 if (!preg_match('/^\d+[smhdMy]$/', $time_out)) {
19 json_exit('缓存时间格式错误,例如:30d、12h、60m、3600s');
20 return;
21 }
22 include_once("../class.php");
23 $api = new bt_api($btipe,$btkeye);
24 $result = $api->set_static_cache($yhc['sqldz'], $suffix, $time_out, $old_suffix);
25 if (isset($result['status']) && ($result['status'] === true || $result['status'] === 'true')) {
26 $action = (in_array($egn, ['cacheedit','editcache','cacheupdate','setcache'], true) || $old_suffix !== '') ? '修改' : '新增';
27 logjl($yhc['user'], '缓存配置', $action.'缓存规则: '.$suffix.' => '.$time_out, '操作成功', $DB);
28 json_exit($action.'成功');
29 } else {
30 json_exit('操作失败:'.($result['msg'] ?? '未知错误'));
31 }
32 return;
33}
34
35if(in_array($egn, ['cachedel','delcache','cachedelete','deletecache','cache_del','cache_delete'], true)) {
36 $suffix = trim($_POST['suffix'] ?? ($_POST['ext'] ?? ''));
37 if ($suffix === '') {
38 json_exit('参数错误');
39 return;
40 }
41 if (!preg_match('/^[A-Za-z0-9_,|-]+$/', $suffix)) {
42 json_exit('文件后缀格式错误');
43 return;
44 }
45 include_once("../class.php");
46 $api = new bt_api($btipe,$btkeye);
47 $result = $api->remove_static_cache($yhc['sqldz'], $suffix);
48 if (isset($result['status']) && ($result['status'] === true || $result['status'] === 'true')) {
49 logjl($yhc['user'], '缓存配置', '删除缓存规则: '.$suffix, '删除成功', $DB);
50 json_exit('删除成功');
51 } else {
52 json_exit('操作失败:'.($result['msg'] ?? '未知错误'));
53 }
54 return;
55}