30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
import sqlite3, json
|
|
conn = sqlite3.connect('cms.db')
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT id, content FROM home_modules WHERE type='features'")
|
|
row = c.fetchone()
|
|
if row:
|
|
content = json.loads(row[1])
|
|
items = content.get('items', [])
|
|
fixed = False
|
|
for i, item in enumerate(items):
|
|
# 同步 image 和 media_url:如果 image 有值,media_url 应该一致
|
|
if item.get('image') and item.get('image') != item.get('media_url'):
|
|
print(f'[{i}] sync media_url to image: {item["image"]}')
|
|
item['media_url'] = item['image']
|
|
fixed = True
|
|
# 第一个 item 的特殊修复:如果 media_url 指向不存在的 202604 文件且 image 为空
|
|
if i == 0 and item.get('media_url') == '/storage/admin/images/202604/1aaf94e5.jpg' and not item.get('image'):
|
|
print(f'[{i}] fix broken media_url to feature1.png')
|
|
item['media_url'] = '/storage/admin/images/features/feature1.png'
|
|
fixed = True
|
|
if fixed:
|
|
c.execute("UPDATE home_modules SET content = ? WHERE type = 'features'",
|
|
(json.dumps(content, ensure_ascii=False),))
|
|
conn.commit()
|
|
print('fixed and saved')
|
|
else:
|
|
print('no fix needed')
|
|
conn.close()
|