commit
This commit is contained in:
@@ -181,9 +181,28 @@ class XHSPublishService:
|
||||
|
||||
local_images = []
|
||||
|
||||
# OSS域名前缀(用于补充不完整的图片路径)
|
||||
oss_prefix = "https://bxmkb-beijing.oss-cn-beijing.aliyuncs.com/Images/"
|
||||
|
||||
print(f"\n正在处理 {len(images)} 张图片...", file=sys.stderr)
|
||||
|
||||
for i, img in enumerate(images):
|
||||
# 检查是否需要补充OSS前缀
|
||||
original_img = img
|
||||
print(f" [调试] 处理图片 {i+1}: '{img}'", file=sys.stderr)
|
||||
print(f" [调试] is_url={self.is_url(img)}, isabs={os.path.isabs(img)}", file=sys.stderr)
|
||||
|
||||
if not self.is_url(img) and not os.path.isabs(img):
|
||||
# 不是URL也不是绝对路径,检查是否需要补充OSS前缀
|
||||
print(f" [调试] 不是URL也不是绝对路径", file=sys.stderr)
|
||||
# 如果路径不包含协议且不以/开头,可能是相对OSS路径
|
||||
if '/' in img and not img.startswith('/'):
|
||||
# 可能是OSS相对路径,补充前缀
|
||||
img = oss_prefix + img
|
||||
print(f" ✅ 检测到相对路径,补充OSS前缀: {original_img} -> {img}", file=sys.stderr)
|
||||
else:
|
||||
print(f" [调试] 不满足补充条件: '/' in img={('/' in img)}, not startswith('/')={not img.startswith('/')}", file=sys.stderr)
|
||||
|
||||
if self.is_url(img):
|
||||
# 网络URL,需要下载
|
||||
try:
|
||||
@@ -195,9 +214,25 @@ class XHSPublishService:
|
||||
continue
|
||||
else:
|
||||
# 本地路径
|
||||
if os.path.exists(img):
|
||||
local_images.append(os.path.abspath(img))
|
||||
print(f" ✅ 本地图片 [{i + 1}]: {os.path.basename(img)}", file=sys.stderr)
|
||||
# 先尝试直接使用,如果不存在则尝试相对路径
|
||||
abs_path = None
|
||||
|
||||
# 1. 尝试作为绝对路径
|
||||
if os.path.isabs(img) and os.path.exists(img):
|
||||
abs_path = img
|
||||
# 2. 尝试相对于当前工作目录
|
||||
elif os.path.exists(img):
|
||||
abs_path = os.path.abspath(img)
|
||||
# 3. 尝试相对于 static 目录
|
||||
elif os.path.exists(os.path.join('static', img)):
|
||||
abs_path = os.path.abspath(os.path.join('static', img))
|
||||
# 4. 尝试相对于 ../go_backend/static 目录
|
||||
elif os.path.exists(os.path.join('..', 'go_backend', 'static', img)):
|
||||
abs_path = os.path.abspath(os.path.join('..', 'go_backend', 'static', img))
|
||||
|
||||
if abs_path:
|
||||
local_images.append(abs_path)
|
||||
print(f" ✅ 本地图片 [{i + 1}]: {os.path.basename(abs_path)} ({abs_path})", file=sys.stderr)
|
||||
else:
|
||||
print(f" ⚠️ 本地图片不存在: {img}", file=sys.stderr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user