Browse Source

Merge pull request #219 from helloxz/dev

1.1.2
main 1.1.2
xiaoz 5 days ago committed by GitHub
parent
commit
24e2050048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 66
      class/Api.php
  2. 2
      controller/api.php
  3. 6
      data/update.log
  4. 4
      templates/admin/setting/subscribe.php
  5. 2
      templates/default2/assets/index.css
  6. 68
      templates/default2/assets/index.js
  7. 4
      templates/default2/info.json
  8. 2
      version.txt

66
class/Api.php

@ -10,6 +10,11 @@ require("./functions/helper.php");
class Api { class Api {
protected $db; protected $db;
public function __construct($db){ public function __construct($db){
// 获取API服务器缓存
$api_url = $this->getFileCache("api_url");
// 如果API地址为空,则设置API地址
if ($api_url == ""){
// 设置API地址(xiaoz) // 设置API地址(xiaoz)
$api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYueGlhb3oudG9w"); $api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYueGlhb3oudG9w");
// 获取API服务器状态码,超时时间为2s // 获取API服务器状态码,超时时间为2s
@ -19,6 +24,11 @@ class Api {
// 失败了则设置备用API地址(rss) // 失败了则设置备用API地址(rss)
$api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYucnNzLmluaw=="); $api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYucnNzLmluaw==");
} }
// 设置API地址缓存
$this->setFileCache("api_url",$api_url,60 * 60 * 24);
}
// $api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYucnNzLmluaw=="); // $api_url = base64_decode("aHR0cHM6Ly9vbmVuYXYucnNzLmluaw==");
// 设置常量 // 设置常量
define("API_URL",$api_url); define("API_URL",$api_url);
@ -3108,7 +3118,63 @@ class Api {
return $httpCode; return $httpCode;
} }
// 读取缓存
private function getFileCache($key) {
// 定义缓存文件的路径
$cacheDir = __DIR__ . '/cache/';
$filePath = $cacheDir . md5($key) . '.cache';
// 检查文件是否存在
if (file_exists($filePath)) {
// 读取文件内容
$data = unserialize(file_get_contents($filePath));
// 检查是否过期
if ($data['expire'] > time()) {
return $data['value'];
} else {
// 如果过期,删除文件
unlink($filePath);
}
}
// 如果文件不存在或已过期,返回空字符串
return '';
}
// 设置缓存
private function setFileCache($key, $value, $ttl) {
// 定义缓存文件的路径
$cacheDir = __DIR__ . '/cache/';
if (!is_dir($cacheDir)) {
mkdir($cacheDir, 0755, true);
}
$filePath = $cacheDir . md5($key) . '.cache';
// 计算过期时间戳
$expireTime = time() + $ttl;
// 将数据和过期时间一起写入文件
file_put_contents($filePath, serialize(['value' => $value, 'expire' => $expireTime]));
}
// 获取相临的版本
public function getNextVersion(){
$this->auth($token);
// 获取当前版本
$version = trim($_GET['version']);
// 正则判断版本是否合法,只能是数组或.组成
$pattern = "/^[0-9.]+$/";
if( !preg_match($pattern,$version) ) {
echo "0.0.0";
exit;
}
// 请求:https://onenav.xiaoz.top/v1/get_version.php?version=1.1.1
$url = API_URL . '/v1/get_version.php?version=' . $version;
// 设置响应头为text类型
header('Content-Type: text/plain');
// 输出结果
echo curl_get($url);
}
} }

2
controller/api.php

@ -458,7 +458,7 @@ function create_sk($api) {
//获取onenav最新版本号 //获取onenav最新版本号
function get_latest_version() { function get_latest_version() {
try { try {
$curl = curl_init("https://git.xiaoz.me/xiaoz/onenav/raw/branch/main/version.txt"); $curl = curl_init("https://git.xiaoz.org/xiaoz/onenav/raw/branch/main/version.txt");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50"); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50");
curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FAILONERROR, true);

6
data/update.log

@ -1,3 +1,9 @@
2025.03.07
1. 搜索支持Ctrl + Enter提交
2. 新增缓存函数
3. 修复一处BUG
4. 版本检测改为后端获取
2025.03.06 2025.03.06
1. 去除default2主题点击输入框自动清空关键词 1. 去除default2主题点击输入框自动清空关键词
2. 去除default2主题点击搜索按钮自动清空关键词 2. 去除default2主题点击搜索按钮自动清空关键词

4
templates/admin/setting/subscribe.php

@ -144,9 +144,11 @@
//获取可更新版本 //获取可更新版本
function available_version() { function available_version() {
var current_version = $("#current_version").val(); var current_version = $("#current_version").val();
$.get("https://onenav.xiaoz.top/v1/get_version.php",{version:current_version},function(data,status){ $.get("/index.php?c=api&method=getNextVersion",{version:current_version},function(data,status){
// console.log(data);
$("#new_version").val(data); $("#new_version").val(data);
}); });
} }
available_version(); available_version();
//立即更新按钮 //立即更新按钮

2
templates/default2/assets/index.css

File diff suppressed because one or more lines are too long

68
templates/default2/assets/index.js

File diff suppressed because one or more lines are too long

4
templates/default2/info.json

@ -3,8 +3,8 @@
"description": "OneNav目前功能最强大的默认主题,推荐使用。", "description": "OneNav目前功能最强大的默认主题,推荐使用。",
"homepage": "https:\/\/blog.xiaoz.org", "homepage": "https:\/\/blog.xiaoz.org",
"help_url":"https://dwz.ovh/gnae4", "help_url":"https://dwz.ovh/gnae4",
"version": "1.2.6", "version": "1.2.7",
"update": "2025\/03\/06", "update": "2025\/03\/07",
"author": "xiaoz<xiaoz93@outlook.com>", "author": "xiaoz<xiaoz93@outlook.com>",
"screenshot": "https://v.png.pub/imgs/2024/11/27/c01894e5d9e0d850.png", "screenshot": "https://v.png.pub/imgs/2024/11/27/c01894e5d9e0d850.png",
"demo":"https://nav.rss.ink", "demo":"https://nav.rss.ink",

2
version.txt

@ -1 +1 @@
v1.1.1-20250306 v1.1.2-20250307
Loading…
Cancel
Save