add Attachment.mimeType,metadata
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package com.imyeyu.api.modules.common.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-12-11 18:14
|
||||
*/
|
||||
public class Metadata {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2025-12-11 18:15
|
||||
*/
|
||||
@Data
|
||||
public static class Image {
|
||||
|
||||
private int width;
|
||||
|
||||
private int height;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.imyeyu.api.bean.MultilingualHandler;
|
||||
import com.imyeyu.java.ref.Ref;
|
||||
import com.imyeyu.spring.entity.Entity;
|
||||
@ -67,6 +68,10 @@ public class Attachment extends Entity implements MultilingualHandler {
|
||||
|
||||
protected String name;
|
||||
|
||||
protected String mimeType;
|
||||
|
||||
protected JsonObject metadata;
|
||||
|
||||
protected Long size;
|
||||
|
||||
protected String md5;
|
||||
@ -82,5 +87,4 @@ public class Attachment extends Entity implements MultilingualHandler {
|
||||
public <T extends Enum<T>> T getAttachTypeValue(Class<T> attachTypeClass) {
|
||||
return Ref.toType(attachTypeClass, attachType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.imyeyu.api.modules.common.service.implement;
|
||||
import com.google.gson.Gson;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.bean.MediaAttach;
|
||||
import com.imyeyu.api.modules.common.bean.Metadata;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
@ -31,6 +32,8 @@ import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -101,6 +104,14 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
||||
request.setMongoId(mongoId);
|
||||
request.setSize(gridFSFile.getLength());
|
||||
request.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||
request.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||
if (request.getMimeType().startsWith("image")) {
|
||||
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
||||
Metadata.Image metadata = new Metadata.Image();
|
||||
metadata.setWidth(image.getWidth());
|
||||
metadata.setHeight(image.getHeight());
|
||||
request.setMetadata(gson.toJsonTree(metadata).getAsJsonObject());
|
||||
}
|
||||
mapper.insert(request);
|
||||
} catch (Exception e) {
|
||||
if (mongoId != null) {
|
||||
|
||||
Reference in New Issue
Block a user