artdam-cli 0.4.3__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {artdam_cli-0.4.3/artdam_cli.egg-info → artdam_cli-0.6.0}/PKG-INFO +40 -7
  2. artdam_cli-0.4.3/PKG-INFO → artdam_cli-0.6.0/README.md +267 -246
  3. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/client.py +15 -8
  4. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/delete_cmd.py +3 -2
  5. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/download.py +2 -0
  6. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/engine.py +2 -2
  7. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/get.py +14 -4
  8. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/login.py +74 -13
  9. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/search.py +4 -2
  10. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/upload.py +10 -2
  11. artdam_cli-0.6.0/artdam_cli/config.py +143 -0
  12. artdam_cli-0.6.0/artdam_cli/display.py +29 -0
  13. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/main.py +19 -0
  14. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/uploader.py +45 -4
  15. artdam_cli-0.4.3/README.md → artdam_cli-0.6.0/artdam_cli.egg-info/PKG-INFO +279 -234
  16. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli.egg-info/SOURCES.txt +4 -0
  17. artdam_cli-0.6.0/artdam_cli.egg-info/entry_points.txt +2 -0
  18. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/pyproject.toml +2 -2
  19. artdam_cli-0.6.0/tests/test_display_policy.py +166 -0
  20. artdam_cli-0.6.0/tests/test_login.py +279 -0
  21. artdam_cli-0.6.0/tests/test_main_entry.py +48 -0
  22. artdam_cli-0.6.0/tests/test_uploader.py +208 -0
  23. artdam_cli-0.4.3/artdam_cli/config.py +0 -39
  24. artdam_cli-0.4.3/artdam_cli.egg-info/entry_points.txt +0 -2
  25. artdam_cli-0.4.3/tests/test_uploader.py +0 -98
  26. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/__init__.py +0 -0
  27. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/__init__.py +0 -0
  28. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/comment.py +0 -0
  29. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/favorite.py +0 -0
  30. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/folder_cmd.py +0 -0
  31. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/folders.py +0 -0
  32. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/project.py +0 -0
  33. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/projects.py +0 -0
  34. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/rate.py +0 -0
  35. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/restore.py +0 -0
  36. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/tag_cmd.py +0 -0
  37. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/tags.py +0 -0
  38. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/commands/update.py +0 -0
  39. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli/update_check.py +0 -0
  40. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli.egg-info/dependency_links.txt +0 -0
  41. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli.egg-info/requires.txt +0 -0
  42. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/artdam_cli.egg-info/top_level.txt +0 -0
  43. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/setup.cfg +0 -0
  44. {artdam_cli-0.4.3 → artdam_cli-0.6.0}/tests/test_search_pagination.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: artdam-cli
3
- Version: 0.4.3
3
+ Version: 0.6.0
4
4
  Summary: ArtDAM 数字资产管理平台命令行工具
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -32,6 +32,9 @@ uv tool install artdam-cli@latest
32
32
  # 登录(首次使用,浏览器 SSO 授权)
33
33
  artdam login
34
34
 
35
+ # 个人 API Key 登录(隐藏输入,适合本机长期使用)
36
+ artdam login --api-key
37
+
35
38
  # 搜索资产
36
39
  artdam search "关键词" --project 1
37
40
 
@@ -44,16 +47,42 @@ artdam download 123 --out ./downloads
44
47
 
45
48
  ## 命令说明
46
49
 
50
+ ### 素材名的显示口径
51
+
52
+ 开了「只显示 public_id」的项目,`search` 的「素材名」列、`get` 的「素材名」行、`delete` 的
53
+ 确认文案都显示 `public_id`(规则同网页端)。
54
+
55
+ `download` 落盘名、`get` 的「路径」行、`--json` 原始响应**照旧给真实文件名**——脱敏只在对外面
56
+ (发布空间 / 分享链接 / ZIP)由后端做,内部下载不变,见 PR #1036。写脚本时按
57
+ `display_asset_public_id_only` 字段自己判断,别拿显示名当文件名用。
58
+
47
59
  ### 查询命令(viewer 及以上)
48
60
 
49
61
  #### `artdam login`
50
62
 
51
- 登录 ArtDAM,保存 token 到本地 `~/.artdam/config.json`。
63
+ 登录 ArtDAM。默认使用浏览器 SSO,也可使用个人 API Key 或账号密码。
52
64
 
53
65
  ```bash
54
- artdam login
66
+ artdam login # 浏览器 SSO
67
+ artdam login --api-key # 隐藏输入个人 ab_ API Key
68
+ artdam login --password # 账号密码(仅 admin / 服务账号)
69
+ ```
70
+
71
+ `--api-key` 会通过只读的 `GET /api/auth/me` 验证密钥,再保存到
72
+ `~/.artdam/config.json`(Linux/macOS 为 `0600`,Windows 收紧为仅当前用户 ACL)。
73
+ 命令行参数和输出都不会显示密钥。
74
+
75
+ 无人值守脚本和 Agent 可直接使用环境变量,无需执行登录,也不会把密钥写入配置文件:
76
+
77
+ ```bash
78
+ export ARTDAM_API_KEY='ab_...'
79
+ export ARTDAM_BASE_URL='https://artdam.xindong.com' # 可选
80
+ artdam search "头盔" --project 1 --json
55
81
  ```
56
82
 
83
+ 个人 API Key 代表创建它的用户,最终能力始终是**用户在项目中的角色权限 ∩ Key 的权限范围
84
+ (scope)**。例如 viewer 用户即使 Key 含 `write` 也不能上传;只有 `read` 的 Key 不能执行写操作。
85
+
57
86
  #### `artdam search`
58
87
 
59
88
  搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
@@ -209,8 +238,8 @@ artdam folders --project 1 --json
209
238
  ### 典型 Agent 工作流
210
239
 
211
240
  ```bash
212
- # 1. 登录(浏览器 SSO 授权)
213
- artdam login
241
+ # 1. 登录(本机可用 SSO;无人值守 Agent 推荐 ARTDAM_API_KEY)
242
+ export ARTDAM_API_KEY='ab_...'
214
243
 
215
244
  # 2. 搜索 → 确认 → 下载
216
245
  artdam search "头盔" --project 1 --json
@@ -231,7 +260,9 @@ artdam update <asset_id> --description "AI 生成的场景描述"
231
260
 
232
261
  - `--project` 参数为**数字 ID**,不是项目名称
233
262
  - `--json` 返回原始 JSON,适合程序解析
234
- - token 保存在 `~/.artdam/config.json`,登录一次长期有效
263
+ - SSO/JWT 或手动输入的 API Key 保存在 `~/.artdam/config.json`,仅当前用户可读写
264
+ - `ARTDAM_API_KEY` 优先于配置文件中的登录凭据,且不会被写入配置或输出
265
+ - API Key 能力受用户项目角色和 Key scope 双重限制
235
266
  - `artdam delete` 是软删除,可用 `artdam restore` 恢复
236
267
 
237
268
  ## 配置文件
@@ -241,6 +272,8 @@ artdam update <asset_id> --description "AI 生成的场景描述"
241
272
  ```json
242
273
  {
243
274
  "base_url": "https://artdam.xindong.com",
244
- "token": "eyJ..."
275
+ "api_key": "ab_..."
245
276
  }
246
277
  ```
278
+
279
+ SSO 或密码登录时凭据字段为 `"token": "eyJ..."`。请勿提交此配置文件或在日志中打印其内容。
@@ -1,246 +1,267 @@
1
- Metadata-Version: 2.4
2
- Name: artdam-cli
3
- Version: 0.4.3
4
- Summary: ArtDAM 数字资产管理平台命令行工具
5
- Requires-Python: >=3.10
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: click>=8.1
8
- Requires-Dist: httpx>=0.27
9
- Requires-Dist: rich>=13.0
10
- Provides-Extra: dev
11
- Requires-Dist: pytest>=8.0; extra == "dev"
12
-
13
- # artdam-cli
14
-
15
- ArtDAM 数字资产管理平台命令行工具,支持所有主流 AI Agent工具接入
16
-
17
- ## 安装
18
-
19
- ```bash
20
- uv tool install artdam-cli
21
- ```
22
-
23
- ## 更新
24
-
25
- ```bash
26
- uv tool install artdam-cli@latest
27
- ```
28
-
29
- ## 快速开始
30
-
31
- ```bash
32
- # 登录(首次使用,浏览器 SSO 授权)
33
- artdam login
34
-
35
- # 搜索资产
36
- artdam search "关键词" --project 1
37
-
38
- # 查看资产详情
39
- artdam get 123
40
-
41
- # 下载资产
42
- artdam download 123 --out ./downloads
43
- ```
44
-
45
- ## 命令说明
46
-
47
- ### 查询命令(viewer 及以上)
48
-
49
- #### `artdam login`
50
-
51
- 登录 ArtDAM,保存 token 到本地 `~/.artdam/config.json`。
52
-
53
- ```bash
54
- artdam login
55
- ```
56
-
57
- #### `artdam search`
58
-
59
- 搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
60
- (Agent 场景推荐,避免结果被截断)。`--all` 最多返回 1000 条,超出会提示用更精确的关键词或
61
- `--ext` / `--folder` 收窄,避免在几万条资产上卡死。
62
-
63
- ```bash
64
- artdam search "头盔" --project 1
65
- artdam search "头盔" --project 1 --limit 50
66
- artdam search "头盔" --project 1 --all # 自动翻页,取全部匹配
67
- artdam search "头盔" --project 1 --all --json # 全量 JSON 输出(AI Agent 用)
68
- artdam search "头盔" --project 1 --ext jpg # 按扩展名过滤
69
- artdam search "头盔" --project 1 --ext jpg,png # 多个扩展名
70
- artdam search "头盔" --project 1 --folder 10
71
- ```
72
-
73
- | 参数 | 说明 |
74
- |---|---|
75
- | `KEYWORD` | 搜索关键词 |
76
- | `-p, --project` | 项目 ID(必填) |
77
- | `-n, --limit` | 返回数量上限,默认 20(不与 `--all` 共用) |
78
- | `--all` | 自动翻页取全部匹配结果(最多 1000 条) |
79
- | `-e, --ext` | 按文件扩展名过滤,逗号分隔,如 `jpg,png` |
80
- | `--folder` | 限定文件夹 ID |
81
- | `--json` | 输出原始 JSON |
82
-
83
- #### `artdam get`
84
-
85
- 查看单个资产详情(含预览链接)。
86
-
87
- ```bash
88
- artdam get 123
89
- artdam get 123 --json # 输出原始 JSON(AI Agent 用)
90
- ```
91
-
92
- #### `artdam download`
93
-
94
- 下载资产文件到本地。
95
-
96
- ```bash
97
- artdam download 123
98
- artdam download 123 --out ./downloads
99
- ```
100
-
101
- #### `artdam tags`
102
-
103
- 列出项目标签。
104
-
105
- ```bash
106
- artdam tags --project 1
107
- artdam tags --project 1 --search "角色"
108
- artdam tags --project 1 --json
109
- ```
110
-
111
- #### `artdam folders`
112
-
113
- 查看文件夹结构。
114
-
115
- ```bash
116
- artdam folders --project 1
117
- artdam folders --project 1 --json
118
- ```
119
-
120
- ### 资产管理(member 及以上)
121
-
122
- #### `artdam upload`
123
-
124
- 上传文件到指定项目和文件夹。采用分块上传,支持大文件(最大 10GB),带进度条;
125
- 上传前按内容计算 SHA-256,库中已有相同文件则**秒传**(直接复用,不重复传输)。
126
- 单个分块遇到网络抖动(超时 / 5xx)会自动重试,中断时清理服务端会话。
127
-
128
- ```bash
129
- artdam upload ./image.jpg --project 1
130
- artdam upload ./image.jpg --project 1 --folder 10
131
- artdam upload ./big_scene.zip --project 1 # 大文件分块 + 进度条
132
- ```
133
-
134
- #### `artdam update`
135
-
136
- 更新资产信息(可同时传多个选项)。
137
-
138
- ```bash
139
- artdam update 123 --name "新文件名"
140
- artdam update 123 --description "新描述"
141
- artdam update 123 --folder 10
142
- ```
143
-
144
- #### `artdam delete`
145
-
146
- 软删除资产(可通过 `restore` 恢复)。
147
-
148
- ```bash
149
- artdam delete 123
150
- ```
151
-
152
- #### `artdam restore`
153
-
154
- 恢复已删除的资产。
155
-
156
- ```bash
157
- artdam restore 123
158
- ```
159
-
160
- ### 标签管理(member 及以上)
161
-
162
- ```bash
163
- # 给资产添加标签
164
- artdam tag add 123 5
165
-
166
- # 从资产移除标签
167
- artdam tag remove 123 5
168
-
169
- # 创建新标签
170
- artdam tag create "标签名" --project 1
171
- ```
172
-
173
- ### 文件夹管理(member 及以上)
174
-
175
- ```bash
176
- # 创建文件夹
177
- artdam folder create "文件夹名" --project 1
178
- artdam folder create "子文件夹" --project 1 --parent 10
179
-
180
- # 删除文件夹
181
- artdam folder delete 10
182
- ```
183
-
184
- ### 互动操作(member 及以上)
185
-
186
- ```bash
187
- # 评论
188
- artdam comment 123 "评论内容"
189
-
190
- # 评分(1-5 星)
191
- artdam rate 123 4
192
-
193
- # 收藏 / 取消收藏
194
- artdam favorite 123
195
- artdam favorite 123 --remove
196
- ```
197
-
198
- ## AI Agent 使用指南
199
-
200
- 所有查询命令支持 `--json` 输出原始 JSON,适合 Agent 解析:
201
-
202
- ```bash
203
- artdam search "安妮" --project 1 --json
204
- artdam get 123 --json
205
- artdam tags --project 1 --json
206
- artdam folders --project 1 --json
207
- ```
208
-
209
- ### 典型 Agent 工作流
210
-
211
- ```bash
212
- # 1. 登录(浏览器 SSO 授权)
213
- artdam login
214
-
215
- # 2. 搜索 → 确认 → 下载
216
- artdam search "头盔" --project 1 --json
217
- artdam get 50707 --json
218
- artdam download 50707 --out ./assets
219
-
220
- # 3. 搜索 → 批量打标签
221
- artdam search "安妮" --project 1 --json
222
- artdam tag add 50707 5
223
- artdam tag add 50708 5
224
-
225
- # 4. 上传并更新描述
226
- artdam upload ./new_asset.jpg --project 1 --folder 10
227
- artdam update <asset_id> --description "AI 生成的场景描述"
228
- ```
229
-
230
- ## 注意事项
231
-
232
- - `--project` 参数为**数字 ID**,不是项目名称
233
- - `--json` 返回原始 JSON,适合程序解析
234
- - token 保存在 `~/.artdam/config.json`,登录一次长期有效
235
- - `artdam delete` 是软删除,可用 `artdam restore` 恢复
236
-
237
- ## 配置文件
238
-
239
- 登录信息保存在 `~/.artdam/config.json`:
240
-
241
- ```json
242
- {
243
- "base_url": "https://artdam.xindong.com",
244
- "token": "eyJ..."
245
- }
246
- ```
1
+ # artdam-cli
2
+
3
+ ArtDAM 数字资产管理平台命令行工具,支持所有主流 AI Agent工具接入
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ uv tool install artdam-cli
9
+ ```
10
+
11
+ ## 更新
12
+
13
+ ```bash
14
+ uv tool install artdam-cli@latest
15
+ ```
16
+
17
+ ## 快速开始
18
+
19
+ ```bash
20
+ # 登录(首次使用,浏览器 SSO 授权)
21
+ artdam login
22
+
23
+ # 个人 API Key 登录(隐藏输入,适合本机长期使用)
24
+ artdam login --api-key
25
+
26
+ # 搜索资产
27
+ artdam search "关键词" --project 1
28
+
29
+ # 查看资产详情
30
+ artdam get 123
31
+
32
+ # 下载资产
33
+ artdam download 123 --out ./downloads
34
+ ```
35
+
36
+ ## 命令说明
37
+
38
+ ### 素材名的显示口径
39
+
40
+ 开了「只显示 public_id」的项目,`search` 的「素材名」列、`get` 的「素材名」行、`delete` 的
41
+ 确认文案都显示 `public_id`(规则同网页端)。
42
+
43
+ `download` 落盘名、`get` 的「路径」行、`--json` 原始响应**照旧给真实文件名**——脱敏只在对外面
44
+ (发布空间 / 分享链接 / ZIP)由后端做,内部下载不变,见 PR #1036。写脚本时按
45
+ `display_asset_public_id_only` 字段自己判断,别拿显示名当文件名用。
46
+
47
+ ### 查询命令(viewer 及以上)
48
+
49
+ #### `artdam login`
50
+
51
+ 登录 ArtDAM。默认使用浏览器 SSO,也可使用个人 API Key 或账号密码。
52
+
53
+ ```bash
54
+ artdam login # 浏览器 SSO
55
+ artdam login --api-key # 隐藏输入个人 ab_ API Key
56
+ artdam login --password # 账号密码(仅 admin / 服务账号)
57
+ ```
58
+
59
+ `--api-key` 会通过只读的 `GET /api/auth/me` 验证密钥,再保存到
60
+ `~/.artdam/config.json`(Linux/macOS 为 `0600`,Windows 收紧为仅当前用户 ACL)。
61
+ 命令行参数和输出都不会显示密钥。
62
+
63
+ 无人值守脚本和 Agent 可直接使用环境变量,无需执行登录,也不会把密钥写入配置文件:
64
+
65
+ ```bash
66
+ export ARTDAM_API_KEY='ab_...'
67
+ export ARTDAM_BASE_URL='https://artdam.xindong.com' # 可选
68
+ artdam search "头盔" --project 1 --json
69
+ ```
70
+
71
+ 个人 API Key 代表创建它的用户,最终能力始终是**用户在项目中的角色权限 ∩ Key 的权限范围
72
+ (scope)**。例如 viewer 用户即使 Key 含 `write` 也不能上传;只有 `read` 的 Key 不能执行写操作。
73
+
74
+ #### `artdam search`
75
+
76
+ 搜索资产,返回匹配列表。默认只取首页(`--limit` 条);加 `--all` 自动翻页取全部结果
77
+ (Agent 场景推荐,避免结果被截断)。`--all` 最多返回 1000 条,超出会提示用更精确的关键词或
78
+ `--ext` / `--folder` 收窄,避免在几万条资产上卡死。
79
+
80
+ ```bash
81
+ artdam search "头盔" --project 1
82
+ artdam search "头盔" --project 1 --limit 50
83
+ artdam search "头盔" --project 1 --all # 自动翻页,取全部匹配
84
+ artdam search "头盔" --project 1 --all --json # 全量 JSON 输出(AI Agent 用)
85
+ artdam search "头盔" --project 1 --ext jpg # 按扩展名过滤
86
+ artdam search "头盔" --project 1 --ext jpg,png # 多个扩展名
87
+ artdam search "头盔" --project 1 --folder 10
88
+ ```
89
+
90
+ | 参数 | 说明 |
91
+ |---|---|
92
+ | `KEYWORD` | 搜索关键词 |
93
+ | `-p, --project` | 项目 ID(必填) |
94
+ | `-n, --limit` | 返回数量上限,默认 20(不与 `--all` 共用) |
95
+ | `--all` | 自动翻页取全部匹配结果(最多 1000 条) |
96
+ | `-e, --ext` | 按文件扩展名过滤,逗号分隔,如 `jpg,png` |
97
+ | `--folder` | 限定文件夹 ID |
98
+ | `--json` | 输出原始 JSON |
99
+
100
+ #### `artdam get`
101
+
102
+ 查看单个资产详情(含预览链接)。
103
+
104
+ ```bash
105
+ artdam get 123
106
+ artdam get 123 --json # 输出原始 JSON(AI Agent 用)
107
+ ```
108
+
109
+ #### `artdam download`
110
+
111
+ 下载资产文件到本地。
112
+
113
+ ```bash
114
+ artdam download 123
115
+ artdam download 123 --out ./downloads
116
+ ```
117
+
118
+ #### `artdam tags`
119
+
120
+ 列出项目标签。
121
+
122
+ ```bash
123
+ artdam tags --project 1
124
+ artdam tags --project 1 --search "角色"
125
+ artdam tags --project 1 --json
126
+ ```
127
+
128
+ #### `artdam folders`
129
+
130
+ 查看文件夹结构。
131
+
132
+ ```bash
133
+ artdam folders --project 1
134
+ artdam folders --project 1 --json
135
+ ```
136
+
137
+ ### 资产管理(member 及以上)
138
+
139
+ #### `artdam upload`
140
+
141
+ 上传文件到指定项目和文件夹。采用分块上传,支持大文件(最大 10GB),带进度条;
142
+ 上传前按内容计算 SHA-256,库中已有相同文件则**秒传**(直接复用,不重复传输)。
143
+ 单个分块遇到网络抖动(超时 / 5xx)会自动重试,中断时清理服务端会话。
144
+
145
+ ```bash
146
+ artdam upload ./image.jpg --project 1
147
+ artdam upload ./image.jpg --project 1 --folder 10
148
+ artdam upload ./big_scene.zip --project 1 # 大文件分块 + 进度条
149
+ ```
150
+
151
+ #### `artdam update`
152
+
153
+ 更新资产信息(可同时传多个选项)。
154
+
155
+ ```bash
156
+ artdam update 123 --name "新文件名"
157
+ artdam update 123 --description "新描述"
158
+ artdam update 123 --folder 10
159
+ ```
160
+
161
+ #### `artdam delete`
162
+
163
+ 软删除资产(可通过 `restore` 恢复)。
164
+
165
+ ```bash
166
+ artdam delete 123
167
+ ```
168
+
169
+ #### `artdam restore`
170
+
171
+ 恢复已删除的资产。
172
+
173
+ ```bash
174
+ artdam restore 123
175
+ ```
176
+
177
+ ### 标签管理(member 及以上)
178
+
179
+ ```bash
180
+ # 给资产添加标签
181
+ artdam tag add 123 5
182
+
183
+ # 从资产移除标签
184
+ artdam tag remove 123 5
185
+
186
+ # 创建新标签
187
+ artdam tag create "标签名" --project 1
188
+ ```
189
+
190
+ ### 文件夹管理(member 及以上)
191
+
192
+ ```bash
193
+ # 创建文件夹
194
+ artdam folder create "文件夹名" --project 1
195
+ artdam folder create "子文件夹" --project 1 --parent 10
196
+
197
+ # 删除文件夹
198
+ artdam folder delete 10
199
+ ```
200
+
201
+ ### 互动操作(member 及以上)
202
+
203
+ ```bash
204
+ # 评论
205
+ artdam comment 123 "评论内容"
206
+
207
+ # 评分(1-5 星)
208
+ artdam rate 123 4
209
+
210
+ # 收藏 / 取消收藏
211
+ artdam favorite 123
212
+ artdam favorite 123 --remove
213
+ ```
214
+
215
+ ## AI Agent 使用指南
216
+
217
+ 所有查询命令支持 `--json` 输出原始 JSON,适合 Agent 解析:
218
+
219
+ ```bash
220
+ artdam search "安妮" --project 1 --json
221
+ artdam get 123 --json
222
+ artdam tags --project 1 --json
223
+ artdam folders --project 1 --json
224
+ ```
225
+
226
+ ### 典型 Agent 工作流
227
+
228
+ ```bash
229
+ # 1. 登录(本机可用 SSO;无人值守 Agent 推荐 ARTDAM_API_KEY)
230
+ export ARTDAM_API_KEY='ab_...'
231
+
232
+ # 2. 搜索 → 确认 → 下载
233
+ artdam search "头盔" --project 1 --json
234
+ artdam get 50707 --json
235
+ artdam download 50707 --out ./assets
236
+
237
+ # 3. 搜索 → 批量打标签
238
+ artdam search "安妮" --project 1 --json
239
+ artdam tag add 50707 5
240
+ artdam tag add 50708 5
241
+
242
+ # 4. 上传并更新描述
243
+ artdam upload ./new_asset.jpg --project 1 --folder 10
244
+ artdam update <asset_id> --description "AI 生成的场景描述"
245
+ ```
246
+
247
+ ## 注意事项
248
+
249
+ - `--project` 参数为**数字 ID**,不是项目名称
250
+ - `--json` 返回原始 JSON,适合程序解析
251
+ - SSO/JWT 或手动输入的 API Key 保存在 `~/.artdam/config.json`,仅当前用户可读写
252
+ - `ARTDAM_API_KEY` 优先于配置文件中的登录凭据,且不会被写入配置或输出
253
+ - API Key 能力受用户项目角色和 Key scope 双重限制
254
+ - `artdam delete` 是软删除,可用 `artdam restore` 恢复
255
+
256
+ ## 配置文件
257
+
258
+ 登录信息保存在 `~/.artdam/config.json`:
259
+
260
+ ```json
261
+ {
262
+ "base_url": "https://artdam.xindong.com",
263
+ "api_key": "ab_..."
264
+ }
265
+ ```
266
+
267
+ SSO 或密码登录时凭据字段为 `"token": "eyJ..."`。请勿提交此配置文件或在日志中打印其内容。
@@ -12,11 +12,11 @@ _RETRY_BACKOFF = (1, 2, 4)
12
12
 
13
13
 
14
14
  def _make_client(timeout: float = 30) -> httpx.Client:
15
- base_url = config.require("base_url")
16
- token = config.require("token")
15
+ base_url = config.get_base_url()
16
+ credential = config.get_auth_credential()
17
17
  return httpx.Client(
18
18
  base_url=base_url,
19
- headers={"Authorization": f"Bearer {token}"},
19
+ headers={"Authorization": f"Bearer {credential}"},
20
20
  timeout=timeout,
21
21
  )
22
22
 
@@ -39,7 +39,9 @@ def _send_with_retry(do_request: Callable[[], httpx.Response]) -> httpx.Response
39
39
  return r
40
40
 
41
41
 
42
- def get(path: str, params: dict | None = None, not_found_msg: str = "资源不存在") -> dict:
42
+ def get(
43
+ path: str, params: dict | None = None, not_found_msg: str = "资源不存在"
44
+ ) -> dict:
43
45
  with _make_client() as c:
44
46
  r = c.get(path, params=params)
45
47
  _raise(r, not_found_msg=not_found_msg)
@@ -47,12 +49,12 @@ def get(path: str, params: dict | None = None, not_found_msg: str = "资源不
47
49
 
48
50
 
49
51
  def download_file(path: str, dest: str, not_found_msg: str = "资源不存在") -> int:
50
- base_url = config.require("base_url")
51
- token = config.require("token")
52
+ base_url = config.get_base_url()
53
+ credential = config.get_auth_credential()
52
54
  with httpx.stream(
53
55
  "GET",
54
56
  f"{base_url}{path}",
55
- headers={"Authorization": f"Bearer {token}"},
57
+ headers={"Authorization": f"Bearer {credential}"},
56
58
  timeout=120,
57
59
  follow_redirects=True,
58
60
  ) as r:
@@ -165,7 +167,12 @@ def cancel_upload(upload_id: str) -> None:
165
167
 
166
168
  def _raise(r: httpx.Response, not_found_msg: str = "资源不存在") -> None:
167
169
  if r.status_code == 401:
168
- raise SystemExit("Token 无效或已过期,请重新运行 artdam login")
170
+ raise SystemExit("登录凭据无效或已过期,请重新运行 artdam login")
171
+ if r.status_code == 403:
172
+ raise SystemExit(
173
+ "权限不足:请检查当前用户的项目角色;"
174
+ "使用个人 API Key 时还需检查密钥的权限范围"
175
+ )
169
176
  if r.status_code == 404:
170
177
  raise SystemExit(not_found_msg)
171
178
  if r.is_error: