mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +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
45 lines
984 B
JavaScript
45 lines
984 B
JavaScript
import path from "node:path"
|
|
import fs from "node:fs"
|
|
|
|
import Upload from "@classes/Upload"
|
|
|
|
export default {
|
|
useContext: ["cache"],
|
|
middlewares: ["withAuthentication"],
|
|
fn: async (req, res) => {
|
|
const workPath = path.resolve(
|
|
this.default.contexts.cache.constructor.cachePath,
|
|
`${req.auth.session.user_id}-${nanoid()}`,
|
|
)
|
|
|
|
await fs.promises.mkdir(workPath, { recursive: true })
|
|
|
|
let localFilepath = null
|
|
|
|
await req.multipart(async (field) => {
|
|
if (!field.file) {
|
|
throw new OperationError(400, "Missing file")
|
|
}
|
|
|
|
localFilepath = path.join(workPath, "file")
|
|
|
|
await field.write(localFilepath)
|
|
})
|
|
|
|
let transformations = req.headers["transformations"]
|
|
|
|
if (transformations) {
|
|
transformations = transformations.split(",").map((t) => t.trim())
|
|
}
|
|
|
|
const result = await Upload.fileHandle({
|
|
user_id: req.auth.session.user_id,
|
|
filePath: localFilepath,
|
|
workPath: workPath,
|
|
transformations: transformations,
|
|
})
|
|
|
|
return result
|
|
},
|
|
}
|