Remove leading slash from 'uploads/' checks in theme URLs
Updated conditions to check 'uploads/' without a leading slash across preview, background, foreground, and asset image URLs. This ensures consistent handling of URLs during the relocation process and avoids potential mismatches in the path string comparison.
This commit is contained in:
@@ -42,19 +42,19 @@ def create_theme(
|
||||
url_updates = {}
|
||||
|
||||
# Move preview image if it exists
|
||||
if theme.preview_image_url and '/uploads/' in theme.preview_image_url:
|
||||
if theme.preview_image_url and 'uploads/' in theme.preview_image_url:
|
||||
new_url = _relocate_theme_file(theme.id, theme.preview_image_url, 'preview', storage)
|
||||
if new_url:
|
||||
url_updates['preview_image_url'] = new_url
|
||||
|
||||
# Move background image if it exists
|
||||
if theme.background_image_url and '/uploads/' in theme.background_image_url:
|
||||
if theme.background_image_url and 'uploads/' in theme.background_image_url:
|
||||
new_url = _relocate_theme_file(theme.id, theme.background_image_url, 'background', storage)
|
||||
if new_url:
|
||||
url_updates['background_image_url'] = new_url
|
||||
|
||||
# Move foreground image if it exists
|
||||
if theme.foreground_image_url and '/uploads/' in theme.foreground_image_url:
|
||||
if theme.foreground_image_url and 'uploads/' in theme.foreground_image_url:
|
||||
new_url = _relocate_theme_file(theme.id, theme.foreground_image_url, 'foreground', storage)
|
||||
if new_url:
|
||||
url_updates['foreground_image_url'] = new_url
|
||||
@@ -63,7 +63,7 @@ def create_theme(
|
||||
if theme.asset_image_urls:
|
||||
new_assets = {}
|
||||
for key, url in theme.asset_image_urls.items():
|
||||
if url and '/uploads/' in url:
|
||||
if url and 'uploads/' in url:
|
||||
new_url = _relocate_theme_file(theme.id, url, f'assets/{key}', storage)
|
||||
if new_url:
|
||||
new_assets[key] = new_url
|
||||
@@ -138,17 +138,17 @@ def update_theme(
|
||||
update_data = theme_in.model_dump(exclude_unset=True)
|
||||
|
||||
# Relocate any image files and update URLs
|
||||
if 'preview_image_url' in update_data and update_data['preview_image_url'] and '/uploads/' in update_data['preview_image_url']:
|
||||
if 'preview_image_url' in update_data and update_data['preview_image_url'] and 'uploads/' in update_data['preview_image_url']:
|
||||
new_url = _relocate_theme_file(theme_id, update_data['preview_image_url'], 'preview', storage)
|
||||
if new_url:
|
||||
update_data['preview_image_url'] = new_url
|
||||
|
||||
if 'background_image_url' in update_data and update_data['background_image_url'] and '/uploads/' in update_data['background_image_url']:
|
||||
if 'background_image_url' in update_data and update_data['background_image_url'] and 'uploads/' in update_data['background_image_url']:
|
||||
new_url = _relocate_theme_file(theme_id, update_data['background_image_url'], 'background', storage)
|
||||
if new_url:
|
||||
update_data['background_image_url'] = new_url
|
||||
|
||||
if 'foreground_image_url' in update_data and update_data['foreground_image_url'] and '/uploads/' in update_data['foreground_image_url']:
|
||||
if 'foreground_image_url' in update_data and update_data['foreground_image_url'] and 'uploads/' in update_data['foreground_image_url']:
|
||||
new_url = _relocate_theme_file(theme_id, update_data['foreground_image_url'], 'foreground', storage)
|
||||
if new_url:
|
||||
update_data['foreground_image_url'] = new_url
|
||||
@@ -156,7 +156,7 @@ def update_theme(
|
||||
if 'asset_image_urls' in update_data and update_data['asset_image_urls']:
|
||||
new_assets = {}
|
||||
for key, url in update_data['asset_image_urls'].items():
|
||||
if url and '/uploads/' in url:
|
||||
if url and 'uploads/' in url:
|
||||
new_url = _relocate_theme_file(theme_id, url, f'assets/{key}', storage)
|
||||
if new_url:
|
||||
new_assets[key] = new_url
|
||||
|
||||
Reference in New Issue
Block a user