From 672a8e3bb2b901b4c8285dc604ab80543cfd75ce Mon Sep 17 00:00:00 2001 From: glowzz <24627181@qq.com> Date: Mon, 24 Mar 2025 17:15:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=88=B0Lsky=20Pro=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E5=92=8C=E8=B6=85=E6=97=B6=E8=AE=BE=E7=BD=AE=EF=BC=9B?= =?UTF-8?q?=E8=B0=83=E6=95=B4Markdown=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialogue_download_change.py | 70 ++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/dialogue_download_change.py b/dialogue_download_change.py index ea7373f..f1f9948 100644 --- a/dialogue_download_change.py +++ b/dialogue_download_change.py @@ -127,23 +127,51 @@ def download_images(): else: messagebox.showwarning("警告", "没有图片被下载") -def upload_image_to_lsky_pro(image_path): - """上传图片到Lsky Pro图床""" - with open(image_path, 'rb') as img_file: - files = {'file': img_file} - headers = { - 'Authorization': f'Bearer {token}', - 'Accept': 'application/json' - } - response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers) - if response.status_code == 200: - try: - data = response.json() - if data['status']: - return data['data']['links']['url'] - except: - pass - return None +# def upload_image_to_lsky_pro(image_path): +# """上传图片到Lsky Pro图床""" +# with open(image_path, 'rb') as img_file: +# files = {'file': img_file} +# headers = { +# 'Authorization': f'Bearer {token}', +# 'Accept': 'application/json' +# } +# response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers) +# if response.status_code == 200: +# try: +# data = response.json() +# if data['status']: +# return data['data']['links']['url'] +# except: +# pass +# return None + +def upload_image_to_lsky_pro(image_path, retries=3, timeout=30): + """上传图片到Lsky Pro图床,增加重试机制和超时设置""" + for attempt in range(retries): + try: + with open(image_path, 'rb') as img_file: + files = {'file': img_file} + headers = { + 'Authorization': f'Bearer {token}', + 'Accept': 'application/json' + } + response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers, timeout=timeout) + if response.status_code == 200: + try: + data = response.json() + if data['status']: + return data['data']['links']['url'] + except: + pass + except requests.exceptions.RequestException as e: + print(f"上传失败,重试 {attempt + 1}/{retries}: {str(e)}") + time.sleep(3) # 重试前等待3秒 + return None + + + + + @@ -182,15 +210,17 @@ def process_image_file(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}{file_ext}" # 保存为新文件 with open(new_file_path, 'w', encoding='utf-8') as file: file.write(new_content) - messagebox.showinfo("完成", f"成功处理 {len(url_mapping)} 张图片") + #messagebox.showinfo("完成", f"成功处理 {len(url_mapping)} 张图片") + print(f"{file_name}:成功处理 {len(url_mapping)} 张图片") else: - messagebox.showwarning("警告", "没有图片被处理") + #messagebox.showwarning("警告", "没有图片被处理") + print("没有图片被处理") -- 2.49.0 From bc871faad00acc6af38768de5ae3f5a4fb92511d Mon Sep 17 00:00:00 2001 From: glowzz <24627181@qq.com> Date: Tue, 25 Mar 2025 09:38:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87URL?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BF=A1=E6=81=AF=E8=BE=93=E5=87=BA=E5=B9=B6?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialogue_download_change.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dialogue_download_change.py b/dialogue_download_change.py index f1f9948..2a242d5 100644 --- a/dialogue_download_change.py +++ b/dialogue_download_change.py @@ -186,7 +186,9 @@ def process_image_file(markdown_file_path): for url in image_urls: try: if not url.startswith(('http://', 'https://')): - if 'image.lqsjy.cn' not in url: + if 'image.lqsjy.cn' not in url: + print(f"处理中: {url}") + url = url.split(' ')[0] -- 2.49.0 From 457b37e7c725869feb9cd6930ac208de46e2ea10 Mon Sep 17 00:00:00 2001 From: glowzz <24627181@qq.com> Date: Wed, 26 Mar 2025 15:14:20 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6=E7=9A=84?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=EF=BC=8C=E4=BB=8E3?= =?UTF-8?q?=E7=A7=92=E5=A2=9E=E5=8A=A0=E5=88=B010=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialogue_download_change.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dialogue_download_change.py b/dialogue_download_change.py index 2a242d5..dd9f438 100644 --- a/dialogue_download_change.py +++ b/dialogue_download_change.py @@ -165,7 +165,7 @@ def upload_image_to_lsky_pro(image_path, retries=3, timeout=30): pass except requests.exceptions.RequestException as e: print(f"上传失败,重试 {attempt + 1}/{retries}: {str(e)}") - time.sleep(3) # 重试前等待3秒 + time.sleep(10) # 重试前等待3秒 return None -- 2.49.0 From 85dd93ffe63f174da28b90ebef75f53d8e0151a4 Mon Sep 17 00:00:00 2001 From: glowzz <24627181@qq.com> Date: Fri, 11 Apr 2025 09:56:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AC=E5=9C=B0/?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E5=9B=BE=E5=BA=8A=E5=88=87=E6=8D=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=80=BB=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialogue_download_change.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/dialogue_download_change.py b/dialogue_download_change.py index dd9f438..329815c 100644 --- a/dialogue_download_change.py +++ b/dialogue_download_change.py @@ -11,11 +11,14 @@ import shutil # 配置信息 local_image_folder = 'downloaded_images' -#lsky_pro_url = 'http://192.168.107.248:18089/api/v1' +lsky_pro_url_local = 'http://192.168.107.248:18089/api/v1' lsky_pro_url = 'https://image.lqsjy.cn/api/v1' upload_endpoint = '/upload' token = '1|QJP2YEr9GIN52VBgmm5hCqV5DwBSvJLUKjnwcKB8' +# 添加全局变量控制使用本地/在线图床 +use_local_server = True + # 确保本地图片文件夹存在 #os.makedirs(local_image_folder, exist_ok=True) def get_image_folder(markdown_path): @@ -155,7 +158,12 @@ def upload_image_to_lsky_pro(image_path, retries=3, timeout=30): 'Authorization': f'Bearer {token}', 'Accept': 'application/json' } - response = requests.post(f'{lsky_pro_url}{upload_endpoint}', files=files, headers=headers, timeout=timeout) + # 根据复选框状态选择URL + current_url = lsky_pro_url_local if use_local_server else lsky_pro_url + response = requests.post(f'{current_url}{upload_endpoint}', + files=files, + headers=headers, + timeout=timeout) if response.status_code == 200: try: data = response.json() @@ -193,7 +201,10 @@ def process_image_file(markdown_file_path): # 上传到图床 - new_url = upload_image_to_lsky_pro(url) + if ":" in url: + new_url = upload_image_to_lsky_pro(url) + else: + new_url = upload_image_to_lsky_pro(os.path.dirname(markdown_file_path)+"//"+url) if new_url: url_mapping[url] = new_url print(f"处理成功: {url} -> {new_url}") @@ -379,6 +390,19 @@ def select_files(): root = tk.Tk() root.title("Markdown图片处理工具") +def toggle_server(): + global use_local_server + use_local_server = use_local_var.get() + print(f"使用{'本地' if use_local_server else '在线'}服务器") + +# 添加复选框 +use_local_var = tk.BooleanVar(value=True) # 默认使用本地服务器 +use_local_checkbox = tk.Checkbutton(root, + text="使用本地服务器", + variable=use_local_var, + command=toggle_server) +use_local_checkbox.grid(row=5, column=0, columnspan=3, pady=5) + # 文件路径显示 tk.Label(root, text="Input File:").grid(row=0, column=0, padx=10, pady=10) input_file_entry = tk.Entry(root, width=50) @@ -389,9 +413,9 @@ tk.Button(root, text="Browse", command=choose_input_file).grid(row=0, column=2, download_button = tk.Button(root, text="下载图片", command=download_images) download_button.grid(row=1, column=0, columnspan=3, pady=5) -# 上传图片按钮 -upload_button = tk.Button(root, text="上传图片", command=upload_images) -upload_button.grid(row=2, column=0, columnspan=3, pady=5) +# # 上传图片按钮 +# upload_button = tk.Button(root, text="上传图片", command=upload_images) +# upload_button.grid(row=2, column=0, columnspan=3, pady=5) # 上传图片按钮_batch_files # upload_button = tk.Button(root, text="上传图片_批量", command=upload_images_batch_files) -- 2.49.0