perf(build): make standalone image deterministic

This commit is contained in:
2026-08-09 21:34:00 +07:00 Unverified
parent c06b2ef88f
commit 1dc44e0215
10 changed files with 65 additions and 32 deletions
+3 -3
View File
@@ -219,7 +219,7 @@ async function publishYoutube(upload: typeof videoUploads.$inferSelect) {
throw new Error(`YouTube upload initialization failed (${init.status}).`);
const location = init.headers.get("location");
if (!location) throw new Error("YouTube did not return an upload URL.");
const video = await readFile(upload.videoPath);
const video = await readFile(/* turbopackIgnore: true */ upload.videoPath);
const result = await fetch(location, {
method: "PUT",
headers: {
@@ -233,7 +233,7 @@ async function publishYoutube(upload: typeof videoUploads.$inferSelect) {
const data = (await result.json()) as { id?: string };
if (!data.id) throw new Error("YouTube did not return a video ID.");
if (upload.thumbnailPath) {
const thumbnail = await readFile(upload.thumbnailPath);
const thumbnail = await readFile(/* turbopackIgnore: true */ upload.thumbnailPath);
const thumb = await fetch(
`https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=${encodeURIComponent(data.id)}`,
{
@@ -279,7 +279,7 @@ async function publishTiktok(upload: typeof videoUploads.$inferSelect) {
settings.privacyLevel ??
creator.data?.privacy_level_options?.[0] ??
"SELF_ONLY";
const video = await readFile(upload.videoPath);
const video = await readFile(/* turbopackIgnore: true */ upload.videoPath);
const chunkSize = Math.min(10 * 1024 * 1024, video.byteLength);
const totalChunkCount = Math.max(1, Math.floor(video.byteLength / chunkSize));
const init = await fetch(
+5 -5
View File
@@ -34,24 +34,24 @@ export async function saveVideoUpload(formData: FormData, discordId: string) {
throw new Error("Invalid staged video.");
}
const stagingDirectory = `${VIDEO_DIR}/staging/${discordId}`;
const stagedFile = (await readdir(stagingDirectory)).find((name) =>
const stagedFile = (await readdir(/* turbopackIgnore: true */ stagingDirectory)).find((name) =>
name.startsWith(`${stagedVideoId}-`),
);
if (!stagedFile) throw new Error("Uploaded video was not found.");
videoPath = `${stagingDirectory}/${stagedFile}`;
originalFilename = String(formData.get("videoName") ?? stagedFile);
mimeType = String(formData.get("videoMimeType") ?? "");
videoSize = (await stat(videoPath)).size;
videoSize = (await stat(/* turbopackIgnore: true */ videoPath)).size;
if (!["video/mp4", "video/quicktime", "video/webm"].includes(mimeType)) {
throw new Error("Use an MP4, MOV, or WebM video.");
}
} else if (video instanceof File) {
validateVideoFile(video);
await mkdir(VIDEO_DIR, { recursive: true });
await mkdir(/* turbopackIgnore: true */ VIDEO_DIR, { recursive: true });
const temporaryId = randomUUID();
const safeVideoName = video.name.replace(/[^a-zA-Z0-9._-]/g, "_");
videoPath = `${VIDEO_DIR}/${temporaryId}-${safeVideoName}`;
await writeFile(videoPath, Buffer.from(await video.arrayBuffer()));
await writeFile(/* turbopackIgnore: true */ videoPath, Buffer.from(await video.arrayBuffer()));
originalFilename = video.name;
mimeType = video.type;
videoSize = video.size;
@@ -74,7 +74,7 @@ export async function saveVideoUpload(formData: FormData, discordId: string) {
let thumbnailPath: string | null = null;
if (thumbnail instanceof File && thumbnail.size > 0) {
thumbnailPath = `${VIDEO_DIR}/${id}-thumbnail-${thumbnail.name.replace(/[^a-zA-Z0-9._-]/g, "_")}`;
await writeFile(thumbnailPath, Buffer.from(await thumbnail.arrayBuffer()));
await writeFile(/* turbopackIgnore: true */ thumbnailPath, Buffer.from(await thumbnail.arrayBuffer()));
}
const youtubeSettings: YoutubeSettings = JSON.parse(