fix(shipping-notice): 修复订单模板未绑定框展示与翻页画布失效
强制展示未绑定字段框并支持清除;预览令牌 TTL 内可复用,避免翻页后画布不可用。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
9d82eafcc9
commit
83da5f326d
14 files changed
+453
-46
No files matched your search
@@ -965,9 +965,13 @@ def list_preview_pages(profile_id: int, *, document_id: int, actor_id: int | Non
|
||||
|
||||
|
||||
def render_preview_page(*, token: str, page_no: int, actor_id: int | None) -> bytes:
|
||||
""" PNG PDF?HTML"""
|
||||
"""按页返回受控 PNG;令牌在 TTL 内可重复使用,以支持标注画布翻页回访。
|
||||
|
||||
核心逻辑:校验 Redis 中的短时 grant(不 getdel);token 仍绑定 profile/document/actor/page。
|
||||
标注编辑需要在多页间来回切换,一次性消费会导致每次翻页都「画布不可用」。
|
||||
"""
|
||||
store = _preview_grant_store()
|
||||
raw_grant = store.getdel(f'{PREVIEW_GRANT_KEY_PREFIX}{str(token)}')
|
||||
raw_grant = store.get(f'{PREVIEW_GRANT_KEY_PREFIX}{str(token)}')
|
||||
try:
|
||||
grant = json.loads(raw_grant) if raw_grant else None
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
|
||||
@@ -3,7 +3,8 @@ backend/app/services/shipping_notice/preview_grant_store.py
|
||||
|
||||
用途:为订单文档模板页预览令牌提供受控存储后端选择。
|
||||
依赖:Flask current_app、统一 Redis client。
|
||||
逻辑:生产默认强依赖 Redis;开发单进程可按配置回退到进程内一次性令牌存储。
|
||||
逻辑:生产默认强依赖 Redis;开发单进程可按配置回退到进程内短时令牌存储。
|
||||
PNG 页预览令牌在 TTL 内可重复 get(支持翻页);原 PDF 预览仍可用 getdel 单次消费。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -19,7 +20,7 @@ from app.services.redis_client import get_redis_client
|
||||
|
||||
|
||||
class _MemoryGrantStore:
|
||||
"""为单进程开发环境提供最小 setex/getdel 语义,保持一次性令牌行为。"""
|
||||
"""为单进程开发环境提供 setex/get/getdel,PNG 页令牌可在 TTL 内重复读取。"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._lock = threading.Lock()
|
||||
@@ -30,6 +31,19 @@ class _MemoryGrantStore:
|
||||
with self._lock:
|
||||
self._items[key] = (expires_at, value)
|
||||
|
||||
def get(self, key: str) -> str | None:
|
||||
"""读取未过期令牌且不删除,供标注画布翻页回访同一 PNG grant。"""
|
||||
now = time.time()
|
||||
with self._lock:
|
||||
row = self._items.get(key)
|
||||
if row is None:
|
||||
return None
|
||||
expires_at, value = row
|
||||
if expires_at <= now:
|
||||
self._items.pop(key, None)
|
||||
return None
|
||||
return value
|
||||
|
||||
def getdel(self, key: str) -> str | None:
|
||||
now = time.time()
|
||||
with self._lock:
|
||||
@@ -57,7 +71,7 @@ def preview_grant_store() -> Any:
|
||||
返回模板预览授权存储。
|
||||
|
||||
AI/调用方触发时机:仅供订单文档模板预览接口内部使用。Redis 不可用时,
|
||||
只有启用了开发兜底配置,才允许退回进程内一次性 token 存储。
|
||||
只有启用了开发兜底配置,才允许退回进程内短时 token 存储。
|
||||
"""
|
||||
client = get_redis_client()
|
||||
if client is not None:
|
||||
|
||||
Reference in new issue
Block a user