feat: compression 12
This commit is contained in:
1 parent
cc237d092c
commit
cf6b9c35c2
1 file changed
+3
-20
@@ -5,7 +5,7 @@ import { getUserHeaders } from "@/helpers/user.helper";
|
||||
import { clearCompressionDirectory, getCompressionOutputPath } from "@/helpers/compression.server";
|
||||
import { assets } from "@/schema";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { openAsBlob } from "node:fs";
|
||||
import { stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
@@ -15,24 +15,6 @@ const readError = async (response: Response) => {
|
||||
return body || response.statusText || `HTTP ${response.status}`;
|
||||
};
|
||||
|
||||
class UploadFile extends File {
|
||||
constructor(
|
||||
private readonly filePath: string,
|
||||
private readonly fileSize: number,
|
||||
fileName: string,
|
||||
) {
|
||||
super([], fileName);
|
||||
}
|
||||
|
||||
override get size() {
|
||||
return this.fileSize;
|
||||
}
|
||||
|
||||
override stream() {
|
||||
return createReadStream(this.filePath) as any;
|
||||
}
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method !== "POST") return res.status(405).json({ message: "Method not allowed" });
|
||||
|
||||
@@ -85,7 +67,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
const replacementFileName = path.basename(source.originalFileName || dbAsset.originalFileName || `${dbAsset.id}.mp4`);
|
||||
const outputPath = getCompressionOutputPath(dbAsset.id, dbAsset.originalFileName);
|
||||
const outputStats = await stat(outputPath);
|
||||
const uploadFile = new UploadFile(outputPath, outputStats.size, replacementFileName);
|
||||
const uploadFile = await openAsBlob(outputPath);
|
||||
|
||||
// Keep the upload payload aligned with Immich's own CLI uploader.
|
||||
// Restore Power Tools/custom metadata only after Immich has created the asset.
|
||||
@@ -233,6 +215,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
assetId: dbAsset.id,
|
||||
message: error?.message,
|
||||
stack: error?.stack,
|
||||
cause: error?.cause,
|
||||
});
|
||||
if (rollbackSafe && changedLivePhotoParentIds.length > 0) {
|
||||
await Promise.all(changedLivePhotoParentIds.map((parentId) =>
|
||||
|
||||
Reference in new issue
Block a user