This commit is contained in:
董海洋
2026-05-24 17:48:20 +08:00
parent e41eb624b9
commit e532e48e47
3 changed files with 33 additions and 5 deletions
+9 -4
View File
@@ -1,11 +1,16 @@
const mysql = require('mysql2/promise');
const config = require('../config/database');
const { DOMAIN_CONFIG } = require('../config/domain');
async function fixImageUrls() {
try {
const connection = await mysql.createConnection(config);
console.log('✅ 数据库连接成功\n');
// 获取当前配置的域名
const targetDomain = DOMAIN_CONFIG.BASE_URL;
console.log(`🎯 目标域名: ${targetDomain}\n`);
// 查找包含旧地址的记录
console.log('🔍 检查数据库中的图片URL...');
const [goods] = await connection.execute('SELECT id, images FROM goods WHERE images LIKE "%localhost%"');
@@ -18,8 +23,8 @@ async function fixImageUrls() {
const oldImages = item.images;
// 替换所有 localhost:3000 和 localhost:3006
let newImages = oldImages
.replace(/http:\/\/localhost:3000/g, 'https://donghy.top')
.replace(/http:\/\/localhost:3006/g, 'https://donghy.top');
.replace(/http:\/\/localhost:3000/g, targetDomain)
.replace(/http:\/\/localhost:3006/g, targetDomain);
await connection.execute(
'UPDATE goods SET images = ? WHERE id = ?',
@@ -41,8 +46,8 @@ async function fixImageUrls() {
if (item.images) {
const oldImages = item.images;
let newImages = oldImages
.replace(/http:\/\/localhost:3000/g, 'https://donghy.top')
.replace(/http:\/\/localhost:3006/g, 'https://donghy.top');
.replace(/http:\/\/localhost:3000/g, targetDomain)
.replace(/http:\/\/localhost:3006/g, targetDomain);
await connection.execute(
'UPDATE points_goods SET images = ? WHERE id = ?',