dxpos-openapi 0.0.3__tar.gz → 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dxpos-openapi
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: DXPOS OpenAPI Python SDK
5
5
  Author-email: DXPOS <support@dxpos.co>
6
6
  License: MIT License
@@ -169,6 +169,26 @@ resp = client.create_scene_enhancement(
169
169
  task_id = resp["data"]["task_id"]
170
170
  ```
171
171
 
172
+ ### 创建灵感复刻任务
173
+
174
+ 原图和参考图各自在 `file_id`、`image_path`、`image_url` 里三选一。不需要主题。结果用查询任务和取消任务。
175
+
176
+ ```python
177
+ resp = client.create_scene_migration(
178
+ image_url="https://example.com/source.jpg",
179
+ ref_image_url="https://example.com/reference.jpg",
180
+ customer_tag_id=customer_tag_id,
181
+ )
182
+
183
+ resp = client.create_scene_migration(
184
+ image_path="/path/to/source.jpg",
185
+ ref_image_path="/path/to/reference.jpg",
186
+ customer_tag_id=customer_tag_id,
187
+ )
188
+
189
+ task_id = resp["data"]["task_id"]
190
+ ```
191
+
172
192
  ### 查询任务
173
193
 
174
194
  ```python
@@ -224,7 +244,7 @@ pip install -e ".[dev]"
224
244
  pytest
225
245
  ```
226
246
 
227
- 当前版本 `0.0.3`(新增抠图任务):
247
+ 当前版本 `0.0.4`(新增灵感复刻任务):
228
248
 
229
249
  ```bash
230
250
  rm -rf dist build src/*.egg-info
@@ -232,9 +252,9 @@ python -m build
232
252
  twine check dist/*
233
253
  twine upload -r testpypi dist/*
234
254
  # 干净环境验证:
235
- # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.3
255
+ # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.4
236
256
  twine upload dist/*
237
- git tag v0.0.3
257
+ git tag v0.0.4
238
258
  git push origin main --tags
239
259
  ```
240
260
 
@@ -112,6 +112,26 @@ resp = client.create_scene_enhancement(
112
112
  task_id = resp["data"]["task_id"]
113
113
  ```
114
114
 
115
+ ### 创建灵感复刻任务
116
+
117
+ 原图和参考图各自在 `file_id`、`image_path`、`image_url` 里三选一。不需要主题。结果用查询任务和取消任务。
118
+
119
+ ```python
120
+ resp = client.create_scene_migration(
121
+ image_url="https://example.com/source.jpg",
122
+ ref_image_url="https://example.com/reference.jpg",
123
+ customer_tag_id=customer_tag_id,
124
+ )
125
+
126
+ resp = client.create_scene_migration(
127
+ image_path="/path/to/source.jpg",
128
+ ref_image_path="/path/to/reference.jpg",
129
+ customer_tag_id=customer_tag_id,
130
+ )
131
+
132
+ task_id = resp["data"]["task_id"]
133
+ ```
134
+
115
135
  ### 查询任务
116
136
 
117
137
  ```python
@@ -167,7 +187,7 @@ pip install -e ".[dev]"
167
187
  pytest
168
188
  ```
169
189
 
170
- 当前版本 `0.0.3`(新增抠图任务):
190
+ 当前版本 `0.0.4`(新增灵感复刻任务):
171
191
 
172
192
  ```bash
173
193
  rm -rf dist build src/*.egg-info
@@ -175,9 +195,9 @@ python -m build
175
195
  twine check dist/*
176
196
  twine upload -r testpypi dist/*
177
197
  # 干净环境验证:
178
- # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.3
198
+ # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.4
179
199
  twine upload dist/*
180
- git tag v0.0.3
200
+ git tag v0.0.4
181
201
  git push origin main --tags
182
202
  ```
183
203
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dxpos-openapi"
7
- version = "0.0.3"
7
+ version = "0.0.4"
8
8
  description = "DXPOS OpenAPI Python SDK"
9
9
  readme = "README.md"
10
10
  license = {file = "LICENSE"}
@@ -1,6 +1,6 @@
1
1
  from dxpos_openapi.client import DxposClient
2
2
  from dxpos_openapi.constants import DEFAULT_BASE_URL
3
3
 
4
- __version__ = "0.0.3"
4
+ __version__ = "0.0.4"
5
5
 
6
6
  __all__ = ["DxposClient", "DEFAULT_BASE_URL", "__version__"]
@@ -14,6 +14,7 @@ from dxpos_openapi.constants import (
14
14
  PATH_FILE,
15
15
  PATH_REMOVE_BG,
16
16
  PATH_SCENE_ENHANCEMENT,
17
+ PATH_SCENE_MIGRATION,
17
18
  PATH_THEME,
18
19
  path_cancel,
19
20
  path_remove_bg_task,
@@ -116,6 +117,48 @@ class DxposClient(object):
116
117
  customer_tag_id=customer_tag_id,
117
118
  )
118
119
 
120
+ def _one_image(self, file_id, image_path, image_url, customer_tag_id, label):
121
+ picked = [item for item in (file_id, image_path, image_url) if item]
122
+ if len(picked) != 1:
123
+ return None, _fail(f"{label}的 file_id、image_path、image_url 必须三选一")
124
+ if image_url:
125
+ return {"type": IMAGE_TYPE_URL, "url": image_url}, None
126
+ if image_path:
127
+ uploaded = self.upload_file(image_path, customer_tag_id=customer_tag_id)
128
+ if uploaded.get("code") != 0:
129
+ return None, uploaded
130
+ file_id = (uploaded.get("data") or {}).get("file_id")
131
+ if not file_id:
132
+ return None, _fail("上传成功但缺少 file_id")
133
+ return {"type": IMAGE_TYPE_FILE_ID, "file_id": file_id}, None
134
+
135
+ def create_scene_migration(
136
+ self,
137
+ file_id=None,
138
+ image_path=None,
139
+ image_url=None,
140
+ ref_file_id=None,
141
+ ref_image_path=None,
142
+ ref_image_url=None,
143
+ customer_tag_id=None,
144
+ ):
145
+ image, error = self._one_image(
146
+ file_id, image_path, image_url, customer_tag_id, "原图"
147
+ )
148
+ if error is not None:
149
+ return error
150
+ ref_image, error = self._one_image(
151
+ ref_file_id, ref_image_path, ref_image_url, customer_tag_id, "参考图"
152
+ )
153
+ if error is not None:
154
+ return error
155
+ return self._request(
156
+ "POST",
157
+ PATH_SCENE_MIGRATION,
158
+ {"image": image, "ref_image": ref_image},
159
+ customer_tag_id=customer_tag_id,
160
+ )
161
+
119
162
  def get_task(self, task_id, customer_tag_id=None):
120
163
  return self._request("GET", path_task(task_id), customer_tag_id=customer_tag_id)
121
164
 
@@ -3,6 +3,7 @@ DEFAULT_BASE_URL = "https://openapi.dxpos.co"
3
3
  PATH_THEME = "/api/v1/theme"
4
4
  PATH_FILE = "/api/v1/file"
5
5
  PATH_SCENE_ENHANCEMENT = "/api/v1/task/scene_enhancement"
6
+ PATH_SCENE_MIGRATION = "/api/v1/task/scene_migration"
6
7
  PATH_REMOVE_BG = "/api/v1/task/remove_bg"
7
8
  PATH_CUSTOMER_TAG = "/api/v1/customer_tag"
8
9
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dxpos-openapi
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: DXPOS OpenAPI Python SDK
5
5
  Author-email: DXPOS <support@dxpos.co>
6
6
  License: MIT License
@@ -169,6 +169,26 @@ resp = client.create_scene_enhancement(
169
169
  task_id = resp["data"]["task_id"]
170
170
  ```
171
171
 
172
+ ### 创建灵感复刻任务
173
+
174
+ 原图和参考图各自在 `file_id`、`image_path`、`image_url` 里三选一。不需要主题。结果用查询任务和取消任务。
175
+
176
+ ```python
177
+ resp = client.create_scene_migration(
178
+ image_url="https://example.com/source.jpg",
179
+ ref_image_url="https://example.com/reference.jpg",
180
+ customer_tag_id=customer_tag_id,
181
+ )
182
+
183
+ resp = client.create_scene_migration(
184
+ image_path="/path/to/source.jpg",
185
+ ref_image_path="/path/to/reference.jpg",
186
+ customer_tag_id=customer_tag_id,
187
+ )
188
+
189
+ task_id = resp["data"]["task_id"]
190
+ ```
191
+
172
192
  ### 查询任务
173
193
 
174
194
  ```python
@@ -224,7 +244,7 @@ pip install -e ".[dev]"
224
244
  pytest
225
245
  ```
226
246
 
227
- 当前版本 `0.0.3`(新增抠图任务):
247
+ 当前版本 `0.0.4`(新增灵感复刻任务):
228
248
 
229
249
  ```bash
230
250
  rm -rf dist build src/*.egg-info
@@ -232,9 +252,9 @@ python -m build
232
252
  twine check dist/*
233
253
  twine upload -r testpypi dist/*
234
254
  # 干净环境验证:
235
- # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.3
255
+ # pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.4
236
256
  twine upload dist/*
237
- git tag v0.0.3
257
+ git tag v0.0.4
238
258
  git push origin main --tags
239
259
  ```
240
260
 
@@ -18,6 +18,7 @@ from dxpos_openapi.constants import (
18
18
  PATH_FILE,
19
19
  PATH_REMOVE_BG,
20
20
  PATH_SCENE_ENHANCEMENT,
21
+ PATH_SCENE_MIGRATION,
21
22
  PATH_THEME,
22
23
  )
23
24
 
@@ -413,6 +414,75 @@ def test_get_remove_bg_task(monkeypatch):
413
414
  _assert_signed("GET", "/api/v1/task/remove_bg/rid", b"", captured["headers"])
414
415
 
415
416
 
417
+ def test_create_scene_migration_urls(monkeypatch):
418
+ client = _client()
419
+ calls = []
420
+
421
+ def fake_request(method, url, data=None, headers=None, timeout=None):
422
+ calls.append({"method": method, "url": url, "data": data, "headers": headers})
423
+ return FakeResponse(_ok({"task_id": "mid"}))
424
+
425
+ monkeypatch.setattr(client._session, "request", fake_request)
426
+ resp = client.create_scene_migration(
427
+ image_url="https://example.com/source.jpg",
428
+ ref_file_id="ref1",
429
+ customer_tag_id="tag1",
430
+ )
431
+ assert resp["code"] == 0
432
+ assert len(calls) == 1
433
+ assert calls[0]["url"].endswith(PATH_SCENE_MIGRATION)
434
+ payload = json.loads(calls[0]["data"].decode("utf-8"))
435
+ assert payload == {
436
+ "image": {"type": "url", "url": "https://example.com/source.jpg"},
437
+ "ref_image": {"type": "file_id", "file_id": "ref1"},
438
+ }
439
+ assert calls[0]["headers"][HEADER_CUSTOMER_TAG] == "tag1"
440
+ _assert_signed("POST", PATH_SCENE_MIGRATION, calls[0]["data"], calls[0]["headers"])
441
+
442
+
443
+ def test_create_scene_migration_local_paths(tmp_path, monkeypatch):
444
+ source = tmp_path / "source.jpg"
445
+ reference = tmp_path / "reference.png"
446
+ source.write_bytes(b"source")
447
+ reference.write_bytes(b"reference")
448
+ client = _client()
449
+ calls = []
450
+
451
+ def fake_request(method, url, data=None, headers=None, timeout=None):
452
+ calls.append({"url": url, "data": data})
453
+ if url.endswith(PATH_FILE):
454
+ file_id = "src" if len(calls) == 1 else "ref"
455
+ return FakeResponse(_ok({"file_id": file_id, "put_url": "https://cos.example/put"}))
456
+ return FakeResponse(_ok({"task_id": "mid"}))
457
+
458
+ def fake_put(url, data=None, headers=None, timeout=None):
459
+ return FakeResponse(status_code=200)
460
+
461
+ monkeypatch.setattr(client._session, "request", fake_request)
462
+ monkeypatch.setattr(client._session, "put", fake_put)
463
+ resp = client.create_scene_migration(
464
+ image_path=str(source), ref_image_path=str(reference)
465
+ )
466
+ assert resp["code"] == 0
467
+ assert calls[-1]["url"].endswith(PATH_SCENE_MIGRATION)
468
+ payload = json.loads(calls[-1]["data"].decode("utf-8"))
469
+ assert payload["image"]["file_id"] == "src"
470
+ assert payload["ref_image"]["file_id"] == "ref"
471
+
472
+
473
+ def test_create_scene_migration_invalid_args():
474
+ client = _client()
475
+ missing = client.create_scene_migration(image_url="https://example.com/a.jpg")
476
+ both = client.create_scene_migration(
477
+ image_url="https://example.com/a.jpg",
478
+ file_id="a",
479
+ ref_image_url="https://example.com/b.jpg",
480
+ )
481
+ assert missing["code"] == both["code"] == -1
482
+ assert "参考图" in missing["msg"]
483
+ assert "原图" in both["msg"]
484
+
485
+
416
486
  def test_network_error(monkeypatch):
417
487
  client = _client()
418
488
 
File without changes
File without changes