mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
✨ 增加 readme.md 兼容模式
This commit is contained in:
@@ -97,6 +97,10 @@ public class StorageSource implements Serializable {
|
||||
@TableField(value = "default_switch_to_img_mode")
|
||||
@ApiModelProperty(value = "是否默认开启图片模式", example = "true")
|
||||
private Boolean defaultSwitchToImgMode;
|
||||
|
||||
@TableField(value = "compatibility_readme")
|
||||
@ApiModelProperty(value = "兼容 readme 模式", example = "true", notes = "兼容模式, 目录文档读取 readme.md 文件")
|
||||
private Boolean compatibilityReadme;
|
||||
|
||||
public boolean allowOperator() {
|
||||
// 允许文件操作,且允许匿名操作或者当前登录用户是管理员
|
||||
|
||||
@@ -65,5 +65,8 @@ public class SaveStorageSourceRequest {
|
||||
|
||||
@ApiModelProperty(value = "是否默认开启图片模式", example = "true")
|
||||
private boolean defaultSwitchToImgMode;
|
||||
|
||||
@ApiModelProperty(value = "兼容 readme 模式", example = "true", notes = "兼容模式, 目录文档读取 readme.md 文件")
|
||||
private boolean compatibilityReadme;
|
||||
|
||||
}
|
||||
@@ -31,7 +31,6 @@ public class StorageSourceAdminResult {
|
||||
@ApiModelProperty(value = "是否允许匿名进行文件操作", example = "true", notes = "是否允许匿名进行文件上传,编辑,删除等操作.")
|
||||
private Boolean enableFileAnnoOperator;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "是否开启缓存", example = "true")
|
||||
private Boolean enableCache;
|
||||
|
||||
@@ -78,5 +77,9 @@ public class StorageSourceAdminResult {
|
||||
|
||||
@ApiModelProperty(value = "存储源刷新信息")
|
||||
private RefreshTokenCache.RefreshTokenInfo refreshTokenInfo;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "兼容 readme 模式", example = "true", notes = "兼容模式, 目录文档读取 readme.md 文件")
|
||||
private Boolean compatibilityReadme;
|
||||
|
||||
}
|
||||
@@ -1,22 +1,29 @@
|
||||
package im.zhaojun.zfile.home.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
||||
import im.zhaojun.zfile.admin.model.entity.ReadmeConfig;
|
||||
import im.zhaojun.zfile.admin.model.entity.StorageSource;
|
||||
import im.zhaojun.zfile.admin.model.enums.ReadmeDisplayModeEnum;
|
||||
import im.zhaojun.zfile.admin.model.param.IStorageParam;
|
||||
import im.zhaojun.zfile.admin.service.ReadmeConfigService;
|
||||
import im.zhaojun.zfile.admin.service.StorageSourceService;
|
||||
import im.zhaojun.zfile.admin.service.SystemConfigService;
|
||||
import im.zhaojun.zfile.common.config.ZFileProperties;
|
||||
import im.zhaojun.zfile.common.context.StorageSourceContext;
|
||||
import im.zhaojun.zfile.common.exception.InvalidStorageSourceException;
|
||||
import im.zhaojun.zfile.common.exception.NotExistFileException;
|
||||
import im.zhaojun.zfile.common.util.AjaxJson;
|
||||
import im.zhaojun.zfile.common.util.HttpUtil;
|
||||
import im.zhaojun.zfile.common.util.StringUtils;
|
||||
import im.zhaojun.zfile.home.convert.StorageSourceConvert;
|
||||
import im.zhaojun.zfile.home.model.dto.SystemConfigDTO;
|
||||
import im.zhaojun.zfile.home.model.request.FileListConfigRequest;
|
||||
import im.zhaojun.zfile.home.model.result.FileItemResult;
|
||||
import im.zhaojun.zfile.home.model.result.SiteConfigResult;
|
||||
import im.zhaojun.zfile.home.model.result.StorageSourceConfigResult;
|
||||
import im.zhaojun.zfile.home.service.base.AbstractBaseFileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -57,6 +64,9 @@ public class SiteController {
|
||||
|
||||
@Resource
|
||||
private ReadmeConfigService readmeConfigService;
|
||||
|
||||
@Resource
|
||||
private StorageSourceContext storageSourceContext;
|
||||
|
||||
|
||||
@ApiOperationSupport(order = 1)
|
||||
@@ -93,18 +103,41 @@ public class SiteController {
|
||||
|
||||
// 根据存储源 key 获取存储源 id
|
||||
Integer storageId = storageSource.getId();
|
||||
|
||||
// 获取指定目录 readme 文件
|
||||
ReadmeConfig readmeByPath = readmeConfigService.findReadmeByPath(storageId, path);
|
||||
|
||||
if (ObjectUtil.isNotNull(readmeByPath)) {
|
||||
String readmeText = readmeByPath.getReadmeText();
|
||||
ReadmeDisplayModeEnum displayMode = readmeByPath.getDisplayMode();
|
||||
|
||||
storageSourceConfigResult.setReadmeText(readmeText);
|
||||
storageSourceConfigResult.setReadmeDisplayMode(displayMode);
|
||||
|
||||
|
||||
ReadmeConfig readmeByPath = new ReadmeConfig();
|
||||
readmeByPath.setStorageId(storageId);
|
||||
readmeByPath.setDisplayMode(ReadmeDisplayModeEnum.BOTTOM);
|
||||
if (BooleanUtil.isTrue(storageSource.getCompatibilityReadme())) {
|
||||
try {
|
||||
log.info("存储源 {} 兼容获取目录 {} 下的 readme.md", storageSource.getName(), path);
|
||||
AbstractBaseFileService<IStorageParam> abstractBaseFileService = storageSourceContext.get(storageId);
|
||||
String pathAndName = StringUtils.concat(path, "readme.md");
|
||||
FileItemResult fileItem = abstractBaseFileService.getFileItem(pathAndName);
|
||||
if (fileItem != null) {
|
||||
String url = fileItem.getUrl();
|
||||
String readmeText = HttpUtil.getTextContent(url);
|
||||
readmeByPath.setReadmeText(readmeText);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof NotExistFileException) {
|
||||
log.error("存储源 {} 兼容获取目录 {} 下的 readme.md 文件失败", storageSource.getName(), path);
|
||||
} else {
|
||||
log.error("存储源 {} 兼容获取目录 {} 下的 readme.md 文件失败", storageSource.getName(), path, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 获取指定目录 readme 文件
|
||||
ReadmeConfig dbReadmeConfig = readmeConfigService.findReadmeByPath(storageId, path);
|
||||
if (dbReadmeConfig != null) {
|
||||
readmeByPath = dbReadmeConfig;
|
||||
}
|
||||
log.info("存储源 {} 规则模式获取目录 {} 下文档信息", storageSource.getName(), path);
|
||||
}
|
||||
|
||||
|
||||
storageSourceConfigResult.setReadmeDisplayMode(readmeByPath.getDisplayMode());
|
||||
storageSourceConfigResult.setReadmeText(readmeByPath.getReadmeText());
|
||||
|
||||
return AjaxJson.getSuccessData(storageSourceConfigResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,5 +62,8 @@ public class StorageSourceDTO {
|
||||
|
||||
@ApiModelProperty(value = "是否默认开启图片模式", example = "true")
|
||||
private boolean defaultSwitchToImgMode;
|
||||
|
||||
@ApiModelProperty(value = "兼容 readme 模式", example = "true", notes = "兼容模式, 目录文档读取 readme.md 文件")
|
||||
private Boolean compatibilityReadme;
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
alter table storage_source add compatibility_readme bit;
|
||||
@@ -0,0 +1 @@
|
||||
alter table storage_source add compatibility_readme bit;
|
||||
@@ -19,12 +19,13 @@
|
||||
<result column="enable_file_operator" jdbcType="VARCHAR" property="enableFileOperator" />
|
||||
<result column="search_mode" jdbcType="VARCHAR" property="searchMode" />
|
||||
<result column="enable_file_anno_operator" jdbcType="BIT" property="enableFileAnnoOperator" />
|
||||
<result column="compatibility_readme" jdbcType="BIT" property="compatibilityReadme" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
`id`, `enable`, `enable_cache`, `name`, `auto_refresh_cache`, `type`, `search_enable`,
|
||||
`search_ignore_case`, `order_num`, `default_switch_to_img_mode`,
|
||||
`remark`, `key`, `enable_file_operator`, `search_mode`, `enable_file_anno_operator`
|
||||
`remark`, `key`, `enable_file_operator`, `search_mode`, `enable_file_anno_operator`, `compatibility_readme`
|
||||
</sql>
|
||||
|
||||
<select id="findListByEnableOrderByOrderNum" resultMap="BaseResultMap">
|
||||
|
||||
Reference in New Issue
Block a user