Skip to content

Commit

Permalink
Check file
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed May 10, 2022
1 parent 2b9d911 commit 55b60cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/src/lib/media/Convert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import spawn from '@expo/spawn-async';
import * as fs from 'node:fs/promises';
import path from 'node:path';

export async function resizeImage(src: string, dst: string, maxSize: number) {
Expand Down Expand Up @@ -27,6 +28,10 @@ export async function resizeImage(src: string, dst: string, maxSize: number) {
if(r.status !== 0) {
throw new Error(`Failed to convert: ${r.stderr}`);
}
const stat = await fs.lstat(dst);
if(!stat.isFile()) {
throw new Error(`File not generated: ${src} -> ${dst}`);
}
}

export async function makeImageIcon(src: string, dst: string, size: number) {
Expand All @@ -43,6 +48,10 @@ export async function makeImageIcon(src: string, dst: string, size: number) {
if(r.status !== 0) {
throw new Error(`Failed to convert: ${r.stderr}`);
}
const stat = await fs.lstat(dst);
if(!stat.isFile()) {
throw new Error(`File not generated: ${src} -> ${dst}`);
}
}

export async function makeVideoIcon(src: string, dst: string, at: number, size: number) {
Expand All @@ -58,6 +67,10 @@ export async function makeVideoIcon(src: string, dst: string, at: number, size:
if(r.status !== 0) {
throw new Error(`Failed to convert: ${r.stderr}`);
}
const stat = await fs.lstat(dst);
if(!stat.isFile()) {
throw new Error(`File not generated: ${src} -> ${dst}`);
}
}

export async function makeAudioIcon(src: string, dst: string, at: number, size: number) {
Expand All @@ -75,4 +88,8 @@ export async function makeAudioIcon(src: string, dst: string, at: number, size:
if(r.status !== 0) {
throw new Error(`Failed to convert: ${r.stderr}`);
}
const stat = await fs.lstat(dst);
if(!stat.isFile()) {
throw new Error(`File not generated: ${src} -> ${dst}`);
}
}

0 comments on commit 55b60cd

Please sign in to comment.