Skip to content

Commit

Permalink
修复:css、js 文件缓存问题
Browse files Browse the repository at this point in the history
  • Loading branch information
taksssss committed Nov 9, 2024
1 parent abfbe31 commit 70c0c79
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 154 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/sync2gitee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,6 @@ jobs:
script: |
return context.repo.repo;
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract the latest update from CHANGELOG.md and write to version.txt
run: |
latest_update=$(awk '/^## /{if (x) exit; x=1} {print}' CHANGELOG.md)
latest_date=$(echo "$latest_update" | head -n 1 | sed -E 's/## ([0-9]{4})-([0-9]{2})-([0-9]{2})/\1.\2.\3/')
latest_content=$(echo "$latest_update" | tail -n +2)
echo "$latest_date" > epg/assets/version.txt
echo "$latest_content" >> epg/assets/version.txt
- name: Create zip file of the epg folder
run: |
cd epg
zip -r codes.zip *
mv codes.zip ..
- name: Commit the zip file
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add epg/assets/version.txt
git add codes.zip
git commit -m "Update version.txt and add codes.zip"
git push
- name: Mirror the GitHub repos to Gitee
uses: Yikun/hub-mirror-action@master
with:
Expand Down
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 2024-11-08
1. 新增:在线升级
2. 新增:版本号显示
3. 优化:项目名称
## 2024-11-09
1. 修复:css、js 文件缓存问题
2. 优化:部分页面布局
3. 更改:项目名称
4. 移除:在线更新功能

## 2024-11-07
4. 优化:明文密码改用 md5 加密
Expand Down
Binary file removed codes.zip
Binary file not shown.
11 changes: 8 additions & 3 deletions epg/assets/css/manage.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ textarea {
word-break: break-all; /* 允许单词内断行 */
}
textarea[id="gen_list_text"] {
height: 147px;
height: 164px;
}
.form-row {
display: flex;
Expand Down Expand Up @@ -187,15 +187,19 @@ input[type="text"] {
width: 830px;
}
.message-modal-content {
width: 220px;
width: 180px;
height: auto;
text-align: justify;
line-height: 1.6;
}
.channel-bind-epg-modal-content,
.more-setting-modal-content,
.channel-match-modal-content {
.channel-match-modal-content,
.icon-modal-content,
.channel-modal-content,
.epg-modal-content {
width: 600px;
height: 530px;
}
.icon-modal-content {
width: 700px;
Expand Down Expand Up @@ -303,6 +307,7 @@ input[type="text"] {
}
.row textarea {
height: 32px;
line-height: 1.3;
white-space: nowrap; /* 禁止换行 */
scrollbar-width: none; /* 隐藏滚动条 */
}
Expand Down
1 change: 0 additions & 1 deletion epg/assets/defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"ret_default": 0,
"tvmao_default": 0,
"all_chs": 0,
"check_update": 1,
"cache_time": 0,
"db_type": "sqlite",
"gen_list_enable": 0,
Expand Down
7 changes: 5 additions & 2 deletions epg/assets/html/login_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="zh-CN">
<head>
<title>登录</title>
<link rel="stylesheet" type="text/css" href="assets/css/login.css">
</head>
<body>
<div class="container">
Expand All @@ -24,7 +23,7 @@
<!-- 底部显示 -->
<div class="footer">
<a href="https://github.com/taksssss/EPG-Server" style="color: #888; text-decoration: none;">
https://github.com/taksssss/EPG-Server v<?php echo htmlspecialchars($currentVersion); ?>
https://github.com/taksssss/EPG-Server
</a>
</div>

Expand Down Expand Up @@ -64,6 +63,10 @@ function showChangePasswordForm() {
}
}
}

// css 缓存处理
var currentDate = new Date().toISOString().split('T')[0];
document.head.appendChild(Object.assign(document.createElement('link'), {rel: 'stylesheet', href: 'assets/css/login.css?date=' + currentDate}));
</script>
</body>
</html>
30 changes: 14 additions & 16 deletions epg/assets/html/manage_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="zh-CN">
<head>
<title>管理配置</title>
<link rel="stylesheet" type="text/css" href="assets/css/manage.css">
</head>
<body>
<div class="container">
Expand Down Expand Up @@ -77,7 +76,7 @@
<!-- 底部显示 -->
<div class="footer">
<a href="https://github.com/taksssss/EPG-Server" style="color: #888; text-decoration: none;">
https://github.com/taksssss/EPG-Server v<?php echo htmlspecialchars($currentVersion); ?>
https://github.com/taksssss/EPG-Server
</a>
</div>

Expand Down Expand Up @@ -316,37 +315,32 @@
<!-- 第三行 -->
<div class="row">
<div class="column">
<label for="check_update">检查版本更新:</label>
<select id="check_update" name="check_update" required>
<option value="1" <?php if (!isset($Config['check_update']) || $Config['check_update'] == 1) echo 'selected'; ?>></option>
<option value="0" <?php if (isset($Config['check_update']) && $Config['check_update'] == 0) echo 'selected'; ?>></option>
<label for="db_type">数据库:</label>
<select id="db_type" name="db_type" required>
<option value="sqlite" <?php if (!isset($Config['db_type']) || $Config['db_type'] == 'sqlite') echo 'selected'; ?>>SQLite</option>
<option value="mysql" <?php if (isset($Config['db_type']) && $Config['db_type'] == 'mysql') echo 'selected'; ?>>MySQL</option>
</select>
</div>
<div class="column">
<label for="cache_time">缓存时间:</label>
<label for="cache_time">缓存时间(小时):</label>
<select id="cache_time" name="cache_time" required>
<?php for ($h = 0; $h < 24; $h++): ?>
<option value="<?php echo $h; ?>" <?php echo floor($Config['cache_time'] / 3600) == $h ? 'selected' : ''; ?>>
<?php echo $h; ?>
</option>
<?php endfor; ?>
</select>
<label style="margin-left: 5px">小时</label>
</div>
</div>
<div class="column">
<label for="db_type">数据库:</label>
<select id="db_type" name="db_type" required>
<option value="sqlite" <?php if (!isset($Config['db_type']) || $Config['db_type'] == 'sqlite') echo 'selected'; ?>>SQLite</option>
<option value="mysql" <?php if (isset($Config['db_type']) && $Config['db_type'] == 'mysql') echo 'selected'; ?>>MySQL</option>
</select>
<!-- <span id="export" style="color: blue; cursor: pointer;">直播源管理</span> -->
</div>
</div>

<!-- 第四行 -->
<div class="row" style="gap: 10px;">
<div class="column">
<label for="mysql_host">地址:</label>
<textarea id="mysql_host"><?php echo htmlspecialchars($Config['mysql']['host'] ?? ''); ?></textarea>
<textarea id="mysql_host" style="width: 129px; margin-right: 25px;"><?php echo htmlspecialchars($Config['mysql']['host'] ?? ''); ?></textarea>
</div>
<div class="column">
<label for="mysql_dbname">库名:</label>
Expand Down Expand Up @@ -385,7 +379,11 @@
var startTime = <?php echo json_encode($Config['start_time']); ?>;
var endTime = <?php echo json_encode($Config['end_time']); ?>;
var displayMessage = <?php echo json_encode($displayMessage); ?>;

// js、css 缓存处理
var currentDate = new Date().toISOString().split('T')[0];
document.head.appendChild(Object.assign(document.createElement('link'), {rel: 'stylesheet', href: 'assets/css/manage.css?date=' + currentDate}));
document.head.appendChild(Object.assign(document.createElement('script'), {src: 'assets/js/manage.js?date=' + currentDate}));
</script>
<script src="assets/js/manage.js"></script>
</body>
</html>
62 changes: 3 additions & 59 deletions epg/assets/js/manage.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,12 @@
document.addEventListener('DOMContentLoaded', function() {
// 页面加载时检查更新
checkVersionUpdate();

// 预加载数据,减少等待时间
// 页面加载时预加载数据,减少等待时间
showModal('channelbindepg', $popup = false);
showModal('moresetting', $popup = false);
showModal('update', $popup = false);
showModal('cron', $popup = false);
showModal('channel', $popup = false);
});

// 异步请求检查版本
function checkVersionUpdate() {
fetch('manage.php?get_version_update_info=true') // 异步调用 PHP 后端
.then(response => response.json()) // 解析 JSON 格式的返回数据
.then(data => {
if (data.hasUpdate) {
const updateMessage = `检测到新版本:<br>v${data.updateVersion}<br><br>更新内容:<br>${data.updateInfo.join('<br>')}`;
showMessageModal(updateMessage);
var modal = document.getElementById("messageModal");

// 创建两个新的按钮
var upgradeBtn = document.createElement("button");
upgradeBtn.classList.add("button", "button-primary");
upgradeBtn.textContent = "升级";
var ignoreBtn = document.createElement("button");
ignoreBtn.classList.add("button", "button-secondary");
ignoreBtn.textContent = "忽略";
var modalFooter = modal.querySelector(".modal-footer");
modalFooter.appendChild(upgradeBtn);
modalFooter.appendChild(ignoreBtn);

// 为“升级”按钮绑定事件
upgradeBtn.onclick = function() {
modalFooter.removeChild(upgradeBtn);
modalFooter.removeChild(ignoreBtn);
showMessageModal('升级中……<br>请耐心等待……');
fetch('manage.php?update_version=true')
.then(response => response.json()) // 解析 JSON 格式的返回数据
.then(data => {
if (data.updated) {
alert('升级成功!');
window.location.href = 'manage.php';
} else {
alert('升级失败!!!');
}
})
.catch(error => {
alert('升级失败!!!');
});
};

// 为“忽略”按钮绑定事件
ignoreBtn.onclick = function() {
modal.style.display = "none"; // 关闭模态框
modalFooter.removeChild(upgradeBtn);
modalFooter.removeChild(ignoreBtn);
};
}
})
.catch(error => {
console.error('无法检查更新,请稍后重试。', error);
});
}

function handleDbManagement() {
if (document.getElementById('db_type').value === 'mysql') {
var img = new Image();
Expand Down Expand Up @@ -779,7 +723,7 @@ function updateIconListJsonFile(){

// 在提交表单时,将更多设置中的数据包括在表单数据中
document.getElementById('settingsForm').addEventListener('submit', function() {
const fields = ['gen_xml', 'include_future_only', 'ret_default', 'tvmao_default', 'all_chs', 'check_update',
const fields = ['gen_xml', 'include_future_only', 'ret_default', 'tvmao_default', 'all_chs',
'cache_time', 'db_type', 'mysql_host', 'mysql_dbname', 'mysql_username', 'mysql_password', 'gen_list_enable'];

const form = this;
Expand Down
4 changes: 0 additions & 4 deletions epg/assets/version.txt

This file was deleted.

42 changes: 4 additions & 38 deletions epg/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

// 获取 $_POST 中除了 'update' 以外的所有键
$config_keys = array_keys(array_filter($_POST, function($key) {
return !in_array($key, ['update']); // 排除 'update' 和 'xml_urls' 键
return !in_array($key, ['update']);
}, ARRAY_FILTER_USE_KEY));

foreach ($config_keys as $key) {
Expand Down Expand Up @@ -181,48 +181,14 @@

// 确定操作类型
$action_map = [
'get_version_update_info', 'update_version', 'get_update_logs', 'get_cron_logs',
'get_channel', 'get_epg_by_channel', 'get_icon', 'get_channel_bind_epg',
'get_channel_match', 'get_gen_list', 'download_data', 'delete_unused_icons'
'get_update_logs', 'get_cron_logs', 'get_channel', 'get_epg_by_channel',
'get_icon', 'get_channel_bind_epg', 'get_channel_match', 'get_gen_list',
'download_data', 'delete_unused_icons'
];
$action = key(array_intersect_key($_GET, array_flip($action_map))) ?: '';

// 根据操作类型执行不同的逻辑
switch ($action) {
case 'get_version_update_info':
if ($Config['check_update'] ?? true) {
// 尝试读取远程版本信息
$versionUrl = 'https://gitee.com/taksssss/EPG-Server/raw/main/epg/assets/version.txt';
$lines = @file($versionUrl, FILE_IGNORE_NEW_LINES);

// 返回结果,若读取失败则返回错误信息
$dbResponse = $lines ? [
'hasUpdate' => version_compare($currentVersion, $lines[0], '<'),
'updateVersion' => $lines[0],
'updateInfo' => array_slice($lines, 1)
] : '';
} else {
$dbResponse = ['hasUpdate' => false];
}
break;

case 'update_version':
// 下载文件并保存到临时文件
$updateUrl = 'https://gitee.com/taksssss/EPG-Server/raw/main/codes.zip';
if ($zipContent = downloadData($updateUrl)) {
file_put_contents('tmp.zip', $zipContent);

// 解压并删除临时文件
$zip = new ZipArchive();
if ($zip->open('tmp.zip') === TRUE) {
$zip->extractTo('.');
$zip->close();
unlink('tmp.zip');
$dbResponse = ['updated' => true];
}
}
break;

case 'get_update_logs':
// 获取更新日志
$dbResponse = $db->query("SELECT * FROM update_log")->fetchAll(PDO::FETCH_ASSOC);
Expand Down
1 change: 0 additions & 1 deletion epg/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
$iconListDefault = json_decode(file_get_contents(__DIR__ . '/assets/defaultIconList.json'), true) or die("默认图标列表文件解析失败: " . json_last_error_msg());
$iconListMerged = array_merge($iconListDefault, $iconList); // 同一个键,以 iconList 的为准
$serverUrl = (($_SERVER['HTTPS'] ?? '') === 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
$currentVersion = file('assets/version.txt', FILE_IGNORE_NEW_LINES)[0] ?? ''; // 版本号

// 设置时区为亚洲/上海
date_default_timezone_set("Asia/Shanghai");
Expand Down

0 comments on commit 70c0c79

Please sign in to comment.