mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Update image uploading to generate social media formats on demand
Remove eager transformations from Cloudinary uploads and generate transformation URLs manually using `cloudinary.url` with `lpad` crop, enabling dynamic image resizing for different social media platforms. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/74fmQLN
This commit is contained in:
1 parent
b6929e7830
commit
a641ec69a0
2 files changed
+30
-19
No files matched your search
@@ -18,10 +18,6 @@ externalPort = 80
|
|||||||
localPort = 5555
|
localPort = 5555
|
||||||
externalPort = 3002
|
externalPort = 3002
|
||||||
|
|
||||||
[[ports]]
|
|
||||||
localPort = 33429
|
|
||||||
externalPort = 3003
|
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 40537
|
localPort = 40537
|
||||||
externalPort = 3000
|
externalPort = 3000
|
||||||
|
|||||||
@@ -31,22 +31,13 @@ class CloudinaryService {
|
|||||||
|
|
||||||
const isVideo = mimeType.startsWith('video/');
|
const isVideo = mimeType.startsWith('video/');
|
||||||
|
|
||||||
// Define eager transformations for images (generated during upload)
|
// Upload to Cloudinary (without eager transformations)
|
||||||
const eagerTransformations = !isVideo ? [
|
|
||||||
{ width: 1200, height: 630, crop: 'pad', gravity: 'center', background: 'black' }, // Facebook Feed
|
|
||||||
{ width: 1080, height: 1080, crop: 'pad', gravity: 'center', background: 'black' }, // Instagram Feed
|
|
||||||
{ width: 1080, height: 1920, crop: 'pad', gravity: 'center', background: 'black' } // Instagram Story
|
|
||||||
] : undefined;
|
|
||||||
|
|
||||||
// Upload to Cloudinary with eager transformations
|
|
||||||
const uploadResult = await new Promise<any>((resolve, reject) => {
|
const uploadResult = await new Promise<any>((resolve, reject) => {
|
||||||
const uploadStream = cloudinary.uploader.upload_stream(
|
const uploadStream = cloudinary.uploader.upload_stream(
|
||||||
{
|
{
|
||||||
folder: 'social-flow',
|
folder: 'social-flow',
|
||||||
public_id: `${Date.now()}-${fileName.replace(/\.[^/.]+$/, '')}`,
|
public_id: `${Date.now()}-${fileName.replace(/\.[^/.]+$/, '')}`,
|
||||||
resource_type: isVideo ? 'video' : 'image',
|
resource_type: isVideo ? 'video' : 'image',
|
||||||
eager: eagerTransformations,
|
|
||||||
eager_async: false, // Generate transformations immediately
|
|
||||||
},
|
},
|
||||||
(error, result) => {
|
(error, result) => {
|
||||||
if (error) reject(error);
|
if (error) reject(error);
|
||||||
@@ -60,15 +51,39 @@ class CloudinaryService {
|
|||||||
const publicId = uploadResult.public_id;
|
const publicId = uploadResult.public_id;
|
||||||
const originalUrl = uploadResult.secure_url;
|
const originalUrl = uploadResult.secure_url;
|
||||||
|
|
||||||
// Extract eager transformation URLs (generated by Cloudinary during upload)
|
// Generate transformation URLs manually with lpad (limit pad) for images
|
||||||
let facebookFeedUrl = null;
|
let facebookFeedUrl = null;
|
||||||
let instagramFeedUrl = null;
|
let instagramFeedUrl = null;
|
||||||
let instagramStoryUrl = null;
|
let instagramStoryUrl = null;
|
||||||
|
|
||||||
if (!isVideo && uploadResult.eager && uploadResult.eager.length === 3) {
|
if (!isVideo) {
|
||||||
facebookFeedUrl = uploadResult.eager[0].secure_url; // Facebook Feed (1200x630)
|
// Use lpad (limit pad) - only scales down if needed, adds padding to fit dimensions
|
||||||
instagramFeedUrl = uploadResult.eager[1].secure_url; // Instagram Feed (1080x1080)
|
facebookFeedUrl = cloudinary.url(publicId, {
|
||||||
instagramStoryUrl = uploadResult.eager[2].secure_url; // Instagram Story (1080x1920)
|
width: 1200,
|
||||||
|
height: 630,
|
||||||
|
crop: 'lpad',
|
||||||
|
background: 'black',
|
||||||
|
fetch_format: 'auto',
|
||||||
|
quality: 'auto'
|
||||||
|
});
|
||||||
|
|
||||||
|
instagramFeedUrl = cloudinary.url(publicId, {
|
||||||
|
width: 1080,
|
||||||
|
height: 1080,
|
||||||
|
crop: 'lpad',
|
||||||
|
background: 'black',
|
||||||
|
fetch_format: 'auto',
|
||||||
|
quality: 'auto'
|
||||||
|
});
|
||||||
|
|
||||||
|
instagramStoryUrl = cloudinary.url(publicId, {
|
||||||
|
width: 1080,
|
||||||
|
height: 1920,
|
||||||
|
crop: 'lpad',
|
||||||
|
background: 'black',
|
||||||
|
fetch_format: 'auto',
|
||||||
|
quality: 'auto'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in new issue
Block a user