Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b26587a41 | |||
16192e00a2 |
@ -127,23 +127,28 @@ def download_images():
|
|||||||
else:
|
else:
|
||||||
messagebox.showwarning("警告", "没有图片被下载")
|
messagebox.showwarning("警告", "没有图片被下载")
|
||||||
|
|
||||||
def upload_image_to_lsky_pro(image_path):
|
def upload_image_to_lsky_pro(image_path, retries=3, timeout=30):
|
||||||
"""上传图片到Lsky Pro图床"""
|
"""上传图片到Lsky Pro图床,增加重试机制和超时设置"""
|
||||||
with open(image_path, 'rb') as img_file:
|
for attempt in range(retries):
|
||||||
files = {'file': img_file}
|
try:
|
||||||
headers = {
|
with open(image_path, 'rb') as img_file:
|
||||||
'Authorization': f'Bearer {token}',
|
files = {'file': img_file}
|
||||||
'Accept': 'application/json'
|
headers = {
|
||||||
}
|
'Authorization': f'Bearer {token}',
|
||||||
response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers)
|
'Accept': 'application/json'
|
||||||
if response.status_code == 200:
|
}
|
||||||
try:
|
response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers, timeout=timeout)
|
||||||
data = response.json()
|
if response.status_code == 200:
|
||||||
if data['status']:
|
try:
|
||||||
return data['data']['links']['url']
|
data = response.json()
|
||||||
except:
|
if data['status']:
|
||||||
pass
|
return data['data']['links']['url']
|
||||||
return None
|
except:
|
||||||
|
pass
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"上传失败,重试 {attempt + 1}/{retries}: {str(e)}")
|
||||||
|
time.sleep(3) # 重试前等待3秒
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -182,8 +187,8 @@ def process_image_file(markdown_file_path):
|
|||||||
|
|
||||||
# 构造新的文件名
|
# 构造新的文件名
|
||||||
file_name, file_ext = os.path.splitext(markdown_file_path)
|
file_name, file_ext = os.path.splitext(markdown_file_path)
|
||||||
new_file_path = f"{file_name}_lsky{file_ext}"
|
#new_file_path = f"{file_name}_lsky{file_ext}"
|
||||||
|
new_file_path = f"{file_name}{file_ext}"
|
||||||
# 保存为新文件
|
# 保存为新文件
|
||||||
with open(new_file_path, 'w', encoding='utf-8') as file:
|
with open(new_file_path, 'w', encoding='utf-8') as file:
|
||||||
file.write(new_content)
|
file.write(new_content)
|
||||||
@ -309,24 +314,18 @@ def download_and_upload_images():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
messagebox.showerror("错误", f"处理过程中出错: {str(e)}")
|
messagebox.showerror("错误", f"处理过程中出错: {str(e)}")
|
||||||
|
|
||||||
|
def upload_images_batch_files(file_paths, max_concurrent_uploads=5):
|
||||||
|
"""批量上传图片,限制并发上传数量"""
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=max_concurrent_uploads) as executor:
|
||||||
|
futures = {executor.submit(process_image_file, file_path): file_path for file_path in file_paths}
|
||||||
def upload_images_batch_files(file_paths):
|
for future in as_completed(futures):
|
||||||
# """ 你的图片上传逻辑(需自行实现) """
|
file_path = futures[future]
|
||||||
for file_path in file_paths:
|
try:
|
||||||
# 这里添加处理每个文件的逻辑
|
future.result()
|
||||||
if not file_path or not os.path.isfile(file_path):
|
except Exception as e:
|
||||||
messagebox.showwarning("警告", "请选择有效的Markdown文件。")
|
print(f"处理文件 {file_path} 时出错: {str(e)}")
|
||||||
return
|
|
||||||
|
|
||||||
print(f"Processing: {file_path}")
|
|
||||||
process_image_file(file_path)
|
|
||||||
|
|
||||||
# 示例:读取markdown文件内容
|
|
||||||
# with open(file_path, 'r') as f:
|
|
||||||
# content = f.read()
|
|
||||||
# 添加你的图片上传逻辑...
|
|
||||||
|
|
||||||
def select_files():
|
def select_files():
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
|
@ -3,7 +3,8 @@ import requests
|
|||||||
|
|
||||||
# 配置信息
|
# 配置信息
|
||||||
local_image_folder = 'downloaded_images'
|
local_image_folder = 'downloaded_images'
|
||||||
lsky_pro_url = 'http://192.168.107.248:18089/api/v1'
|
#lsky_pro_url = 'http://192.168.107.248:18089/api/v1'
|
||||||
|
lsky_pro_url = 'https://image.lqsjy.cn/api/v1'
|
||||||
upload_endpoint = '/upload'
|
upload_endpoint = '/upload'
|
||||||
token = '1|QJP2YEr9GIN52VBgmm5hCqV5DwBSvJLUKjnwcKB8'
|
token = '1|QJP2YEr9GIN52VBgmm5hCqV5DwBSvJLUKjnwcKB8'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user