Class: EasyAI::Command::Restore::Codex
- Inherits:
-
Restore
- Object
- Restore
- EasyAI::Command::Restore::Codex
- Defined in:
- lib/easyai/command/restore/codex.rb
Constant Summary collapse
- AUTH_KEY =
'auth'.freeze
- CONFIG_KEY =
'config_toml'.freeze
Instance Method Summary collapse
-
#auth_target ⇒ Object
注意:路径用方法动态 expand_path,避免常量在加载期冻结真实 HOME.
- #backup_path ⇒ Object
- #codex_dir ⇒ Object
- #config_target ⇒ Object
-
#restore_auth_only ⇒ Object
仅还原 auth.json(供 easyai codex 选择 ChatGPT Subscribe 时取回官方 token), 不触碰 config.toml。返回是否实际还原。异常由调用方处理。.
- #run ⇒ Object
- #validate! ⇒ Object
Instance Method Details
#auth_target ⇒ Object
注意:路径用方法动态 expand_path,避免常量在加载期冻结真实 HOME
32 |
# File 'lib/easyai/command/restore/codex.rb', line 32 def auth_target = File.('~/.codex/auth.json') |
#backup_path ⇒ Object
35 |
# File 'lib/easyai/command/restore/codex.rb', line 35 def backup_path = File.('~/.easyai/backup/.codex.json') |
#codex_dir ⇒ Object
34 |
# File 'lib/easyai/command/restore/codex.rb', line 34 def codex_dir = File.('~/.codex') |
#config_target ⇒ Object
33 |
# File 'lib/easyai/command/restore/codex.rb', line 33 def config_target = File.('~/.codex/config.toml') |
#restore_auth_only ⇒ Object
仅还原 auth.json(供 easyai codex 选择 ChatGPT Subscribe 时取回官方 token), 不触碰 config.toml。返回是否实际还原。异常由调用方处理。
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/easyai/command/restore/codex.rb', line 56 def restore_auth_only return false unless File.exist?(backup_path) auth = read_json(backup_path)[AUTH_KEY] return false unless auth.is_a?(Hash) && !auth.empty? FileUtils.mkdir_p(codex_dir) restore_auth(auth) true end |
#run ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/easyai/command/restore/codex.rb', line 43 def run FileUtils.mkdir_p(codex_dir) backup = read_json(backup_path) ensure_file_credentials_supported!(backup) auth_summary = restore_auth(backup[AUTH_KEY]) config_summary = restore_config(backup[CONFIG_KEY]) report(auth_summary, config_summary) end |
#validate! ⇒ Object
37 38 39 40 41 |
# File 'lib/easyai/command/restore/codex.rb', line 37 def validate! super help! "备份文件不存在: #{backup_path}\n请先运行 easyai backup codex 创建备份。" unless File.exist?(backup_path) ensure_file_credentials_supported! end |