mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
The commit refactors the chunked upload system to support a transformation pipeline. Key changes include: - Replace SSE field names for consistency (sseChannelId, sseUrl) - Fix progress reporting structure with state and percent fields - Add transformation handlers (a-dash, mq-hls, img-compress, video-compress) - Create new Upload class with clear separation of concerns - Improve file processing workflow with better directory structure - Fix typo in UploadButton component (progess → progress) - Remove deprecated file processing services
44 lines
874 B
JavaScript
44 lines
874 B
JavaScript
import fs from "node:fs"
|
|
import path from "node:path"
|
|
|
|
import Sharp from "sharp"
|
|
|
|
const imageProcessingConf = {
|
|
sizeThreshold: 10 * 1024 * 1024,
|
|
imageQuality: 80,
|
|
}
|
|
|
|
const imageTypeToConfig = {
|
|
png: {
|
|
compressionLevel: Math.floor(imageProcessingConf.imageQuality / 100),
|
|
},
|
|
default: {
|
|
quality: imageProcessingConf.imageQuality,
|
|
},
|
|
}
|
|
|
|
export default async ({ filePath, workPath }) => {
|
|
const stat = await fs.promises.stat(file.filepath)
|
|
|
|
// ignore if too small
|
|
if (stat.size < imageProcessingConf.sizeThreshold) {
|
|
return file
|
|
}
|
|
|
|
let image = await Sharp(filePath)
|
|
|
|
const { format } = await image.metadata()
|
|
|
|
image = await image[format](
|
|
imageTypeToConfig[format] ?? imageTypeToConfig.default,
|
|
).withMetadata()
|
|
|
|
filePath = path.resolve(workPath, `${path.basename(filePath)}_ff`)
|
|
|
|
await image.toFile(outputFilepath)
|
|
|
|
return {
|
|
filePath: filePath,
|
|
}
|
|
}
|