95 lines
3.0 KiB
JavaScript
95 lines
3.0 KiB
JavaScript
/**
|
|
* 修复 APlus_03 的 4K 还原脚本
|
|
*/
|
|
require('dotenv').config();
|
|
const axios = require('axios');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
|
const imageProcessor = require('./lib/image-processor');
|
|
|
|
const API_KEY = 'G9rXx3Ag2Xfa7Gs8zou6t6HqeZ';
|
|
const API_BASE = 'https://api.wuyinkeji.com/api';
|
|
|
|
const r2Client = new S3Client({
|
|
region: 'auto',
|
|
endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
credentials: {
|
|
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
|
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
|
},
|
|
forcePathStyle: true,
|
|
});
|
|
|
|
async function uploadToR2(buffer, filename) {
|
|
const fileName = `fix-aplus03-${Date.now()}-${filename}`;
|
|
await r2Client.send(new PutObjectCommand({
|
|
Bucket: process.env.R2_BUCKET_NAME || 'ai-flow',
|
|
Key: fileName,
|
|
Body: buffer,
|
|
ContentType: 'image/jpeg',
|
|
}));
|
|
return `${process.env.R2_PUBLIC_DOMAIN}/${fileName}`;
|
|
}
|
|
|
|
async function main() {
|
|
const v2Path = path.join(__dirname, 'output_carrier_v2_2025-12-27/APlus_03.jpg');
|
|
const outputDir = path.join(__dirname, 'output_carrier_v3_4K_Upscale_2025-12-29T02-32-52'); // 覆盖到当前的 4K 目录
|
|
|
|
console.log('🛠️ 正在修复 APlus_03.jpg...');
|
|
|
|
const prompt = `
|
|
[FIDELITY ENHANCEMENT - 4K]
|
|
REFERENCE: An Amazon A+ detail module.
|
|
DESCRIPTION:
|
|
- Two panels showing Chanel Brown quilted leather.
|
|
- Left panel has water splashes and "TouchDog" silver logo in small script font.
|
|
- Right panel shows a silver buckle.
|
|
- Bottom has text "LUXURIOUS FEEL & STYLISH DESIGN".
|
|
|
|
STRICT REQUIREMENTS:
|
|
1. 1:1 PIXEL FIDELITY: Keep the layout, logo position (bottom-left of left panel), and fonts EXACTLY as shown in the reference image.
|
|
2. NO REDESIGN: Do not change the logo to capital letters or move it to the center.
|
|
3. QUALITY ONLY: Just enhance the clarity, leather texture sharpness, and metal reflections.
|
|
`.trim();
|
|
|
|
const imgBuffer = fs.readFileSync(v2Path);
|
|
const imgUrl = await uploadToR2(imgBuffer, 'APlus_03.jpg');
|
|
|
|
const payload = {
|
|
key: API_KEY,
|
|
prompt: prompt,
|
|
img_url: imgUrl,
|
|
aspectRatio: '3:2',
|
|
imageSize: '4K'
|
|
};
|
|
|
|
const response = await axios.post(`${API_BASE}/img/nanoBanana-pro`, payload);
|
|
const taskId = response.data.data?.id || response.data.id;
|
|
console.log(` Task ID: ${taskId}`);
|
|
|
|
let resultUrl;
|
|
let attempts = 0;
|
|
while (attempts < 60) {
|
|
const res = await axios.get(`${API_BASE}/img/drawDetail`, { params: { key: API_KEY, id: taskId } });
|
|
if (res.data.data?.status === 2) {
|
|
resultUrl = res.data.data.image_url;
|
|
break;
|
|
}
|
|
process.stdout.write('.');
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
attempts++;
|
|
}
|
|
|
|
if (resultUrl) {
|
|
const res = await axios.get(resultUrl, { responseType: 'arraybuffer' });
|
|
fs.writeFileSync(path.join(outputDir, 'APlus_03.jpg'), Buffer.from(res.data));
|
|
console.log('\n✅ APlus_03.jpg 修复完成并存入 v3 目录');
|
|
}
|
|
}
|
|
|
|
main().catch(console.error);
|
|
|
|
|
|
|