argument('state'); if (! in_array($state, ['on','off','status'], true)) { $this->error('Use on, off, or status.'); return self::FAILURE; } if ($state !== 'status') { $path = config('site_mode.state_path'); if (! is_dir(dirname($path))) mkdir(dirname($path), 0700, true); $temporary = $path.'.'.Str::uuid().'.tmp'; try { $handle = fopen($temporary, 'x'); if (! $handle) throw new \RuntimeException('Cannot create mode state.'); chmod($temporary, 0600); $payload = json_encode(['quiet' => $state === 'on', 'changed_at' => now()->toIso8601String()]); try { if (fwrite($handle, $payload) !== strlen($payload) || ! fflush($handle)) { throw new \RuntimeException('Cannot save mode state.'); } } finally { fclose($handle); } if (! rename($temporary, $path)) throw new \RuntimeException('Cannot activate mode state.'); } finally { if (is_file($temporary)) unlink($temporary); } \Spatie\ResponseCache\Facades\ResponseCache::clear(); } $this->info('暂避风头模式:'.(SiteMode::quiet() ? '开启(节点更新暂停,机场广告隐藏)' : '关闭(正常模式)')); return self::SUCCESS; } }