first commit
This commit is contained in:
162
routes/merchbay.js
Normal file
162
routes/merchbay.js
Normal file
@@ -0,0 +1,162 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { checkScreenshotsExist, generateScreenshots, buildResponsePayload } = require('../utils/screenshot');
|
||||
const { viewerUrls } = require('../config/config');
|
||||
|
||||
/**
|
||||
* Merchbay T-Shirt screenshot handler (4 views: front, back, right, left)
|
||||
* Route: GET /merchbay/tshirt/:designId
|
||||
*/
|
||||
router.get('/tshirt/:designId', async (req, res) => {
|
||||
try {
|
||||
const designId = req.params.designId;
|
||||
console.log('Merchbay T-Shirt screenshot request for design:', designId);
|
||||
|
||||
const filenames = {
|
||||
thumb_front: `${designId}-front-thumbnail.png`,
|
||||
thumb_back: `${designId}-back-thumbnail.png`,
|
||||
thumb_right: `${designId}-right-thumbnail.png`,
|
||||
thumb_left: `${designId}-left-thumbnail.png`
|
||||
};
|
||||
|
||||
// Check if screenshots already exist
|
||||
if (checkScreenshotsExist(Object.values(filenames))) {
|
||||
console.log('Screenshots already exist, returning cached versions');
|
||||
return res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
}
|
||||
|
||||
// Generate new screenshots
|
||||
const url = `${viewerUrls.merchbay}${designId}/`;
|
||||
const clipConfigs = [
|
||||
{
|
||||
filename: filenames.thumb_front,
|
||||
clip: { x: 120, y: 37.11, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_back,
|
||||
clip: { x: 776.967, y: 37.11, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_right,
|
||||
clip: { x: 120, y: 557, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_left,
|
||||
clip: { x: 776.967, y: 557, width: 470, height: 520 }
|
||||
}
|
||||
];
|
||||
|
||||
await generateScreenshots(url, clipConfigs);
|
||||
|
||||
res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
} catch (error) {
|
||||
console.error('Merchbay T-Shirt screenshot error:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to generate screenshots',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Merchbay All-Over Print screenshot handler (2 views: front, back)
|
||||
* Route: GET /merchbay/allover/:designId
|
||||
*/
|
||||
router.get('/allover/:designId', async (req, res) => {
|
||||
try {
|
||||
const designId = req.params.designId;
|
||||
console.log('Merchbay All-Over Print screenshot request for design:', designId);
|
||||
|
||||
const filenames = {
|
||||
thumb_front: `${designId}-front-thumbnail.png`,
|
||||
thumb_back: `${designId}-back-thumbnail.png`
|
||||
};
|
||||
|
||||
// Check if screenshots already exist
|
||||
if (checkScreenshotsExist(Object.values(filenames))) {
|
||||
console.log('Screenshots already exist, returning cached versions');
|
||||
return res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
}
|
||||
|
||||
// Generate new screenshots
|
||||
const url = `${viewerUrls.merchbay}${designId}/`;
|
||||
const clipConfigs = [
|
||||
{
|
||||
filename: filenames.thumb_front,
|
||||
clip: { x: 56.5, y: 40, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_back,
|
||||
clip: { x: 716.78, y: 40, width: 470, height: 520 }
|
||||
}
|
||||
];
|
||||
|
||||
await generateScreenshots(url, clipConfigs);
|
||||
|
||||
res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
} catch (error) {
|
||||
console.error('Merchbay All-Over Print screenshot error:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to generate screenshots',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Merchbay Legacy T-Shirt screenshot handler (4 views: front, back, right, left)
|
||||
* Uses legacy viewer URL format
|
||||
* Route: GET /merchbay/legacy/:designId
|
||||
*/
|
||||
router.get('/legacy/:designId', async (req, res) => {
|
||||
try {
|
||||
const designId = req.params.designId;
|
||||
console.log('Merchbay Legacy screenshot request for design:', designId);
|
||||
|
||||
const filenames = {
|
||||
thumb_front: `${designId}-front-thumbnail.png`,
|
||||
thumb_back: `${designId}-back-thumbnail.png`,
|
||||
thumb_right: `${designId}-right-thumbnail.png`,
|
||||
thumb_left: `${designId}-left-thumbnail.png`
|
||||
};
|
||||
|
||||
// Check if screenshots already exist
|
||||
if (checkScreenshotsExist(Object.values(filenames))) {
|
||||
console.log('Screenshots already exist, returning cached versions');
|
||||
return res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
}
|
||||
|
||||
// Generate new screenshots using legacy URL format
|
||||
const url = `${viewerUrls.merchbayLegacy}${designId}`;
|
||||
const clipConfigs = [
|
||||
{
|
||||
filename: filenames.thumb_front,
|
||||
clip: { x: 120, y: 37.11, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_back,
|
||||
clip: { x: 776.967, y: 37.11, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_right,
|
||||
clip: { x: 120, y: 557, width: 470, height: 520 }
|
||||
},
|
||||
{
|
||||
filename: filenames.thumb_left,
|
||||
clip: { x: 776.967, y: 557, width: 470, height: 520 }
|
||||
}
|
||||
];
|
||||
|
||||
await generateScreenshots(url, clipConfigs);
|
||||
|
||||
res.status(200).jsonp(buildResponsePayload(filenames));
|
||||
} catch (error) {
|
||||
console.error('Merchbay Legacy screenshot error:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to generate screenshots',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user