Compare commits

...
Author SHA1 Message Date
Codex a365cde888 Keep free-node publishing active in quiet mode 2026-11-07 14:07:49 +08:00
7 changed files with 30 additions and 102 deletions

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ ## 独立文章发布 API
2026-11-02本地将“综合教程”改为“进阶教程”,地址仍 `/advanced`,并统一桌面/手机顶级栏目图标对齐,尚未发布。当前名称、命令和验收见[栏目导航维护](docs/maintenance/NAVIGATION.md)。
2026-11-03本地新增“暂避风头模式”:暂停免费节点发布更新并隐藏机场广告/推荐,保留旧资源和其他文章。命令 `php artisan site:quiet on|off|status`,当前本地关闭、未发布;唯一实现、权限和验收见[暂避风头模式](docs/maintenance/QUIET_MODE.md)。
2026-11-07起“暂避风头模式”只隐藏机场广告和推荐,免费节点照常发布。命令 `php artisan site:quiet on|off|status`,操作、状态文件和回退见[暂避风头模式](docs/maintenance/QUIET_MODE.md)。
## SEO统一合同(2026-10-31)
+2 -2
View File
@@ -9,7 +9,7 @@
final class QuietMode extends Command
{
protected $signature = 'site:quiet {state=status : on, off, or status}';
protected $description = 'Pause free-node publishing and hide airport promotions without deleting data';
protected $description = 'Hide airport ads and recommendations';
public function handle(): int
{
@@ -36,7 +36,7 @@ public function handle(): int
} finally { if (is_file($temporary)) unlink($temporary); }
\Spatie\ResponseCache\Facades\ResponseCache::clear();
}
$this->info('暂避风头模式:'.(SiteMode::quiet() ? '开启(节点更新暂停,机场广告隐藏)' : '关闭(正常模式)'));
$this->info('暂避风头模式:'.(SiteMode::quiet() ? '开启(机场广告及推荐隐藏,节点照常发布)' : '关闭(正常模式)'));
return self::SUCCESS;
}
}
@@ -48,7 +48,6 @@ public function receive(Request $oRequest)
$aOptTag = explode(",", $sOptTag);
$oCategory = Categories::where("sName", $sOptCategoryName)->first();
\App\Services\SiteMode::assertUpdatesAllowed($oCategory?->sSlug);
if (!$oCategory) {
$sMsg = "不存在的文章分类:{$sOptCategoryName}";
@@ -64,7 +63,6 @@ public function receive(Request $oRequest)
];
$oArticle = Articles::where("sSlug", $sSlug)->first();
if ($oArticle) \App\Services\SiteMode::assertUpdatesAllowed($oArticle->oCategory?->sSlug);
if ($oArticle && \Illuminate\Support\Facades\DB::table('editorial_documents')->where('article_id',$oArticle->id)->exists()) {
abort(409, 'This article is managed by the editorial API');
@@ -188,7 +186,6 @@ public function receiveShadowrocketids(Request $oRequest)
public function receiveFreenode(Request $oRequest)
{
\App\Services\SiteMode::assertUpdatesAllowed('freenode');
$sObjName = "nodehub:article_receive_freenodeV2";
$oFlow = Flow::make($sObjName);
@@ -268,7 +265,6 @@ public function receiveFreenode(Request $oRequest)
public function receiveFreenode_laji(Request $oRequest)
{
\App\Services\SiteMode::assertUpdatesAllowed('freenode');
$sObjName = "nodehub:article_receive_freenode";
$oFlow = Flow::make($sObjName);
-1
View File
@@ -109,7 +109,6 @@ public function scopePublicVisible($query)
protected static function booted()
{
static::saving(function ($article) {
\App\Services\SiteMode::guardArticle($article);
// Historical test fixtures and migration tooling may use the pre-SEO schema.
if (!\Illuminate\Support\Facades\Schema::hasColumn('articles', 'sContentUpdatedAt')) return;
if (!$article->exists || $article->isDirty(['sTitle','sTitleSub','sContent','sThumb','iCategoryId','iStatus','bPageThumb'])) {
+1 -26
View File
@@ -2,10 +2,6 @@
namespace App\Services;
use App\Models\Articles;
use App\Models\Categories;
use Illuminate\Http\Exceptions\HttpResponseException;
final class SiteMode
{
public static function quiet(): bool
@@ -13,28 +9,7 @@ public static function quiet(): bool
$path = config('site_mode.state_path');
if (! $path || ! is_file($path)) return (bool) config('site_mode.quiet', false);
$state = json_decode((string) file_get_contents($path), true);
// An unreadable/invalid operational flag must not silently resume publishing.
// An unreadable/invalid operational flag keeps promotions hidden.
return ! is_array($state) || ! is_bool($state['quiet'] ?? null) || $state['quiet'];
}
public static function assertUpdatesAllowed(?string $type): void
{
if ($type !== 'freenode' || ! self::quiet()) return;
throw new HttpResponseException(response()->json([
'isDone' => false, 'status' => 'paused', 'code' => 'FREE_NODE_UPDATES_PAUSED',
'message' => 'Free node updates are temporarily paused; existing publications are retained.',
], 503, ['Retry-After' => '3600']));
}
public static function guardArticle(Articles $article): void
{
if (! self::quiet()) return;
$fields = ['sSlug','iCategoryId','sTitle','sTitleSub','sContent','sThumb',
'iStatus','created_at','sDisplayPublishedAt','sResourceStatus','iResourceCount'];
if ($article->exists && ! $article->isDirty($fields)) return;
$ids = array_filter([$article->iCategoryId, $article->getRawOriginal('iCategoryId')]);
if ($ids && Categories::whereIn('id', $ids)->where('sSlug', 'freenode')->exists()) {
self::assertUpdatesAllowed('freenode');
}
}
}
+9 -31
View File
@@ -1,10 +1,10 @@
# 暂避风头模式
2026-11-03按用户要求新增统一开关:免费节点暂停更新,机场广告暂时下掉。已Git推送并部署正式cfn,按用户明确要求在生产开启;本地仍关闭。当前发布回执、验收和恢复点见[六项发布记录](SIX_RELEASE_2026-11-03.md)。以下本地测试记录保留当时范围。
2026-11-07起,开启暂避风头模式只隐藏机场广告和推荐。免费节点的新发和覆盖更新沿正常接收流程执行,仍按原有规则校验节点结果。2026-11-03旧版行为及原发布记录见[六项发布记录](SIX_RELEASE_2026-11-03.md)。
## 操作
在本站项目目录运行:
在本站项目目录,以 PHP 运行账号(cfn 为 nginx)执行:
```sh
php artisan site:quiet on
@@ -12,36 +12,14 @@ ## 操作
php artisan site:quiet status
```
- on:阻止免费节点新发布和覆盖更新;隐藏机场随机横幅、推荐表格、已知旧福云推广段与自动推荐跳转。
- off:恢复正常接收与原广告配置,各服务商单独开关/链接/价格/优惠码保持原值。
- status:只读查询。没有给公众网页增加操作入口或状态横幅。
- `on` 隐藏机场横幅、推荐表格、可识别的旧福云推广段和推荐跳转。
- `off` 恢复各服务商的原广告与推荐配置。
- `status` 查询当前状态。
初始无运行状态文件时按 `SITE_QUIET_MODE` 配置,默认false。运行命令后以 `storage/app/private/site-mode.json` 内的布尔值为优先,包括false;不必重启PHP或重建配置缓存。CLI与网页使用同一实例目录,不共享其他实例状态。环境变量只作为不存在文件时的缺省值,不覆盖已有运行选择。
初始按 `SITE_QUIET_MODE` 配置(默认关闭)。运行命令后优先读取实例私有的 `storage/app/private/site-mode.json`,开启和关闭均原子保存为 0600 文件,并清理响应缓存。状态文件损坏或不可读时,广告继续隐藏。发布保留实例现有的状态文件及所有者。
状态文件原子替换、0600,私有目录不存在时0700创建,已确认Git忽略。**发布后须以PHP运行账号执行开关命令**,先核实该账号(已有cfn操作常用nginx),不要用root生成网页进程无法读取的0600文件。状态文件损坏/不可读取时保持暂停与隐藏,不能静默恢复;修复同一文件及所有者后运行off或on并分别核对CLI和页面。
## 验收与回退
开启/关闭会清理响应缓存;既有HTML响应缓存合同本已关闭。切换后新请求生效,已打开的旧页面需刷新。开关保存在项目运行目录,发布不能打包覆盖/删除它。
`QuietModeTest` 验证状态切换、广告和推荐隐藏、节点接收进入正常校验,以及开启状态下节点新建和更新成功。
## 范围与实现
- `app/Services/SiteMode.php` 读取开关,暂停返回HTTP503,JSON `isDone=false / status=paused / code=FREE_NODE_UPDATES_PAUSED`,带 `Retry-After: 3600`。不上报发布成功,不消耗正常发布回执;恢复后由正常上游重试/后续发布执行,不自动重放或补造历史文章。
- 两个免费节点接收方法在解析/Flow/配图调用之前阻断;通用接收在目标分类或原文章为freenode时阻断,不能通过换分类绕过。没有改上游任务/服务或服务器调度。
- 文章Eloquent保存事件补充检查:涉及节点正文、标题、图片、分类、发布时间、资源状态等发布字段时拒绝写入;同样保留旧数据。点赞、浏览等指标允许正常保存。直接绕过模型的SQL/人工运维不属于应用发布开关的保护范围。
- 仅暂停freenode,原文章和订阅仍可访问;小火箭ID、教程、资讯、资源列表和站点导航不停止。
- 随机广告组件及保留的三个旧广告组件均检查开关,关闭时不输出广告模板、图片或noscript广告。
- 推荐模块providers为空,隐藏共用推荐并清理匹配的已知旧推广及自动跳转。只处理明确的旧推广结构,不猜测删除普通正文,账号/订阅复制值与正文数据库不变。
- 该模式不删除数据、不撤下已发布资源、不切换现有SEO规则、域名、证书、图片池、上游服务器或其他项目。
## 验收
- 专项 `QuietModeTest`:5项/51断言通过,覆盖命令双向切换、状态持久化/权限、异常状态、专用及通用入口阻断、换分类绕过、模型新建/更新保护、真实点赞字段保存、其他类型放行、广告/旧推广隐藏、复制值及原文保护、恢复。
- 正常回归:QuietMode、ArticleRecommendations、SEO合同及苹果ID解析共32项/331断言通过;之后仅补充旧组件与真实点赞保存断言,再跑专项5项/51断言通过。测试基类隔离运行站点的开关,避免测试误继承本地暂时启用的状态;初轮未隔离的失败已修正。
- 本地IAB开启实测:首页3个复制按钮保留,随机广告0、推荐表格0、旧推广0;教程正文可读,广告0、推荐0、自动推荐跳转0。截图 `output/quiet-mode-20261103/quiet-on.png`。
- 关闭后同一首页恢复随机广告1、推荐模块1,3个订阅按钮保留。CLI回读明确关闭。未进行实际账号登录、上游真实发稿或线上访问。
- PHP语法与本次diff检查通过,未进行生产构建。
## 发布与回退
本批已按用户明确授权完成Git发布,生产开启;后续变更仍按任务授权执行。相关文件包括SiteMode服务、QuietMode命令、配置、接收器入口、模型保存事件、推荐展示服务、四个广告组件、环境模板与测试/维护入口;不能漏发模型或展示服务。默认缺省关闭,不应随代码发布自动切换生产模式。
回退前关闭模式并核对正常状态,再增量撤销本批调用;不得整文件还原覆盖并行SEO、文章渲染或其他修改。运行状态文件须单独保留/按明确运维操作处理,不以Git回退等同模式切换。
回退到 2026-11-03 旧版且模式开启时,节点发布会再次暂停。回退前按当前生产目标核对模式与节点发布行为,使用 Git 恢复点并保留运行状态文件。
+17 -37
View File
@@ -8,7 +8,7 @@
use App\Services\ArticleRecommendations;
use App\Services\SiteMode;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Exceptions\HttpResponseException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
@@ -51,16 +51,6 @@ protected function tearDown(): void
parent::tearDown();
}
private function paused(callable $action): void
{
try { $action(); $this->fail('Expected paused response.'); }
catch (HttpResponseException $e) {
$this->assertSame(503, $e->getResponse()->getStatusCode());
$this->assertSame('3600', $e->getResponse()->headers->get('Retry-After'));
$this->assertSame('FREE_NODE_UPDATES_PAUSED', json_decode($e->getResponse()->getContent(), true)['code']);
}
}
public function test_command_switch_is_persistent_reversible_and_private(): void
{
$this->assertFalse(SiteMode::quiet());
@@ -75,7 +65,7 @@ public function test_command_switch_is_persistent_reversible_and_private(): void
$this->assertFalse(SiteMode::quiet());
}
public function test_invalid_state_stays_paused_and_environment_fallback_works(): void
public function test_invalid_state_keeps_ads_hidden_and_environment_fallback_works(): void
{
config(['site_mode.quiet'=>true]); $this->assertTrue(SiteMode::quiet());
config(['site_mode.quiet'=>false]);
@@ -83,38 +73,28 @@ public function test_invalid_state_stays_paused_and_environment_fallback_works()
file_put_contents($this->state, '{"quiet":"false"}'); $this->assertTrue(SiteMode::quiet());
}
public function test_receivers_pause_before_images_flows_and_any_database_write(): void
public function test_free_node_receiver_runs_normal_validation_with_ads_hidden(): void
{
config(['site_mode.quiet'=>true]);
$controller = new ArticlesController();
$this->paused(fn () => $controller->receiveFreenode(new Request()));
$this->paused(fn () => $controller->receiveFreenode_laji(new Request()));
$this->paused(fn () => $controller->receive(new Request(['_raw'=>[
'id'=>8, 'opt'=>json_encode(['sCategoryName'=>'免费节点']),
]])));
// Moving an existing node article to another category must not bypass the pause.
$this->paused(fn () => $controller->receive(new Request(['_raw'=>[
'id'=>7, 'opt'=>json_encode(['sCategoryName'=>'新手教程']),
]])));
$this->assertSame(1, DB::table('articles')->count());
$this->assertSame('original', DB::table('articles')->where('id',7)->value('sContent'));
Http::assertNothingSent();
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Resource update has no usable result');
(new ArticlesController())->receiveFreenode(new Request(['article'=>[
'title'=>'Free nodes', 'title_sub'=>'', 'content'=>'A resource update',
'tags'=>[], 'check_status'=>'failed',
]]));
}
public function test_model_rejects_publication_changes_but_allows_metrics_and_other_types(): void
public function test_free_node_model_can_publish_and_update_with_ads_hidden(): void
{
config(['site_mode.quiet'=>true]);
$existing = Articles::find(7); $existing->sContent = 'replacement';
$this->paused(fn () => $existing->save());
$this->assertSame('original', DB::table('articles')->where('id',7)->value('sContent'));
$existing = Articles::find(7);
$existing->sContent = 'replacement';
$existing->save();
$new = new Articles(['iCategoryId'=>1,'sSlug'=>'fn-new','sContent'=>'new']);
$this->paused(fn () => $new->save());
$metrics = Articles::find(7); $metrics->iLikeCount = 10; $metrics->save();
$this->assertSame(10, DB::table('articles')->where('id',7)->value('iLikeCount'));
foreach ([2,3] as $id) SiteMode::guardArticle(new Articles(['iCategoryId'=>$id,'sContent'=>'unchanged scope']));
SiteMode::assertUpdatesAllowed('shadowrocketids');
$this->assertSame(1, DB::table('articles')->count());
config(['site_mode.quiet'=>false]); SiteMode::assertUpdatesAllowed('freenode');
$new->save();
$this->assertSame('replacement', Articles::find(7)->sContent);
$this->assertSame('new', Articles::where('sSlug', 'fn-new')->firstOrFail()->sContent);
}
public function test_promotions_disappear_without_mutating_original_body_or_copy_payload(): void