chore/ 删除无用文件

This commit is contained in:
Kevin
2026-03-19 14:36:14 +08:00
parent 2f60858c9c
commit c6e07ce5ca
135 changed files with 2111 additions and 4510 deletions

View File

@@ -48,7 +48,11 @@ class LiblibImageGenerator:
try:
job = {"job_id": task_id}
result = self._provider.poll_until_complete(job, self._poll_interval, 1)
status = TaskStatus.COMPLETED if result.get("status") == "completed" else TaskStatus.PROCESSING
status = (
TaskStatus.COMPLETED
if result.get("status") == "completed"
else TaskStatus.PROCESSING
)
return ImageResult(
status=status,
task_id=task_id,

View File

@@ -2,6 +2,7 @@
Liblib 图生 SDK 封装,位于 adapters 层;实现细节不暴露给 feature。
Feature 通过 port ImageGenerator 使用,本模块仅被 app.adapters.image_gen.liblib 使用。
"""
import base64
import hmac
import logging
@@ -61,8 +62,12 @@ class LiblibImageProvider:
self.http_client = http_client or httpx.Client(timeout=120)
self.access_key = access_key or (settings.liblib_access_key or "")
self.secret_key = secret_key or (settings.liblib_secret_key or "")
self.base_url = (base_url or settings.liblib_base_url or "https://openapi.liblibai.cloud").rstrip("/")
self.template_uuid = template_uuid or (settings.liblib_template_uuid or DEFAULT_LIBLIB_TEMPLATE_UUID)
self.base_url = (
base_url or settings.liblib_base_url or "https://openapi.liblibai.cloud"
).rstrip("/")
self.template_uuid = template_uuid or (
settings.liblib_template_uuid or DEFAULT_LIBLIB_TEMPLATE_UUID
)
self.allowed_download_hosts = _build_allowed_download_hosts(
self.base_url,
allowed_download_hosts=allowed_download_hosts,
@@ -133,7 +138,9 @@ class LiblibImageProvider:
response.raise_for_status()
data = response.json()
if data.get("code") != 0:
raise RuntimeError(f"Liblib status query failed: {data.get('msg', data)}")
raise RuntimeError(
f"Liblib status query failed: {data.get('msg', data)}"
)
result = data.get("data", {})
status = result.get("generateStatus")
if status == 5:
@@ -144,17 +151,28 @@ class LiblibImageProvider:
"image_url": images[0]["imageUrl"],
"job_id": job["job_id"],
}
raise RuntimeError(f"Liblib returned success but no images for {job['job_id']}")
raise RuntimeError(
f"Liblib returned success but no images for {job['job_id']}"
)
if status == 6:
raise RuntimeError(f"Liblib generation failed: {result.get('generateMsg', 'unknown')}")
raise RuntimeError(
f"Liblib generation failed: {result.get('generateMsg', 'unknown')}"
)
if status == 7:
raise TimeoutError(f"Liblib returned undocumented status 7 for {job['job_id']}")
raise TimeoutError(
f"Liblib returned undocumented status 7 for {job['job_id']}"
)
logger.debug(
"Liblib poll attempt %d/%d, status=%s, job=%s",
attempt + 1, max_attempts, status, job["job_id"],
attempt + 1,
max_attempts,
status,
job["job_id"],
)
time.sleep(poll_interval_seconds)
raise TimeoutError(f"Liblib image generation timed out after {max_attempts} attempts for {job['job_id']}")
raise TimeoutError(
f"Liblib image generation timed out after {max_attempts} attempts for {job['job_id']}"
)
def download_image(self, job: dict) -> bytes:
image_url = job["image_url"]
@@ -183,9 +201,13 @@ class _LiblibAuthRedactionFilter(logging.Filter):
record.msg = _redact_sensitive_query_values(record.msg)
if record.args:
if isinstance(record.args, dict):
record.args = {k: _redact_sensitive_query_values(v) for k, v in record.args.items()}
record.args = {
k: _redact_sensitive_query_values(v) for k, v in record.args.items()
}
else:
record.args = tuple(_redact_sensitive_query_values(v) for v in record.args)
record.args = tuple(
_redact_sensitive_query_values(v) for v in record.args
)
return True
@@ -196,7 +218,13 @@ def _redact_sensitive_query_values(value):
def _install_http_log_redaction() -> None:
for logger_name in ("httpx", "httpcore", "httpcore.connection", "httpcore.http11", "httpcore.proxy"):
for logger_name in (
"httpx",
"httpcore",
"httpcore.connection",
"httpcore.http11",
"httpcore.proxy",
):
target_logger = get_logger(logger_name)
if getattr(target_logger, "_liblib_auth_redaction_installed", False):
continue
@@ -219,7 +247,10 @@ def _build_allowed_download_hosts(
default_hosts: set[str] = set()
if base_hostname:
default_hosts.add(base_hostname)
if base_hostname.endswith(".liblibai.cloud") or base_hostname == "liblibai.cloud":
if (
base_hostname.endswith(".liblibai.cloud")
or base_hostname == "liblibai.cloud"
):
default_hosts.add("liblibai.cloud")
default_hosts.add("liblib.cloud")
return tuple(sorted(default_hosts.union(configured_hosts)))
@@ -230,7 +261,9 @@ def _validate_download_url(image_url: str, allowed_hosts: tuple[str, ...]) -> No
hostname = (parsed.hostname or "").lower()
if parsed.scheme != "https" or not hostname:
raise ValueError(f"Unsupported image download URL: {image_url}")
if not any(_hostname_matches(hostname, allowed_host) for allowed_host in allowed_hosts):
if not any(
_hostname_matches(hostname, allowed_host) for allowed_host in allowed_hosts
):
raise ValueError(f"Image download host is not allowed: {hostname}")