nodehub/app/Http/Controllers/Api/v1/FreenodeController.php
2026-05-15 13:22:53 +08:00

86 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Api\v1;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\TomTool\Flow;
use App\Services\TomTool\Telegram\Slave as TeleSlave;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
class FreenodeController extends Controller
{
public function filePut(Request $oRequest)
{
$sObjName = "freenode:filePub";
$oFlow = Flow::make($sObjName);
$aData = $oRequest->all();
$sSubSiteCodeShort = $aData["site_code_short"];
$aRaw = $aData["raw"];
$sDate = date('Ymd');
$sSuffix = "nodes";
$sRawKey = $sDate . $sSuffix;
$sUniqueToken = hash_hmac('sha256', $sRawKey, 'wocaonide');
$sShortToken = Str::substr($sUniqueToken, 0, 16);
$aResult = [];
foreach ($aRaw as $sClient => $sContent) {
if (!$sContent) {
$sMsg = "\n {$sObjName}来空?";
echo $sMsg;
TeleSlave::warn()->send($sMsg);
continue;
}
$sExtension = '.txt';
if ($sClient == "v2ray") {
$sExtension = ".txt";
} else if ($sClient == "clash") {
$sExtension = ".yaml";
}
$sFileSavePath = $sSubSiteCodeShort."/".$sShortToken;
$sFileSaveName = date("Ymd")."-".$sClient.$sExtension;
$sFilePathFull = $sFileSavePath."/".$sFileSaveName;
if (!File::isDirectory($sFileSavePath)) {
File::makeDirectory($sFileSavePath, 0755, true);
}
$xSaveLenth = File::put($sFilePathFull, $sContent);
chmod($sFilePathFull, 0644);
// chmod($sFilePathFull, 0777);
if (!$xSaveLenth) {
$sMsg = "\n {$sObjName}保存file失败";
echo $sMsg;
TeleSlave::warn()->send($sMsg);
continue;
}
$sFileUrl = config("app.url")."/".$sFilePathFull;
if (config("app.is_loc") == false) {
TeleSlave::log()
->enableDetail(false)
->setFileUrl($sFileUrl, "更新ok的".config("app.site_code_short")."{$sSubSiteCodeShort}{$sClient}的长{$xSaveLenth}")
->send();
// if ($oFlow->isFail()) {
// var_dump($oFlow->getResult());
// exit;
// }
}
}
return response()->json($oFlow->done());
}
}