image detection not working
This commit is contained in:
@@ -3,7 +3,6 @@ import requests
|
|||||||
import re
|
import re
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
@@ -204,31 +203,21 @@ def push_to_gitea_wiki(local_dir, pages):
|
|||||||
if found_images:
|
if found_images:
|
||||||
logger.info(f"Found images on page '{title}': {found_images}")
|
logger.info(f"Found images on page '{title}': {found_images}")
|
||||||
|
|
||||||
# Download images referenced in the content
|
# Process all !image! patterns in the content
|
||||||
# First, we need to find all image URLs and download them
|
original_content = markdown_content
|
||||||
# Look for Redmine-style image tags like !image.png!
|
|
||||||
def replace_image(match):
|
|
||||||
image_name = match.group(1)
|
|
||||||
|
|
||||||
# Try to find the actual image URL by searching for it in the page content
|
# Find all image tags in the format !image_name!
|
||||||
# This is a simplified approach - we'll assume the image name matches
|
image_tags = re.findall(r'!(.*?)!', original_content)
|
||||||
# what's found in Redmine's image system
|
|
||||||
if image_name:
|
|
||||||
# In Redmine, images are usually at /attachments/... path
|
|
||||||
image_url = f"/attachments/download/{image_name}"
|
|
||||||
logger.info(f"Attempting to download image: {image_name}")
|
|
||||||
|
|
||||||
downloaded_path = download_image(image_url, local_dir)
|
# For each image tag, attempt to download it and replace it with Markdown syntax
|
||||||
if downloaded_path:
|
for image_tag in image_tags:
|
||||||
return f""
|
if image_tag and not image_tag.startswith('\\'):
|
||||||
else:
|
logger.info(f"Found image tag: {image_tag}")
|
||||||
# If download fails, keep the original format
|
# Replace the specific tag with our download logic
|
||||||
return f"!{image_name}!"
|
markdown_content = markdown_content.replace(
|
||||||
return match.group(0)
|
f"!{image_tag}!",
|
||||||
|
handle_image_tag(image_tag, local_dir)
|
||||||
# We need to handle both !image.png! and  formats
|
)
|
||||||
# For now, we'll process !image.png! patterns specifically
|
|
||||||
markdown_content = re.sub(image_pattern, replace_image, markdown_content)
|
|
||||||
|
|
||||||
# Write to file
|
# Write to file
|
||||||
with open(filepath, 'w', encoding='utf-8') as f:
|
with open(filepath, 'w', encoding='utf-8') as f:
|
||||||
@@ -245,6 +234,30 @@ def push_to_gitea_wiki(local_dir, pages):
|
|||||||
|
|
||||||
logger.info("✅ Wiki pages pushed to Gitea!")
|
logger.info("✅ Wiki pages pushed to Gitea!")
|
||||||
|
|
||||||
|
def handle_image_tag(image_name, local_dir):
|
||||||
|
"""Handle replacement of image tags with downloaded images"""
|
||||||
|
# Check if the image has a valid extension (.png, .jpg, or .jpeg)
|
||||||
|
valid_extensions = ('.png', '.jpg', '.jpeg')
|
||||||
|
if not any(image_name.lower().endswith(ext) for ext in valid_extensions):
|
||||||
|
logger.warning(f"Invalid image extension in tag: {image_name}")
|
||||||
|
return f"!{image_name}!" # Return original format for invalid extensions
|
||||||
|
|
||||||
|
if image_name and not image_name.startswith('\\'):
|
||||||
|
# In Redmine, images are usually at /attachments/... path
|
||||||
|
image_url = f"/attachments/download/{image_name}"
|
||||||
|
logger.info(f"Attempting to download image: {image_name}")
|
||||||
|
|
||||||
|
# Try to download the image
|
||||||
|
downloaded_path = download_image(image_url, local_dir)
|
||||||
|
if downloaded_path:
|
||||||
|
return f""
|
||||||
|
else:
|
||||||
|
# If download fails, keep the original format
|
||||||
|
return f"!{image_name}!"
|
||||||
|
else:
|
||||||
|
# This is likely a regex capture group that wasn't meant to be an image
|
||||||
|
return f"!{image_name}!"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Step 1: Get wiki pages from Redmine
|
# Step 1: Get wiki pages from Redmine
|
||||||
logger.info("Fetching Redmine wiki pages...")
|
logger.info("Fetching Redmine wiki pages...")
|
||||||
|
|||||||
Reference in New Issue
Block a user