Skip to content

Commit

Permalink
fix: 调整代码
Browse files Browse the repository at this point in the history
  • Loading branch information
CarefreeState committed Sep 29, 2024
1 parent 2039b1d commit 4ee7740
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,32 @@ public interface FeishuService {
ApplyReserveRespBody reserveApplyBriefly(String ownerId, Long endTime, String topic);

/**
* 上传资源
* 上传资源(云空间,不存储)
*/
UploadAllMediaRespBody uploadMedia(UploadAllMediaReqBody uploadAllMediaReqBody);

UploadAllMediaRespBody uploadMediaBriefly(String originalName, byte[] bytes, ObjectType objectType);

/**
* 上传文件(存储到指定目录)
*/
UploadAllFileRespBody uploadFile(UploadAllFileReqBody uploadAllFileReqBody);

UploadAllFileRespBody uploadFileBriefly(String originalName, byte[] bytes, ObjectType objectType);

String getFileTokenBriefly(String originalName, byte[] bytes, ObjectType objectType);

/**
* 创建导入任务
* 创建导入任务,指定挂载的链接
*/
CreateImportTaskRespBody importTask(ImportTask importTask);

CreateImportTaskRespBody importTaskBriefly(String originalName, byte[] bytes, ObjectType objectType);

/**
* 查询导入结果
* 根据 ticket 查询会创建一个额外的协作链接,这个与原本不同的点就是,原本那个是存储,现在这个是协作文件(一般不会共享存储的文件)
* 这个额外的协作链接生成具有飞书风格的协作文件(加载也会快点,更适合协作)
*/
GetImportTaskRespBody getImportTask(String ticket);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ public class FeishuServiceImpl implements FeishuService, InitializingBean {

private String defaultOwnerId;

private Boolean backup;

@Override
public void afterPropertiesSet() throws Exception {
this.defaultOwnerId = getUserIdByMobile(feishuAppConfig.getOwner().getMobile());
this.backup = Optional.ofNullable(feishuAppConfig.getResource().getBackup()).orElse(Boolean.FALSE);
}

@Override
Expand Down Expand Up @@ -202,6 +205,15 @@ public UploadAllFileRespBody uploadFileBriefly(String originalName, byte[] bytes
});
}

@Override
public String getFileTokenBriefly(String originalName, byte[] bytes, ObjectType objectType) {
if(Boolean.TRUE.equals(backup)) {
return uploadFileBriefly(originalName, bytes, objectType).getFileToken();
}else {
return uploadMediaBriefly(originalName, bytes, objectType).getFileToken();
}
}

@Override
public CreateImportTaskRespBody importTask(ImportTask importTask) {
// CreateImportTaskReq createImportTaskReq = CreateImportTaskReq.newBuilder()
Expand All @@ -226,15 +238,15 @@ public CreateImportTaskRespBody importTask(ImportTask importTask) {

@Override
public CreateImportTaskRespBody importTaskBriefly(String originalName, byte[] bytes, ObjectType objectType) {
String fileToken = uploadFileBriefly(originalName, bytes, objectType).getFileToken();
String fileToken = getFileTokenBriefly(originalName, bytes, objectType);
ImportTask importTask = ImportTask.newBuilder()
.fileName(originalName)
.fileExtension(objectType.getFileExtension())
.fileToken(fileToken)
.type(objectType.getObjType())
.point(ImportTaskMountPoint.newBuilder()
.mountType(ImportTaskMountPointMountTypeEnum.SPACE)
.mountKey(objectType.getParentNode())
.mountKey(objectType.getMountKey())
.build())
.build();
return importTask(importTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@Data
public class ResourceProperties {

private Boolean backup;

private String parentNode;

private Long tryAgain;
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/achobeta/feishu/constants/ObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
@AllArgsConstructor
public class ObjectType {

private final static String ACHOBETA_RECRUITMENT_DOCX_FOLDER = "LpDBf0emllgCc2dKNfKcsqxJnjc";
private final static String ACHOBETA_RECRUITMENT_SHEET_FOLDER = "OQbUfIGR9lqdFVdbJCDcQ3CSntd";
private final static String ACHOBETA_RECRUITMENT_DOCX_FOLDER_RESOURCE = "LpDBf0emllgCc2dKNfKcsqxJnjc";
private final static String ACHOBETA_RECRUITMENT_SHEET_FOLDER_RESOURCE = "OQbUfIGR9lqdFVdbJCDcQ3CSntd";
private final static String ACHOBETA_RECRUITMENT_DOCX_FOLDER_COOPERATE = "LpDBf0emllgCc2dKNfKcsqxJnjc";
private final static String ACHOBETA_RECRUITMENT_SHEET_FOLDER_COOPERATE = "SyBEf61JglcR5NdCp34cs2tGnMd";

public final static ObjectType TXT = ObjectType.of("docx", "txt", ACHOBETA_RECRUITMENT_DOCX_FOLDER);
public final static ObjectType XLSX = ObjectType.of("sheet", "xlsx", ACHOBETA_RECRUITMENT_SHEET_FOLDER);
public final static ObjectType MD = ObjectType.of("docx", "md", ACHOBETA_RECRUITMENT_DOCX_FOLDER);
public final static ObjectType MARKDOWN = ObjectType.of("docx", "markdown", ACHOBETA_RECRUITMENT_DOCX_FOLDER);
public final static ObjectType TXT = ObjectType.of("docx", "txt", ACHOBETA_RECRUITMENT_DOCX_FOLDER_RESOURCE, ACHOBETA_RECRUITMENT_DOCX_FOLDER_COOPERATE);
public final static ObjectType XLSX = ObjectType.of("sheet", "xlsx", ACHOBETA_RECRUITMENT_SHEET_FOLDER_RESOURCE, ACHOBETA_RECRUITMENT_SHEET_FOLDER_COOPERATE);
public final static ObjectType MD = ObjectType.of("docx", "md", ACHOBETA_RECRUITMENT_DOCX_FOLDER_RESOURCE, ACHOBETA_RECRUITMENT_DOCX_FOLDER_COOPERATE);
public final static ObjectType MARKDOWN = ObjectType.of("docx", "markdown", ACHOBETA_RECRUITMENT_DOCX_FOLDER_RESOURCE, ACHOBETA_RECRUITMENT_DOCX_FOLDER_COOPERATE);

@SerializedName("obj_type")
private final String objType;
Expand All @@ -37,8 +39,11 @@ public class ObjectType {
@Expose(deserialize = false, serialize = false)
private final String parentNode;

private static ObjectType of(String objType, String fileExtension, String parentNode) {
return new ObjectType(objType, fileExtension, parentNode);
@Expose(deserialize = false, serialize = false)
private final String mountKey;

private static ObjectType of(String objType, String fileExtension, String parentNode, String mountKey) {
return new ObjectType(objType, fileExtension, parentNode, mountKey);
}

}

0 comments on commit 4ee7740

Please sign in to comment.