|
|
@@ -8,7 +8,6 @@ import com.zksy.common.utils.file.FileUploadUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -23,12 +22,8 @@ public class AlarmReviewAttachmentService {
|
|
|
if (file == null || file.isEmpty() || file.getSize() > MAX_BYTES)
|
|
|
throw new ServiceException("附件不能为空且单个不得超过10MB");
|
|
|
String name = Objects.toString(file.getOriginalFilename(), "").toLowerCase(Locale.ROOT);
|
|
|
- byte[] header;
|
|
|
- try (InputStream input = file.getInputStream()) { header = input.readNBytes(8); }
|
|
|
- boolean jpeg = (name.endsWith(".jpg") || name.endsWith(".jpeg")) && header.length >= 3
|
|
|
- && (header[0] & 255) == 255 && (header[1] & 255) == 216 && (header[2] & 255) == 255;
|
|
|
- boolean png = name.endsWith(".png") && Arrays.equals(header, new byte[]{(byte)137,80,78,71,13,10,26,10});
|
|
|
- if (!jpeg && !png) throw new ServiceException("仅支持内容与扩展名一致的JPG、JPEG、PNG图片");
|
|
|
+ if (!(name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png")))
|
|
|
+ throw new ServiceException("仅支持JPG、JPEG、PNG后缀的附件");
|
|
|
String path = FileUploadUtils.upload(ZksyConfig.getUploadPath(), file, new String[]{"jpg", "jpeg", "png"}, true);
|
|
|
String token = UUID.randomUUID().toString();
|
|
|
redis.setCacheObject(key(alarmId, token), path, 2, TimeUnit.HOURS);
|