maplestory/backend/services/image.js
caadiq 921ce9676b 이미지 다중 업로드/삭제 및 중복 방지 추가
- 한 번에 여러 이미지 업로드 (드래그/선택, 개별 이름 수정/제거)
- 다중 선택 삭제 모드 (선택 모드 토글, 전체 선택)
- 커스텀 확인 다이얼로그 (네이티브 confirm 대체)
- 이미지 이름 unique 제약 + 입력 시 실시간 중복/빈 값 검증
- 백엔드 다중 업로드 시 사전 중복 체크
- 카드에서 URL 표시 제거

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:42:51 +09:00

31 lines
877 B
JavaScript

import sharp from 'sharp';
import crypto from 'crypto';
import { uploadObject, deleteObject } from '../lib/s3.js';
/**
* 이미지를 webp로 변환하고 RustFS에 업로드
* @param {Buffer} buffer - 원본 이미지 버퍼
* @returns {Promise<{path: string, width: number, height: number, size: number}>}
*/
export async function convertAndUpload(buffer) {
const webpBuffer = await sharp(buffer)
.webp({ quality: 90 })
.toBuffer();
const metadata = await sharp(webpBuffer).metadata();
const hash = crypto.createHash('sha256').update(webpBuffer).digest('hex').slice(0, 16);
const path = `common/${hash}.webp`;
await uploadObject(path, webpBuffer, 'image/webp');
return {
path,
width: metadata.width,
height: metadata.height,
size: webpBuffer.length,
};
}
export async function deleteFromS3(path) {
await deleteObject(path);
}