Skip to content

Commit 5546d97

Browse files
junzero741claude
andcommitted
feat(frontend): add 5MB image size validation in editor
Validate image file size before insertion via file picker, drag-and-drop, and paste to show an immediate alert instead of waiting for server rejection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4a670ff commit 5546d97

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/frontend/src/components/Editor.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import Placeholder from '@tiptap/extension-placeholder';
77
import { TextStyle, FontSize } from '@tiptap/extension-text-style';
88
import { useRef, useState, useCallback } from 'react';
99

10+
const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 5MB
11+
12+
function isImageTooLarge(file: File | Blob): boolean {
13+
if (file.size > MAX_IMAGE_SIZE) {
14+
alert('이미지 크기는 5MB 이하만 가능합니다.');
15+
return true;
16+
}
17+
return false;
18+
}
19+
1020
interface EditorProps {
1121
onChange: (html: string) => void;
1222
initialContent?: string;
@@ -69,6 +79,7 @@ export default function Editor({ onChange, initialContent }: EditorProps) {
6979
if (!imageFile) return false;
7080

7181
event.preventDefault();
82+
if (isImageTooLarge(imageFile)) return true;
7283
const blobUrl = URL.createObjectURL(imageFile);
7384
const { schema } = view.state;
7485
const node = schema.nodes.image.create({ src: blobUrl });
@@ -89,6 +100,7 @@ export default function Editor({ onChange, initialContent }: EditorProps) {
89100
event.preventDefault();
90101
const file = imageItem.getAsFile();
91102
if (!file) return false;
103+
if (isImageTooLarge(file)) return true;
92104

93105
const blobUrl = URL.createObjectURL(file);
94106
const { schema } = view.state;
@@ -103,6 +115,7 @@ export default function Editor({ onChange, initialContent }: EditorProps) {
103115
function handleImageInsert(e: React.ChangeEvent<HTMLInputElement>) {
104116
const file = e.target.files?.[0];
105117
if (!file || !editor) return;
118+
if (isImageTooLarge(file)) return;
106119

107120
const blobUrl = URL.createObjectURL(file);
108121
editor.chain().focus().setImage({ src: blobUrl }).run();

0 commit comments

Comments
 (0)