Skip to content

Commit

Permalink
fix: add error logging in FileService writeFileSafe method
Browse files Browse the repository at this point in the history
- Introduced console error logging in the writeFileSafe method of the FileService class to capture and report errors during file write attempts. This enhancement aids in debugging and improves error visibility.
  • Loading branch information
blinko-space committed Dec 17, 2024
1 parent 3de26b5 commit 17604c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/api/file/upload-by-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const POST = async (req: NextRequest, res: NextResponse) => {
const urlPath = new URL(url).pathname;
const originalName = path.basename(urlPath).replaceAll(" ", "_");
const extension = path.extname(originalName);

console.log({ originalName, extension })
const filePath = await FileService.uploadFile(buffer, originalName);

return NextResponse.json({
Expand Down
6 changes: 3 additions & 3 deletions src/components/Common/AttachmentRender/imageRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ type IProps = {
const ImageThumbnailRender = ({ file, className }: { file: FileType, className?: string }) => {
const [isOriginalError, setIsOriginalError] = useState(false);
const [currentSrc, setCurrentSrc] = useState(
file.preview.includes('/api/s3file/') ? file.preview :
`${file.preview}?thumbnail=true`
);

useEffect(() => {
if (isOriginalError) {
setCurrentSrc('/image-fallback.svg')
setCurrentSrc('/image-fallback.svg')
}
}, [isOriginalError])

Expand All @@ -37,7 +38,6 @@ const ImageThumbnailRender = ({ file, className }: { file: FileType, className?:
}
setCurrentSrc(file.preview)
}}
crossOrigin="use-credentials"
className={`object-cover w-full ${className}`}
/>
}
Expand Down Expand Up @@ -73,7 +73,7 @@ const ImageRender = observer((props: IProps) => {
return `max-h-[100px] w-auto`
}
if (!preview && !isPc) {
return `h-[80px] w-[80px] min-w-[80px]`
return `h-[80px] min-w-[80px]`
}
if (imageLength == 1) {
return `h-[200px] max-h-[200px] md:max-w-[200px]`
Expand Down
3 changes: 2 additions & 1 deletion src/server/plugins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export class FileService {

let filename = attempt === 0 ?
`${baseName}${extension}` :
`${baseName}_${attempt}${extension}`;
`${baseName}_${Date.now()}${extension}`;

try {
const filePath = path.join(process.cwd(), `${UPLOAD_FILE_PATH}/` + filename);
await fs.access(filePath);
//@ts-ignore
return this.writeFileSafe(baseName, extension, buffer, attempt + 1);
} catch (error) {
console.error(error)
const filePath = path.join(process.cwd(), `${UPLOAD_FILE_PATH}/` + filename);
//@ts-ignore
await writeFile(filePath, buffer);
Expand Down

0 comments on commit 17604c2

Please sign in to comment.