Reduce media bandwidth: compress uploads, add long-lived cache headers, gzip API
- Resize/re-encode every uploaded image server-side (posts, avatars, stories, shop products/logo, chat messages) via a shared sharp-based optimizer — caps dimensions to what's actually displayed and re-compresses in place, cutting a typical raw camera photo by ~90% with no visible quality loss - Cap uploaded video resolution/bitrate (re-encode only when above 1280px/ ~2.5Mbps) alongside the existing faststart step; apply faststart+cap to story and chat videos too (previously stored completely raw) - Add long-lived Cache-Control to all /storage static routes so clients stop re-downloading unchanged media on every request - Add gzip/brotli compression for JSON API responses (feed/explore/chat) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ try {
|
||||
} catch (error) {
|
||||
console.warn('[postController] postVideoProcessing unavailable:', error.message)
|
||||
}
|
||||
const { optimizeImageFile } = require('../../../utils/imageOptimize')
|
||||
|
||||
const createPostValidationRules = () => {
|
||||
return [
|
||||
@@ -89,6 +90,14 @@ const createPost = async (req, res) => {
|
||||
? maskPhoneNumbers(String(caption).trim().slice(0, 2000))
|
||||
: null
|
||||
|
||||
// کوچک/فشردهکردنِ عکسها قبل از ذخیره — قبل از اینکه مسیرشون توی دیتابیس بره، چون
|
||||
// مسیر (file.path) دستنخورده میماند، فقط بایتهای خودِ فایل جایگزین میشوند
|
||||
await Promise.all(
|
||||
files
|
||||
.filter((file) => (file.mimetype || file.type || '').startsWith('image/'))
|
||||
.map((file) => optimizeImageFile(file.path))
|
||||
)
|
||||
|
||||
const filePaths = files.map((file) => ({
|
||||
path: file.path,
|
||||
type: (file.mimetype || file.type || '').startsWith('video/') ? 'video' : 'image'
|
||||
|
||||
Reference in New Issue
Block a user