数据文件结构更新

This commit is contained in:
sunson 2024-12-06 18:18:28 +08:00
parent 35100eb2d7
commit 90af7a8d98
3 changed files with 479 additions and 436 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
o/*
.idea/*
db.php

View File

@ -19,6 +19,21 @@ php5.2.x及以上版本均可运行做了很多测试老机都可以轻易
图片分享支持直接连接BBcodeHTMLMarkdown轻松一点即可。
### 以下所有接口提交请用GET方式
美女壁纸接口
输入参数:
getGirlWallpaper 必填
type 可选输出json
调用URL?getGirlWallpaper&type
输出JSON结果
{"code":"0","msg":"成功","url":"http://tutu.rf.gd/o/a/b/abf77b43acb51fec2fd5e7590ebd3750.avif"}
其它情况直接302转向图片网址。
## 官网地址:
https://git.czyx007.cn/sunson/siw

163
index.php
View File

@ -1,53 +1,104 @@
<?php
$base_dir = '/o/';// 以/结束
$web_base = 'http://tutu.rf.gd/o/'; // 图站基地址
$img_dir = '/o/'; // 以/结束;
$img_ext = '.avif'; // 文件默认后辍
$http = "http://";
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
$http = "https://";
}
$base_dir = $http . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
$user = array("chate.store"); // 用户名,可多个
$pwd = array("123456"); // 密码,跟用户对应,请记得更换
if(isset($_GET['phpinfo'])){phpinfo();exit;}
if (isset($_GET['type'])) {
header('Content-Type: application/json');
}
if (isset($_GET['getGirlWallpaper'])) {
if (file_exists('db.php')) {
include ('db.php');
}
if (empty($web_base)) {
$web_base = $http . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . $img_dir;
if (empty($img_ext)) {
$img_ext = '.avif';
}
}
$lines = array_filter(explode("\n", gzuncompress(base64_decode($data))));
$file = chop($lines[array_rand($lines) ]);
$extension = pathinfo($file, PATHINFO_EXTENSION);
if (empty($extension)) {
$file.= $img_ext;
}
if (substr($file, 0, 4) == 'http') {
$url = $file;
} else {
$url = "$web_base" . substr($file, 0, 1) . "/" . substr($file, 1, 1) . "/$file";
}
if (isset($_GET['type'])) {
echo '{"code":"0","msg":"成功","url":"' . $url . '"}';
} else {
header('HTTP/1.1 302 Found');
// 添加Location头部指定重定向的URL
header("Location: " . $url);
}
exit;
}
if (isset($_GET['phpinfo'])) {
phpinfo();
exit;
}
$authorization = false;
$key = array_search($_SERVER['PHP_AUTH_USER'], $user);
if($key !== false && $_SERVER['PHP_AUTH_PW'] ==$pwd[$key]){$auth = true;}
if ($key !== false && $_SERVER['PHP_AUTH_PW'] == $pwd[$key]) {
$auth = true;
}
if (!$auth) {
// 没登录,弹出登录窗口
header("WWW-Authenticate:Basic realm='Private'");
header('HTTP/1.0 401 Unauthorized');
exit;
}
// 处理上传
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$name = $_FILES['file']['name'];
$file_tmp = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
// 检查上传错误,直接提示错误代码
if ($error !== UPLOAD_ERR_OK) {
echo '{"error":"上传失败,错误代码:' . $error . '"}';
exit;
}
// 兼容跨平台路径
$md5 = md5_file($file_tmp);
$up_dir = $base_dir . substr($md5,0,1).'/'.substr($md5,1,1);
$upload_dir = getcwd() . $up_dir;
$up_dir = substr($md5, 0, 1) . '/' . substr($md5, 1, 1);
$upload_dir = getcwd() . $img_dir . $up_dir;
// 检查并创建目录
if (!is_dir($upload_dir)) {
if (!mkdir($upload_dir, 0777, true) && !is_dir($upload_dir)) {
echo '{"error":"无法创建目录:'.$upload_dir.'"}';
echo '{"error":"无法创建目录"}';
exit;
}
// 开始创建index.html
file_put_contents($upload_dir . '/index.html', 'no access');
if(!file_exists(dirname($upload_dir) . '/index.html')){file_put_contents(dirname($upload_dir) . '/index.html', 'no access');}
if(!file_exists(dirname($upload_dir,2) . '/index.html')){file_put_contents(dirname($upload_dir,2) . '/index.html', 'no access');}
if (!file_exists(dirname($upload_dir) . '/index.html')) {
file_put_contents(dirname($upload_dir) . '/index.html', 'no access');
}
}
// 根据文件内容生成MD5文件名这样可以排除重复上传
$FileName = md5_file($file_tmp) . '.' . strtolower(pathinfo($name, PATHINFO_EXTENSION));
// 这里判断下重复文件不移动文件
$target_file = $upload_dir . '/' . $FileName;
if (file_exists($target_file) || move_uploaded_file($file_tmp, $target_file)) {
echo '{"upload_url":"http://'.$_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']).$up_dir .'/'. $FileName.'"}';
echo '{"upload_url":"' . $base_dir . $img_dir . $up_dir . '/' . $FileName . '"}';
// 为提供接口写入DB.php
$lines = array();
if (file_exists('db.php')) {
include ('db.php');
$lines = array_filter(explode("\n", gzuncompress(base64_decode($data))));
}
$lines[] = $FileName;
$data = array_unique($lines);
sort($data);
file_put_contents('db.php', '<?php $data="' . base64_encode(gzcompress(implode("\n", $data), 9)) . '"?>');
} else {
echo '{"error":"写入失败,无法保存文件"}';
}
@ -73,6 +124,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
align-items: center;
flex-direction: column;
}
.background {
position: absolute;
top: 0;
@ -84,15 +136,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
transition: opacity 1s ease-in-out;
opacity: 1;
}
.container {
width: 600px;
overflow: hidden;
}
.file-list {
max-height: 200px;
overflow-y: auto;
margin-bottom: 15px;
}
.file-row {
display: flex;
justify-content: space-between;
@ -101,9 +156,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
border-bottom: 1px solid #ccc;
margin-bottom: 5px;
}
.file-row:last-child {
border-bottom: none;
}
.file-name {
flex-grow: 1;
width: 200px;
@ -111,11 +168,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
text-overflow: ellipsis;
white-space: nowrap;
}
.file-size {
margin-left: 10px;
color: #666;
margin-right: 5px;
}
.progress {
width: 100px;
font-size: 12px;
@ -123,6 +182,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
display: none;
border-radius: 5px;
}
.btn-download, .btn-copy {
color: #ffffff;
width: 50px;
@ -131,12 +191,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
font-size: 14px;
margin-left: 5px;
}
.btn-download {
background-color: #0d6efd;
}
.btn-copy {
background-color: #198754;
}
.status-output {
margin-top: 15px;
height: 30px;
@ -145,12 +208,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
font-weight: 1000;
font-size: 16px;
}
.link-output {
/*margin-top: 20px;
border: 1px solid #ccc;*/
padding: 10px;
display: none; /* 默认隐藏 */
}
.link-output textarea {
width: 100%;
height: 100px;
@ -158,22 +223,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
white-space: pre-wrap; /* 自动换行 */
overflow-wrap: break-word; /* 强制换行 */
}
.copy-all-btn-container {
display: flex;
justify-content: flex-end; /* 使按钮靠右对齐 */
margin-top: 10px; /* 添加上边距 */
}
.nav {
display: flex;
justify-content: center; /* 居中对齐 */
align-items: center; /* 垂直居中 */
gap: 20px; /* 链接之间的间距 */
}
</style>
</head>
<body>
<div class="background" id="background"></div>
<div class="background" id="bg"></div>
<div class="container">
<div class="card">
<div class="card-body">
@ -182,7 +235,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
<form id="uploadForm" enctype="multipart/form-data">
<div class="mb-3">
<label for="files" class="form-label"></label>
<input type="file" class="form-control" id="files" name="files[]" multiple accept="image/jpeg, image/png, image/gif, image/webp, image/avif" required>
<input type="file" class="form-control" id="files" name="files[]" multiple
accept="image/jpeg, image/png, image/gif, image/webp, image/avif" required>
</div>
<button type="submit" class="btn btn-primary w-100" style="font-weight: bold;">开始上传</button>
</form>
@ -196,46 +250,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
<button class="btn btn-success" id="copyAllBtn">复制所有链接</button>
<textarea id="linkText" readonly></textarea>
</div>
<h6 id="formatHint" class="card-title text-center">支持格式: JPEG, PNG, GIF, WEBP, AVIF 最大上传:<?php echo ini_get('upload_max_filesize');?></h6>
<h6 id="formatHint" class="card-title text-center">支持格式: JPEG, PNG, GIF, WEBP, AVIF
最大上传:<?php echo ini_get('upload_max_filesize'); ?></h6>
</div>
</div>
</div>
</div>
<script>
async function setBackgroundImages() {
// 取必应每天的壁纸做背景
var response = await fetch('https://raw.onmicrosoft.cn/Bing-Wallpaper-Action/main/data/zh-CN_all.json');
var data = await response.json();
var images = data.data.map(image => image.url);
var backgroundDiv = document.getElementById('background');
var baseurl = 'https://www.bing.com/';
if (images.length > 0) {
backgroundDiv.style.backgroundImage = 'url(' + baseurl + images[0] + ')';
}
let index = 0;
let currentBackgroundDiv = backgroundDiv;
setInterval(() => {
const nextIndex = (index + 1) % images.length;
const nextBackgroundDiv = document.createElement('div');
nextBackgroundDiv.className = 'background next';
nextBackgroundDiv.style.backgroundImage = 'url(' + baseurl + images[nextIndex] + ')';
document.body.appendChild(nextBackgroundDiv);
nextBackgroundDiv.style.opacity = 0;
setTimeout(() => {
nextBackgroundDiv.style.opacity = 1;
}, 50);
setTimeout(() => {
document.body.removeChild(currentBackgroundDiv);
currentBackgroundDiv = nextBackgroundDiv;
index = nextIndex;
if(index>10)index=0;// 只取前十张
}, 1000);
}, 5000);
}
$(document).ready(function () {
setBackgroundImages();// 设置背景
$.ajax({url:"https://raw.onmicrosoft.cn/Bing-Wallpaper-Action/main/data/zh-CN_all.json",dataType: 'json',success:function(result){
$('#bg').css({"background":"url(https://www.bing.com/"+ result.data[Math.floor(Math.random() * result.data.length)].url +")"});
}}); // 设置背景
// 初始化时显示格式提示
$('#formatHint, #serverWarning, #navLinks').show();
@ -257,6 +282,7 @@ $(document).ready(function () {
$('#linkText').val('');
uploadedLinks = [];
}
// 点击选择文件框时清除输出信息
$('#files').on('click', function () {
clearOutput();
@ -292,6 +318,7 @@ $(document).ready(function () {
event.preventDefault();
var files = $('#files')[0].files;
var fileIndex = 0;
function uploadNextFile() {
if (fileIndex < files.length) {
var formData = new FormData();
@ -335,10 +362,8 @@ $(document).ready(function () {
uploadedLinks.push(result.upload_url);
fileRow.find('.progress-status').text('处理完成');
fileRow.find('.progress').hide();
var linkHtml = `
<a href="${result.upload_url}" target="_blank" class="btn btn-info btn-download">预览</a>
<button class="btn btn-success btn-copy copyButton" data-url="${result.upload_url}">复制</button>
`;
var linkHtml = `<a href="${result.upload_url}" target="_blank" class="btn btn-info btn-download">预览</a>
<button class="btn btn-success btn-copy copyButton" data-url="${result.upload_url}">复制</button>`;
fileRow.append(linkHtml);
setTimeout(function () {
fileRow.find('.progress-status').text('成功上传');
@ -363,15 +388,18 @@ $(document).ready(function () {
$('#statusOutput').text('上传任务操作完成');
$('#files').val(''); // 清空文件选择
}
$('#statusOutput').text(`当前状态: 正在上传 ${files[fileIndex].name}`);
if(fileIndex<files.length-1)$('#statusOutput').text(`当前状态: 正在上传 ${files[fileIndex].name}`);
}
uploadNextFile();
});
function showLinkOutput() {
$('.link-output').show();
$('#linkText').val(uploadedLinks.join('\n')); // 显示所有链接
$('#linkText').scrollTop($('#linkText')[0].scrollHeight);
}
function showAlert(message) {
var tooltip = document.createElement('div');
tooltip.style.position = 'fixed';
@ -455,7 +483,6 @@ $(document).ready(function () {
}, 2200);
});
$(document).on('click', '.copyButton', function () {
var copyText = $(this).data('url');
var tempInput = document.createElement('input');