diff --git a/app/Http/Controllers/Api/v1/ArticlesController.php b/app/Http/Controllers/Api/v1/ArticlesController.php index 6c3ac6e1..de84e394 100755 --- a/app/Http/Controllers/Api/v1/ArticlesController.php +++ b/app/Http/Controllers/Api/v1/ArticlesController.php @@ -30,6 +30,67 @@ public function find(Request $oRequest) return response()->json($oArticle); } + public function receive(Request $oRequest) + { + $aArticle = $oRequest->input("_raw"); + $sTitle = $aArticle["name"] ?? ""; + $sSchema = $aArticle["schema"] ?? ""; + $sSlug = "m".$aArticle["id"]; + + $sOpt = $aArticle["opt"] ?? "[]"; + $aOpt = json_decode($sOpt, true); + + $iOptIsTop = $aOpt["iIsTop"] ?? 0; + $sOptCategoryName = $aOpt["sCategoryName"] ?? ""; + $sOptTag = $aOpt["tag"] ?? ""; + $aOptTag = explode(",", $sOptTag); + + $oCategory = Categories::where("sName", $sOptCategoryName)->first(); + + if (!$oCategory) { + $sMsg = "不存在的文章分类:{$sOptCategoryName}"; + TeleSlave::fail()->send($sMsg); + exit($sMsg); + } + + $aPutField = [ + "iCategoryId" => $oCategory->id, + "iLikeCount" => $aOpt["iLikeCount"] ?? "skip", + "i7like" => $aOpt["i7like"] ?? "skip", + "i365like" => $aOpt["i365like"] ?? "skip", + "iIsTop" => $aOpt["iIsTop"] ?? "skip", + ]; + + $oArticle = Articles::where("sSlug", $sSlug)->first(); + + if (!$oArticle) { + $oArticle = new Articles(); + $oArticle->sSlug = $sSlug; + } + + foreach ($aPutField as $k => $v) { + if ($v !== "skip") { + $oArticle->{$k} = $v; + } + } + + $oArticle->save(); + + (new TagService())->syncArticleTagsByName($oArticle, $aOptTag); + + $aArticle = $oArticle->toArray(); + unset($aArticle["sContent"]); + unset($aArticle["sTitleSub"]); + $jArticle = json_encode($aArticle, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); + + $sMsg = "文章put成功~\n\n{$jArticle}"; + TeleSlave::notify()->send($sMsg); + + return [ + "isDone" => true, + ]; + } + public function receiveFreenode(Request $oRequest) { @@ -93,3 +154,34 @@ public function receiveFreenode(Request $oRequest) return response()->json($oFlow->done()); } } + + + +//array(13) { +// ["id"]=> +// int(134) +// ["code"]=> +// string(15) "fn_b-1773480551" +// ["name"]=> +// string(1) "1" +// ["schema"]=> +// string(1) "1" +// ["schema_pro"]=> +// NULL +// ["group_code"]=> +// string(4) "fn_b" +// ["cmd"]=> +// string(114) "{"|fn_b|vfnfull|20260314172911|":{"site_code":"vfnfull","cmd":"put","value":"value","date":"2026-03-14 17:29:11"}}" +// ["cmd_log"]=> +// NULL +// ["opt"]=> +// string(95) "{"sCategoryName":"Windows","iIsTop":0,"iLikeCount":0,"i7like":0,"i365like":0,"tag":"clash,ssr"}" +// ["enable_sync"]=> +// int(1) +// ["status"]=> +// int(1) +// ["created_at"]=> +// string(27) "2026-03-14T09:29:11.000000Z" +// ["updated_at"]=> +// string(27) "2026-03-14T09:29:11.000000Z" +//} diff --git a/routes/web.php b/routes/web.php index 59649dc1..273ae628 100755 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ use App\Http\Controllers\Api\v1\FreenodeController as ApiV1FreenodeController; Route::post('/api/article/receive/freenode', [ApiV1ArticlesController::class, 'receiveFreenode']); +Route::post('/api/article/receive', [ApiV1ArticlesController::class, 'receive']); //Route::post('/api/freenode/receive', [ApiV1FreenodeController::class, 'receive']); Route::post('/api/article/find', [ApiV1ArticlesController::class, 'find']);