Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30af707484 | ||
|
|
f0fe36b42b | ||
|
|
4778ca17d1 | ||
|
|
c06b292139 | ||
|
|
dce1309842 | ||
|
|
7962ada5ae |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
# fnb 项目维护入口
|
||||
|
||||
项目工作先读 GemDocs AI版项目总览、维护协议及 `/Users/hellcat/Documents/GemDocs/AI版/10-项目/fnb.md`。线上事务优先经白色机 SSH;网页与订阅 HTTP 访问须符合 GemDocs 的反代规则。
|
||||
|
||||
订阅检测已独立为 SubCheck,入口见 [SubCheck](/Users/hellcat/Documents/GemCodes/subcheck/AGENTS.md);cfn来源适配与调查见 [CFN.md](/Users/hellcat/Documents/GemCodes/subcheck/docs/CFN.md)。fnb不再保存检测实现。代码、凭据、业务数据及并行修改按当前任务授权处理。
|
||||
@@ -107,7 +107,7 @@ public static function fail(string $sChatCode = 'admin'): self
|
||||
// new
|
||||
public static function notify(string $sChatCode = 'admin'): self
|
||||
{
|
||||
return self::start("fail", $sChatCode);
|
||||
return self::start("notification", $sChatCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -275,51 +275,29 @@ private function _send_master(): Flow
|
||||
$aData = $this->buildDataTom();
|
||||
|
||||
if ($this->enableSlaveQueue) {
|
||||
$oFlow = ServiceHttpQueue::start("telegram_master")->arg($aData)->save();
|
||||
} else {
|
||||
|
||||
$oFlow = Flow::start("_send_master");
|
||||
$sUrlMaSterBase = $_ENV["url_master_base"] ?? "";
|
||||
|
||||
if (!$sUrlMaSterBase) {
|
||||
throw new \Exception("未设置env的url_master_base");
|
||||
}
|
||||
|
||||
$sUrlMasterPost = "https://".$sUrlMaSterBase."/api/telegram/post";
|
||||
|
||||
try {
|
||||
|
||||
$oHttpV2 = HttpV2::make($sUrlMasterPost);
|
||||
|
||||
if ($this->enableAsync) {
|
||||
$oHttpV2 = $oHttpV2->enableAsync();
|
||||
}
|
||||
|
||||
$r = $oHttpV2->enableJsonAs()->setData($aData)->send();
|
||||
|
||||
if ($this->enableAsync) {
|
||||
return $oFlow->sData("async")->done("async");
|
||||
} else {
|
||||
$a = json_decode($r, true);
|
||||
$isDone = $a["isDone"] ?? false;
|
||||
|
||||
if ($isDone) {
|
||||
return $oFlow->done();
|
||||
} else {
|
||||
return $oFlow->fail($r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$oFlow = $oFlow->fail($e->getMessage());
|
||||
}
|
||||
return ServiceHttpQueue::start("telegram_master")->arg($aData)->save();
|
||||
}
|
||||
|
||||
$flow = Flow::start("operations notification");
|
||||
try {
|
||||
$root = dirname(__DIR__, 4);
|
||||
require_once $root . '/ops/AdminNotice.php';
|
||||
$this->operationsEventKey ??= bin2hex(random_bytes(16));
|
||||
$receipts = \LegacyOperations\AdminNotice::submit($root, $aData, $this->operationsEventKey);
|
||||
return $flow->done('TeleHub accepted ' . implode(',', $receipts));
|
||||
} catch (\Throwable $error) {
|
||||
return $flow->fail($error->getMessage());
|
||||
}
|
||||
|
||||
return $oFlow;
|
||||
}
|
||||
|
||||
// 直接从本地发到tg,几乎用不上,都走master了
|
||||
|
||||
private ?string $operationsEventKey = null;
|
||||
|
||||
public function forOperationsQueueRow(int $id): self
|
||||
{
|
||||
$this->operationsEventKey = 'queue.' . $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _send_local(): Flow
|
||||
{
|
||||
if ($this->enableSlaveQueue) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LegacyOperations;
|
||||
|
||||
final class AdminNotice
|
||||
{
|
||||
public static function bot(string $code): string
|
||||
{
|
||||
return match ($code) {
|
||||
'log' => 'log',
|
||||
'warn', 'warning' => 'warning',
|
||||
'fail', 'error' => 'error',
|
||||
'notify', 'notification' => 'notification',
|
||||
'base', 'admin', '' => 'base',
|
||||
default => throw new \DomainException('Unregistered operations notification category'),
|
||||
};
|
||||
}
|
||||
|
||||
public static function submit(string $projectRoot, array $data, string $eventKey): array
|
||||
{
|
||||
$target = (string) ($data['sChatCode'] ?? '');
|
||||
if (!in_array($target, ['', 'base', 'admin'], true) || !empty($data['iChatId']) || !empty($data['sBotToken'])) {
|
||||
throw new \DomainException('Explicit Telegram recipients require their own publisher');
|
||||
}
|
||||
if (!empty($data['sPhotoUrl']) || !empty($data['sFileUrl'])) {
|
||||
throw new \DomainException('Attachments require their original publisher');
|
||||
}
|
||||
$configPath = '/etc/telehub-operations/' . hash('sha256', $projectRoot) . '.json';
|
||||
$config = json_decode((string) @file_get_contents($configPath), true, 16, JSON_THROW_ON_ERROR);
|
||||
$bot = self::bot($data['sBotCode'] ?? '');
|
||||
$text = (string) ($data['sMsg'] ?? '');
|
||||
if (trim($text) === '') {
|
||||
throw new \DomainException('Empty operations notification');
|
||||
}
|
||||
$title = '【' . $config['project'] . '/生产 - 运行通知】' . "\n";
|
||||
$room = 4096 - mb_strlen($title, 'UTF-8');
|
||||
$receipts = [];
|
||||
foreach (mb_str_split($text, $room, 'UTF-8') as $part => $body) {
|
||||
$payload = json_encode(['bot' => $bot, 'target' => 'base', 'text' => $title . $body], JSON_THROW_ON_ERROR);
|
||||
$http = curl_init('https://telehub.gemcook.net/api/v1/messages');
|
||||
curl_setopt_array($http, [
|
||||
CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 4, CURLOPT_TIMEOUT => 15, CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json', 'Accept: application/json',
|
||||
'Authorization: Bearer ' . $config['key'],
|
||||
'Idempotency-Key: ' . $eventKey . '.' . $part,
|
||||
],
|
||||
]);
|
||||
$response = curl_exec($http);
|
||||
$status = curl_getinfo($http, CURLINFO_RESPONSE_CODE);
|
||||
curl_close($http);
|
||||
$receipt = is_string($response) ? (json_decode($response, true)['data'] ?? []) : [];
|
||||
if (!in_array($status, [200, 202], true) || empty($receipt['id'])) {
|
||||
throw new \RuntimeException('TeleHub submission unconfirmed (HTTP ' . $status . ')');
|
||||
}
|
||||
if (in_array($receipt['status'] ?? '', ['failed', 'uncertain', 'cancelled'], true)) {
|
||||
throw new \RuntimeException('TeleHub delivery requires review: ' . $receipt['id']);
|
||||
}
|
||||
$receipts[] = $receipt['id'];
|
||||
}
|
||||
return $receipts;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\TestController;
|
||||
use App\Http\Controllers\Api\v1\Telegram\HookController;
|
||||
use App\Http\Middleware\ApiCheckToken;
|
||||
use App\Http\Controllers\Api\CacheController;
|
||||
use App\Models\Tags;
|
||||
@@ -40,7 +39,6 @@
|
||||
|
||||
//Route::get("/cache/clear", [CacheController::class, 'clear']); // 保留
|
||||
|
||||
Route::any('/api/v1/telegram/hook', [HookController::class, 'cmd']);
|
||||
|
||||
Route::get('/a/{sArticleSlug}.html', [ArticlesController::class, 'show'])
|
||||
->name('article.show');
|
||||
|
||||
Reference in new issue
Block a user