Skip to content

Commit

Permalink
更友好的安装,新上一些卡片组件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
tsxcw committed Nov 6, 2024
1 parent 9f99adf commit 7a6fedd
Show file tree
Hide file tree
Showing 422 changed files with 3,529 additions and 10,464 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ mtab.zip
/public/dist/
/public/static/exportsTabLink.json
/vendor
xy.pem
/plugins/
/public/browserExt.zip
8 changes: 5 additions & 3 deletions app/AppService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare (strict_types=1);

namespace app;

use think\Service;
Expand All @@ -12,14 +13,15 @@ class AppService extends Service
public function register()
{
// 服务注册
if (!file_exists(public_path() . 'installed.lock')) {//如果没有安装的就提示安装
header("Location:/install.php");
if (!file_exists(public_path() . '/installed.lock')) {//如果没有安装的就提示安装
//如果是/installApp开头的路径一律放行
header('Location:/install.php');
exit();
}
}

public function boot()
{
// 服务启动

}
}
2 changes: 0 additions & 2 deletions app/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ class BaseController

public function __construct(App $app)
{

$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();

}

// 初始化
Expand Down
1 change: 1 addition & 0 deletions app/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function __construct()
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:*');
header('Access-Control-Allow-Headers:*');

$this->encodeType();
parent::__construct();
}
Expand Down
26 changes: 0 additions & 26 deletions app/command/test.php

This file was deleted.

3 changes: 2 additions & 1 deletion app/command/upgrade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare (strict_types=1);

declare(strict_types=1);

namespace app\command;

Expand Down
8 changes: 4 additions & 4 deletions app/common.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
//程序版本号,请勿修改
const app_version = '2.3.3';
const app_version = '2.4.3';
//程序内部更新版本代码,请勿修改
const app_version_code = 235;
const app_version_code = 243;
// 应用公共文件
function validateEmail($email): bool
{
Expand All @@ -29,9 +29,9 @@ function renderToken($t = 'tab'): string
return md5($s);
}

function joinPath($path1, $path2)
function joinPath($path1, $path2='')
{
return preg_replace("#//#", "/", $path1 . $path2);
return preg_replace("#/+/#", "/", $path1 . $path2);
}

function getRealIp(): string
Expand Down
21 changes: 14 additions & 7 deletions app/controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,21 @@ function getServicesStatus(): \think\response\Json
function getUserLine(): \think\response\Json
{
$this->getAdmin();
$result = UserModel::whereMonth('create_time');
$today = new DateTime();
$firstDayOfMonth = new DateTime($today->format('Y-m-01'));
$lastDayOfMonth = new DateTime($today->format('Y-m-t'));
$formatDate = function ($date) {
return $date->format('Y-m-d');
};
$defaultDate = [
$formatDate($firstDayOfMonth),
$formatDate($lastDayOfMonth)
];
$dateSelect = $this->request->post('dateSelect', $defaultDate);
$result = UserModel::whereBetweenTime('create_time', $dateSelect[0], $dateSelect[1]); // 当前月
$result = $result->field('DATE_FORMAT(create_time, "%Y-%m-%d") as time, count(id) as total');
$result = $result->group('time')->select();
return $this->success('ok', $this->render($result));
return $this->success('ok', $this->render($result, $dateSelect[0], $dateSelect[1]));
}

function getHotTab(): \think\response\Json
Expand All @@ -186,18 +197,14 @@ function getHotTab(): \think\response\Json
return $this->success('ok', $list);
}

private function render($arr): array
private function render($arr, $start, $end): array
{
$info = [];
foreach ($arr as $key => $value) {
$info[$value['time']] = $value['total'];
}
$time = [];
$total = [];
//当月的第一天
$start = date('Y-m-01', strtotime(date('Y-m-d')));
//当月的最后一天
$end = date('Y-m-d', strtotime(date('Y-m-01') . ' +1 month -1 day'));
$start_date = new DateTime($start);
$end_date = new DateTime($end);
$interval = new DateInterval('P1D');
Expand Down
94 changes: 60 additions & 34 deletions app/controller/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function getMailCode(): \think\response\Json
} catch (\Exception $e) {
return $this->error($e->getMessage());
}

}
return $this->error('发送失败');
}
Expand Down Expand Up @@ -241,7 +240,6 @@ function getIcon(): \think\response\Json
if ($icon) {
return $this->success(['src' => $icon, 'name' => $title]);
}

} catch (\Exception $e) {
return $this->error('没有抓取到图标');
}
Expand Down Expand Up @@ -341,26 +339,13 @@ private function downloadFile($url, $name)
mkdir($remotePath, 0755, true);
}
try {
$response = $client->request('GET', $url, [
$client->request('GET', $url, [
'sink' => $downloadPath,
'headers' => [
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
]
]);
$realPath = joinPath(public_path(), $path . $name);
$hash = hash_file('md5', $realPath);
$check = FileModel::where('hash', $hash)->find();
if ($check) {
try {
if (joinPath(public_path(), $check['path']) !== $realPath) {
unlink($realPath);
}
} catch (\Exception $e) {
}
return $check['path'];
}
FileModel::addFile($path . $name, $user['user_id'] ?? null);
return $path . $name;
return FileModel::addFile($path . $name, $user['user_id'] ?? null);
} catch (RequestException $e) {
}
return false;
Expand Down Expand Up @@ -392,29 +377,19 @@ function upload(): \think\response\Json
if (empty($file)) {
return $this->error('not File');
}
$maxSize = (double)$this->systemSetting('upload_size', '2');
$calc = $this->request->header("Calc");
$maxSize = (float)$this->systemSetting('upload_size', '2');
if ($file->getSize() > 1024 * 1024 * $maxSize) {
$limit = $maxSize < 1 ? ($maxSize * 1000) . 'KB' : ($maxSize) . 'MB';
return $this->error("文件最大$limit,请压缩后再试");
}
if (in_array(strtolower($file->getOriginalExtension()), ['png', 'jpg', 'jpeg', 'webp', 'ico', 'svg'])) {
// 验证文件并保存
try {
$cdn = $this->systemSetting('assets_host', '/', true);
// 构建保存路径
$savePath = '/images/' . date('Y/m/d');
$hash = Str::random(32);
$fileName = $hash . '.' . $file->getOriginalExtension();
$hash = $file->hash('md5');
$check = FileModel::where('hash', $hash)->find();
if ($check) {
try {
unlink($file->getRealPath());
} catch (\Exception $e) {
}
$dt = ['url' => joinPath($cdn, $check['path'])];
return $this->success($dt);
}
$filePath = Filesystem::disk('images')->putFileAs($savePath, $file, $fileName);
$minPath = '';
if ($type == 'icon' || $type == 'avatar') {
Expand All @@ -426,10 +401,18 @@ function upload(): \think\response\Json
$fp = joinPath(public_path(), $filePath);
$image = new \ImageBack($fp);
$image->resize(400, 0)->save(joinPath(public_path(), $minPath));
FileModel::addFile($minPath, $user['user_id'] ?? null);
$minPath = FileModel::addFile($minPath, $user['user_id'] ?? null);
}
//如果包含裁剪头就裁剪图片
if ($calc) {
$w = (int)explode("x", $calc)[0];
$h = (int)explode("x", $calc)[1];
$fp = joinPath(public_path(), $filePath);
$image = new \ImageBack($fp);
$image->resize($w, $h)->save($fp);
}
FileModel::addFile($filePath, $user['user_id'] ?? null);
return $this->success(['url' => $cdn . $filePath, "minUrl" => joinPath($cdn, $minPath)]);
$filePath = FileModel::addFile($filePath, $user['user_id'] ?? null);
return $this->success(['url' => $filePath, "minUrl" => $minPath, 'filename' => $fileName]);
} catch (\think\exception\ValidateException $e) {
return $this->error($e->getMessage());
// 验证失败,给出错误提示
Expand Down Expand Up @@ -457,8 +440,8 @@ function AdminUpload(): \think\response\Json
$fileName = $hash . '.' . $file->getOriginalExtension();
$filePath = Filesystem::disk('images')->putFileAs($savePath, $file, $fileName);
$cdn = $this->systemSetting('assets_host', '/', true);
FileModel::addFile($filePath, $user['user_id'] ?? null);
return $this->success(['url' => $cdn . $filePath]);
$path = FileModel::addFile($filePath, $user['user_id'] ?? null);
return $this->success(['url' => $cdn . $path]);
} catch (\think\exception\ValidateException $e) {
// 验证失败,给出错误提示
// ...
Expand All @@ -476,4 +459,47 @@ function refresh(): \think\response\Json
}
return $this->error("not login");
}

function cardImages(): \think\response\Json
{
$list = [];
$webPath = '/static/CardBackground/bg/';
$dirPath = public_path($webPath);
$dir = opendir($dirPath);
while (($file = readdir($dir)) !== false) {
if ($file != "." && $file != "..") {
if (is_file(joinPath($dirPath, $file))) {
$list[] = [
"thumbor" => joinPath($webPath, $file),
"url" => joinPath($webPath, $file),
];
}
}
}
//针对文件的创建时间排序
usort($list, function ($a, $b) {
return filemtime(joinPath(public_path(), $b['thumbor'])) - filemtime(joinPath(public_path(), $a['thumbor']));
});
return $this->success($list);
}

function moveFile(): \think\response\Json
{
$this->getAdmin();
$old = $this->request->post("old");
$new = $this->request->post("new");
FileModel::moveFile($old, $new);
return $this->success("文件移动成功");
}

function delImages(): \think\response\Json
{
$this->getAdmin();
$url = $this->request->post('url');
$p = joinPath(public_path(), $url);
if (file_exists($p)) {
FileModel::delFile($url);
}
return $this->success("删除完毕");
}
}
1 change: 0 additions & 1 deletion app/controller/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use app\BaseController;
use app\model\CardModel;
use app\model\SettingModel;

class Card extends BaseController
{
Expand Down
38 changes: 21 additions & 17 deletions app/controller/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,36 @@
use app\model\TabbarModel;
use app\model\UserSearchEngineModel;
use think\facade\Cache;
use think\facade\Db;

class Link extends BaseController
{
public function update(): \think\response\Json
{
$user = $this->getUser(true);
if ($user) {
$link = $this->request->post("link", []);
if ($link) {
$is = LinkModel::where("user_id", $user['user_id'])->find();
if ($is) {
HistoryModel::create(['user_id' => $user['user_id'], 'link' => $is['link'], 'create_time' => date("Y-m-d H:i:s")]); //历史记录备份,用于用户误操作恢复用途
$ids = HistoryModel::where("user_id", $user['user_id'])->order("id", 'desc')->limit(50)->select()->toArray();
$ids = array_column($ids, "id");
HistoryModel::where("user_id", $user['user_id'])->whereNotIn("id", $ids)->delete();
$is->link = $link;
$is->save();
} else {
LinkModel::create(["user_id" => $user['user_id'], "link" => $link]);
$error = "";
try {
if ($user) {
$link = $this->request->post("link", []);
if (is_array($link)) {
$is = LinkModel::where("user_id", $user['user_id'])->find();
if ($is) {
HistoryModel::create(['user_id' => $user['user_id'], 'link' => $is['link'], 'create_time' => date("Y-m-d H:i:s")]); //历史记录备份,用于用户误操作恢复用途
$ids = HistoryModel::where("user_id", $user['user_id'])->order("id", 'desc')->limit(50)->select()->toArray();
$ids = array_column($ids, "id");
HistoryModel::where("user_id", $user['user_id'])->whereNotIn("id", $ids)->delete();
$is->link = $link;
$is->save();
} else {
LinkModel::create(["user_id" => $user['user_id'], "link" => $link]);
}
Cache::delete("Link.{$user['user_id']}");
return $this->success('ok');
}
Cache::delete("Link.{$user['user_id']}");
return $this->success('ok');
}
} catch (\Throwable $th) {
$error = $th->getMessage();
}
return $this->error('保存失败');
return $this->error('保存失败'.$error);
}

public function get(): \think\response\Json
Expand Down
Loading

0 comments on commit 7a6fedd

Please sign in to comment.