Skip to content

Commit

Permalink
- 优化二级目录使用
Browse files Browse the repository at this point in the history
  • Loading branch information
icret committed May 7, 2024
1 parent 9f512bc commit 0f89648
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 113 deletions.
2 changes: 1 addition & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<img src="<?php echo $config['login_bg']; ?>" alt="简单图床登陆界面背景图" />
</div>
<div class="formBx">
<form class="form-horizontal" action="/admin/index.php" method="post" onsubmit="return md5_post()">
<form class="form-horizontal" action="index.php" method="post" onsubmit="return md5_post()">
<h2>登录</h2>
<label for="account" class="col-sm-2"></label>
<input type="text" name="user" id="account" class="form-control" value="" placeholder="输入登录账号" autocomplete="off" required="required">
Expand Down
1 change: 0 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Verot\Upload;

require_once __DIR__ . '/../app/function.php';
Expand Down
131 changes: 86 additions & 45 deletions api/public.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,114 @@
<?php

/**
* 图床公共信息查询APi
* 2022年2月22日11:41:38
* 图床公共信息查询API
* 2024年04月07日 08:00:00
* @author Icret
*/

// 定义常量以替换魔术字符串
const TIME_KEY = 'total_time';
const TODAY_UPLOAD_KEY = 'todayUpload';
const YESTERDAY_UPLOAD_KEY = 'yestUpload';
const USAGE_SPACE_KEY = 'usage_space';
const FILENUM_KEY = 'filenum';
const DIRNUM_KEY = 'dirnum';

require_once '../app/chart.php';

// 检查是否开启查询
if ($config['public'] === 0) die('开放数据接口已关闭!');

// 获得get值
$show = (empty($_GET['show'])) ? die('没有参数!') : htmlspecialchars($_GET['show']);
if ($config['public'] === 0) {
http_response_code(403); // 返回403 Forbidden
die('开放数据接口已关闭!');
}

// 检查是否在允许范围内
if (!in_array($show, $config['public_list'])) die('没有权限或参数错误!');
// 获取并验证GET参数
$show = isset($_GET['show']) ? trim($_GET['show']) : '';
if (!$show || !in_array($show, $config['public_list'])) {
http_response_code(400); // 返回400 Bad Request
die('没有权限或参数错误!');
}

// 根据请求返回值
switch ($show) {
try {
// 根据请求返回值
switch ($show) {
// 统计时间
case 'time':
echo read_total_json('total_time');
break;
case 'time':
echo read_total_json(TIME_KEY);
break;

// 今日上传
case 'today':
echo read_total_json('todayUpload');
break;
case 'today':
echo read_total_json(TODAY_UPLOAD_KEY);
break;

// 昨日上传
case 'yesterday':
echo read_total_json('yestUpload');
break;
case 'yesterday':
echo read_total_json(YESTERDAY_UPLOAD_KEY);
break;

// 总空间
case 'total_space':
echo getDistUsed(disk_total_space('.'));
break;
case 'total_space':
echo getDistUsed(disk_total_space('.'));
break;

// 已用空间
case 'used_space':
echo getDistUsed(disk_total_space('.') - disk_free_space('.'));
break;
case 'used_space':
$totalSpace = disk_total_space('.');
if ($totalSpace !== false && is_numeric($totalSpace)) {
$freeSpace = disk_free_space('.');
if ($freeSpace !== false && is_numeric($freeSpace)) {
echo getDistUsed($totalSpace - $freeSpace);
} else {
throw new Exception('无法获取磁盘剩余空间');
}
} else {
throw new Exception('无法获取磁盘总空间');
}
break;

// 剩余空间
case 'free_space':
echo getDistUsed(disk_free_space('/'));
break;
case 'free_space':
$freeSpace = disk_free_space('/');
if ($freeSpace !== false && is_numeric($freeSpace)) {
echo getDistUsed($freeSpace);
} else {
throw new Exception('无法获取磁盘剩余空间');
}
break;

// 图床使用空间
case 'image_used':
echo read_total_json('usage_space');
break;
case 'image_used':
echo read_total_json(USAGE_SPACE_KEY);
break;

// 文件数量
case 'file':
echo read_total_json('filenum');
break;
case 'file':
echo read_total_json(FILENUM_KEY);
break;

// 文件夹数量
case 'dir':
echo read_total_json('dirnum');
break;
case 'month':
foreach (read_chart_total()['number'] as $value)
echo $value;
break;
case 'dir':
echo read_total_json(DIRNUM_KEY);
break;

// 修复"month"分支的逻辑
case 'month':
$chartTotal = read_chart_total();
if (isset($chartTotal['number']) && is_array($chartTotal['number'])) {
foreach ($chartTotal['number'] as $value) {
echo $value;
}
} else {
throw new Exception('无法获取图表总数中的“number”数据');
}
break;

default:
return read_chart_total();
break;
}
default:
echo read_chart_total();
break;
}
} catch (Exception $e) {
http_response_code(500); // 返回500 Internal Server Error
die("发生错误: " . $e->getMessage());
}
2 changes: 1 addition & 1 deletion app/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// 设置html为utf8
header('Content-Type:text/html;charset=utf-8');
// 定义根目录
define('APP_ROOT', str_replace('\\', '/', realpath(dirname(__FILE__) . '/../')));
define('APP_ROOT', str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__) . '/../')));
// 时区设置 https://www.php.net/manual/zh/timezones.php
require_once APP_ROOT . '/config/config.php';
empty($config['timezone']) ? date_default_timezone_set('Asia/Shanghai') : date_default_timezone_set($config['timezone']);
Expand Down
6 changes: 3 additions & 3 deletions app/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function getDel($url, $type)
$url = urldecode(trim($url));

if ($type == 'url') {
$url = $_SERVER['DOCUMENT_ROOT'] . $url;
$url = APP_ROOT . $url;
}
if ($type == 'hash') {
$url = APP_ROOT . $url;
Expand Down Expand Up @@ -643,7 +643,7 @@ function easyimage_delete($url, $type)
$url = urldecode(trim($url));

if ($type == 'url') {
$url = $_SERVER['DOCUMENT_ROOT'] . $url;
$url = APP_ROOT . $url;
}
if ($type == 'hash') {
$url = APP_ROOT . $url;
Expand Down Expand Up @@ -1544,7 +1544,7 @@ function write_upload_logs($filePath, $sourceName, $absolutePath, $fileSize, $fr

// $name = trim(basename($filePath), " \t\n\r\0\x0B"); // 当前图片名称
$log = array(basename($filePath) => array( // 以上传图片名称为Array
'source' => htmlspecialchars($sourceName), // 原始文件名称
'source' => htmlspecialchars($sourceName), // 原始文件名称
'date' => date('Y-m-d H:i:s'), // 上传日期
'ip' => real_ip(), // 上传IP
'port' => $_SERVER['REMOTE_PORT'], // IP端口
Expand Down
2 changes: 1 addition & 1 deletion app/ip2region/Ip2Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function simple($ip)
$geo = $this->memorySearch($ip);
$arr = explode('|', str_replace(['0|'], '|', isset($geo['region']) ? $geo['region'] : ''));
if (($last = array_pop($arr)) === '内网IP') $last = '';
return join('', $arr) . (empty($last) ? '' : "[{$last}]");
return join('', $arr) . (empty($last) ? '' : "{$last}");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/ip2region/XdbSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function search($ip)
// read the vector index block
$buff = $this->read(self::HeaderInfoLength + $idx, 8);
if ($buff === null) {
throw new Exception("failed to read vector index at ${idx}");
throw new Exception("failed to read vector index at {$idx}");
}

$sPtr = self::getLong($buff, 0);
Expand All @@ -147,7 +147,7 @@ function search($ip)
// read the segment index
$buff = $this->read($p, self::SegmentIndexSize);
if ($buff == null) {
throw new Exception("failed to read segment index at ${p}");
throw new Exception("failed to read segment index at {$p}");
}

$sip = self::getLong($buff, 0);
Expand Down
Binary file modified app/ip2region/ip2region.xdb
Binary file not shown.
23 changes: 11 additions & 12 deletions app/thumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
* 2022-1-30 06:35:08
*
* TimThumb参数指南
* 命令 作用 参数 描述
* src 图像URL 告诉TimThumb调整哪个图片
* w 宽度 宽度调整 调整输出图像的宽度
* h 高度 高度调整 调整输出图像的高度
* q 质量 0 - 100 压缩质量,值越大质量越高。不建议高于95
* a 对齐 c, t, l, r, b, tl, tr, bl, br 图像对齐。 c = center, t = top, b = bottom, r = right, l = left。 可以创建对角位置
* zc 缩放/裁剪 0、1、2、3 0:根据传入的值进行缩放(不裁剪), 1:以最合适的比例裁剪和调整大小(裁剪), 2:按比例调整大小,并添加边框(裁剪),3:按比例调整大小,不添加边框(裁剪)
* f 过滤器 太多了 可以改变亮度/对比度;甚至模糊图像
* s 锐化 锐化 使得按比例缩小图片看起来有点;更清晰
* cc 画布上的颜色 十六进制的颜色值(# ffffff) 改变背景颜色。 大多数更改缩放和作物设置时使用,进而可以添加图像边界。
* ct 画布的透明度 true (1) 使用透明而忽略背景颜色
* 命令 作用 参数 描述
* src 源文件 图像URL 告诉TimThumb调整哪个图片
* w 宽度 宽度调整 调整输出图像的宽度
* h 高度 高度调整 调整输出图像的高度
* q 质量 0-100 压缩质量,值越大质量越高。不建议高于95
* a 对齐 c, t, l, r, b, tl, tr, bl, br 图像对齐。 c = center, t = top, b = bottom, r = right, l = left。 可以创建对角位置
* zc 缩放/裁剪 0、1、2、3 0: 根据传入的值进行缩放(不裁剪), 1:以最合适的比例裁剪和调整大小(裁剪), 2:按比例调整大小,并添加边框(裁剪),3:按比例调整大小,不添加边框(裁剪)
* f 过滤器 太多了 可以改变亮度/对比度;甚至模糊图像
* s 锐化 锐化 使得按比例缩小图片看起来有点;更清晰
* cc 画布颜色 #ffffff 改变背景颜色。 大多数更改缩放和作物设置时使用,进而可以添加图像边界。
* ct 画布透明度 true (1) 使用透明而忽略背景颜色
*/

require_once __DIR__ . '/function.php';
Expand Down Expand Up @@ -74,7 +74,6 @@
$config['imgurl'],
);


/**
* 修复无法生成生成webp动态图片的缩略图bug
*/
Expand Down
3 changes: 1 addition & 2 deletions app/viewlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
throw new Exception('<div class="alert alert-info">没有上传日志!<div>');
}
} catch (Exception $e) {
echo $e->getMessage();
require_once APP_ROOT . '/app/footer.php';
exit;
}
Expand Down Expand Up @@ -176,7 +175,7 @@ function(data, status) {
checkImg: '<?php echo strstr('OFF', $v['checkImg']) ? '否' : '是'; ?>',
from: '<?php echo is_string($v['from']) ? "网页" : 'API: ' . $v['from']; ?>',
manage: '<div class="btn-group"><a href="<?php echo rand_imgurl() . $v['path']; ?>" target="_blank" class="btn btn-mini btn-success">查看</a> <a href="/app/info.php?img=<?php echo $v['path']; ?>" target="_blank" class="btn btn-mini">信息</a><a href="#" onclick="ajax_post(\'<?php echo $v['path']; ?>\',\'recycle\')" class="btn btn-mini btn-info">回收</a> <a href="#" onclick="ajax_post(\'<?php echo $v['path']; ?>\',\'delete\')" class="btn btn-mini btn-danger">删除</a></div>',
},
},
<?php endforeach; ?>
]
},
Expand Down

0 comments on commit 0f89648

Please sign in to comment.