From bb9e20bd9bc1c229e8ec68694a841219076cf739 Mon Sep 17 00:00:00 2001 From: hellcat Date: Tue, 18 Aug 2026 17:58:27 +0800 Subject: [PATCH] no message --- app/Console/Commands/ClearDb.php | 19 ++++ .../Controllers/Api/v1/GithubController.php | 98 +++++++++++++++++++ routes/api.php | 7 +- routes/console.php | 67 ++++++------- 4 files changed, 157 insertions(+), 34 deletions(-) create mode 100755 app/Http/Controllers/Api/v1/GithubController.php diff --git a/app/Console/Commands/ClearDb.php b/app/Console/Commands/ClearDb.php index cfabc6e6..e309d4bf 100755 --- a/app/Console/Commands/ClearDb.php +++ b/app/Console/Commands/ClearDb.php @@ -5,6 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use App\Models\ArticleLikes; +use App\Models\Categories; +use App\Models\Articles; class ClearDb extends Command { @@ -15,11 +17,28 @@ public function handle(): void { $this->info("开始清理过期数据..."); + $this->article(); $this->articleLikes(); $this->info("数据清理完成 !"); } + private function article() + { + $aCateId = Categories::whereIn("sSlug", ["freenode", "shadowrocketids"])->pluck("id")->toArray(); + + if (empty($aCateId)) { + $this->info("没有匹配的分类,跳过清理"); + return; + } + + $sDate = date('Y-m-d', strtotime('-180 days')); + + $i = Articles::whereIn("iCategoryId", $aCateId)->whereDate("created_at", "<", $sDate)->delete(); + + $this->info("清理 {$i} 条数据"); + } + private function articleLikes() { // 1. 确定 30 天前的时间点 diff --git a/app/Http/Controllers/Api/v1/GithubController.php b/app/Http/Controllers/Api/v1/GithubController.php new file mode 100755 index 00000000..46308387 --- /dev/null +++ b/app/Http/Controllers/Api/v1/GithubController.php @@ -0,0 +1,98 @@ +exists(); + + return $bUpd; + + } + + public function getLast() + { +// $sCode = date("Ymd"); + + $aToday = Article::orderBy("id", "desc")->first()->toArray(); + + echo json_encode($aToday); + + } + + + // 始终返回数据,今天没有就是前一天,前一天没有就是异常情况 + public function getFnToday($sDate = false) + { + $sMasterUrl = "https://".$_ENV["url_master_base"]; + $sSiteCodeShort = $_ENV["site_code_short"]; + + $oResponse = Http::withOptions([ + 'verify' => false, // 禁用 SSL 证书检查 + ]) + ->timeout(8) + ->get($sMasterUrl."/api/v1/freenode/url_feed_today/".$sSiteCodeShort); + + $aData = []; + $rcode = 400; + if ($oResponse->successful()) { + $aData = $oResponse->json(); + $rcode = 100; + } + + $aData["code"] = $rcode; + + return $aData; + + + +// echo 1233;exit; +// if (!$sDate) { +// $sDate = date("Ymd"); +// } +// +// $sCode = $sDate; +// +// //// test +// // 20250721 - 23 有数据 +//// $sCode = "20250720"; +// +// $bUpd = Article::where("code", $sCode)->exists(); +// +// if ($bUpd === true) { +// $sCodeTrue = $sCode; +// } else { +// $sCodeTrue = date("Ymd", strtotime("-1 day")); +// } +// +// $sFilePathClash = "sub/".$sCodeTrue."-clash.yaml"; +// $sFilePathV2ray = "sub/".$sCodeTrue."-v2ray.txt"; +// +// $sFileClash = file_get_contents($sFilePathClash); +// $sFileV2ray = file_get_contents($sFilePathV2ray); +// +// $aData = [ +// "code" => "100", +// "clash" => $sFileClash, +// "v2ray" => $sFileV2ray +// ]; +// +// echo json_encode($aData); +// +// exit; + + } + +} diff --git a/routes/api.php b/routes/api.php index a90fc83f..ead25f11 100755 --- a/routes/api.php +++ b/routes/api.php @@ -5,6 +5,11 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\Api\Tg\HookController; use App\Http\Controllers\Api\Nasa\V1\CategoryBaseController as NasaV1CategoryBaseController; +use App\Http\Controllers\Api\v1\GithubController; + +Route::get('/github/todayupd', [GithubController::class, 'todayUpd']); +Route::get('/github/getlast', [GithubController::class, 'getLast']); +Route::get('/github/getfntoday/{date?}', [GithubController::class, 'getFnToday']); Route::prefix('nasa/v1')->middleware('nasa.auth')->group(function () { @@ -19,6 +24,6 @@ Route::put('clone/save', [NasaV1CategoryBaseController::class, 'cloneSave']); Route::get('hit/{id}/{field}', [NasaV1CategoryBaseController::class, 'hit']); }); - + }); diff --git a/routes/console.php b/routes/console.php index 748b8ceb..c46eefdc 100755 --- a/routes/console.php +++ b/routes/console.php @@ -10,39 +10,6 @@ $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); -Artisan::command('db:reCreate {sTableName?}', function ($sTableName = null) { - // 1. 没传参数?直接亮红牌! - if (empty($sTableName)) { - $this->error('错误:必须指定要重建的表名!我可不想乱开火。'); - $this->info('用法示例:php artisan db:reCreate slave_sites'); - return; // 直接撤退,不往下走 - } - - // 2. 确定目标 - $sTable = $sTableName; - - // 3. 检查表是否存在(不存在炸个寂寞?) - if (!Schema::hasTable($sTable)) { - $this->warn("目标表 [{$sTable}] 本就不存在,但我还是会清理迁移记录并尝试重建。"); - } - - // 4. 物理抹除表 - Schema::dropIfExists($sTable); - - // 5. 撕掉迁移记录 - // 针对你的匈牙利命名或标准命名,用 snake 匹配最稳 - $sMatch = Str::snake($sTable); - DB::table('migrations')->where('migration', 'like', "%{$sMatch}%")->delete(); - - $this->warn("已爆破表及记录: {$sTable}"); - - // 6. 重新集结 - $this->comment('正在根据迁移文件重新创建表...'); - Artisan::call('migrate'); - - $this->info("表 [{$sTable}] 重建成功!任务完成!"); -})->purpose('定点爆破并重建指定的表,不带参数不动手'); - // 每周一凌晨 2:00 准时开跑,避开流量高峰 Schedule::command('stat:tags-cloud')->weeklyOn(1, '02:00'); // 没到时间我想测试,如何直接触发 @@ -51,3 +18,37 @@ Schedule::command('clear_db')->dailyAt('03:00'); Schedule::command('article:sync-likes')->everyFiveMinutes(); + + +//Artisan::command('db:reCreate {sTableName?}', function ($sTableName = null) { +// // 1. 没传参数?直接亮红牌! +// if (empty($sTableName)) { +// $this->error('错误:必须指定要重建的表名!我可不想乱开火。'); +// $this->info('用法示例:php artisan db:reCreate slave_sites'); +// return; // 直接撤退,不往下走 +// } +// +// // 2. 确定目标 +// $sTable = $sTableName; +// +// // 3. 检查表是否存在(不存在炸个寂寞?) +// if (!Schema::hasTable($sTable)) { +// $this->warn("目标表 [{$sTable}] 本就不存在,但我还是会清理迁移记录并尝试重建。"); +// } +// +// // 4. 物理抹除表 +// Schema::dropIfExists($sTable); +// +// // 5. 撕掉迁移记录 +// // 针对你的匈牙利命名或标准命名,用 snake 匹配最稳 +// $sMatch = Str::snake($sTable); +// DB::table('migrations')->where('migration', 'like', "%{$sMatch}%")->delete(); +// +// $this->warn("已爆破表及记录: {$sTable}"); +// +// // 6. 重新集结 +// $this->comment('正在根据迁移文件重新创建表...'); +// Artisan::call('migrate'); +// +// $this->info("表 [{$sTable}] 重建成功!任务完成!"); +//})->purpose('定点爆破并重建指定的表,不带参数不动手');