forked from erp-dev/erp
feat: added customContent
This commit is contained in:
@@ -24,15 +24,6 @@ def _truncate(s: str, max_len: int) -> str:
|
|||||||
return s
|
return s
|
||||||
return s[:max_len]
|
return s[:max_len]
|
||||||
|
|
||||||
def _default_tiia_tags_for_image_url(image_url: str) -> str:
|
|
||||||
"""
|
|
||||||
TencentCloud TIIA `Tags` is a string field; in practice people often put JSON string inside.
|
|
||||||
We store the original accessible image URL there so SearchImage results can carry it back.
|
|
||||||
"""
|
|
||||||
payload = {'imageUrl': (image_url or '').strip()}
|
|
||||||
# Keep it compact and readable.
|
|
||||||
return json.dumps(payload, ensure_ascii=False, separators=(',', ':'))
|
|
||||||
|
|
||||||
def _compute_tiia_pic_name(*, image_url: str, pic_prefix: str) -> str:
|
def _compute_tiia_pic_name(*, image_url: str, pic_prefix: str) -> str:
|
||||||
parsed = urlparse(image_url)
|
parsed = urlparse(image_url)
|
||||||
basename = (parsed.path.rsplit('/', 1)[-1] or '').strip()
|
basename = (parsed.path.rsplit('/', 1)[-1] or '').strip()
|
||||||
@@ -246,10 +237,10 @@ def upload_image_url_to_tencent_tiia(*, image_url: str, entity_id: str, tags: st
|
|||||||
req.EntityId = str(entity_id)
|
req.EntityId = str(entity_id)
|
||||||
req.PicName = str(pic_name)
|
req.PicName = str(pic_name)
|
||||||
req.ImageUrl = str(image_url)
|
req.ImageUrl = str(image_url)
|
||||||
# Store accessible URL into tags so SearchImage result can carry it back.
|
# Per product requirement: do NOT write Tags by default.
|
||||||
# (UpdateImage only supports Tags, not CustomContent, so Tags is the primary field.)
|
if tags is not None and str(tags).strip() != '':
|
||||||
req.Tags = str(tags) if tags is not None else _default_tiia_tags_for_image_url(image_url)
|
req.Tags = str(tags)
|
||||||
# Also store it in CustomContent for human readability (CreateImage supports it).
|
# Keep CustomContent as full URL by default (CreateImage supports it).
|
||||||
req.CustomContent = str(custom_content) if custom_content is not None else str(image_url)
|
req.CustomContent = str(custom_content) if custom_content is not None else str(image_url)
|
||||||
|
|
||||||
resp = client.CreateImage(req)
|
resp = client.CreateImage(req)
|
||||||
|
|||||||
@@ -26,3 +26,16 @@
|
|||||||
- `api_v1/views/test_tiia_search_image_api.py`
|
- `api_v1/views/test_tiia_search_image_api.py`
|
||||||
- 新增用例覆盖 `limit/offset/matchThreshold` 透传与边界校验(limit>100、offset<0)
|
- 新增用例覆盖 `limit/offset/matchThreshold` 透传与边界校验(limit>100、offset<0)
|
||||||
|
|
||||||
|
### 2) 方案 A:让搜图结果可拿到可访问 URL(写入 CustomContent)
|
||||||
|
|
||||||
|
由于腾讯云 TIIA `SearchImage` 的返回 `ImageInfos` 默认不包含 `ImageUrl`,因此无法直接从结果拼出可访问 URL。
|
||||||
|
为便于前端展示/回查,上传入库时将“可访问图片 URL”写入图片元信息中:
|
||||||
|
|
||||||
|
- `api_v1/utils/tencentcloud_tiia.py`
|
||||||
|
- `upload_image_url_to_tencent_tiia(...)` 调用 `CreateImage` 时:
|
||||||
|
- `CustomContent` 默认写入原始 URL(`CustomContent` 文档上限 4096 字符)
|
||||||
|
- `Tags` 默认不写入(避免触发“标签值长度过长”)
|
||||||
|
|
||||||
|
前端取值建议:
|
||||||
|
|
||||||
|
- 若腾讯云 `SearchImage` 返回的 `ImageInfos[i].CustomContent` 可用,则直接作为可访问 URL 使用
|
||||||
|
|||||||
Reference in New Issue
Block a user