🐛 修复 OneDrive 获取文档区或文件夹密码时, 链接超时导致异常的 BUG.

This commit is contained in:
zhaojun1998
2020-02-29 15:45:11 +08:00
parent 04f94b4bf5
commit 67e42d9753
2 changed files with 43 additions and 19 deletions

View File

@@ -45,26 +45,33 @@ public class GlobalScheduleTask {
@Scheduled(fixedRate = 1000 * 60 * 10, initialDelay = 1000 * 30)
public void autoRefreshOneDriveToken() {
AbstractFileService currentFileService = systemConfigService.getCurrentFileService();
if (!(currentFileService instanceof OneDriveServiceImpl
|| currentFileService instanceof OneDriveChinaServiceImpl)) {
log.debug("当前启用存储类型, 不是 OneDrive, 跳过自动刷新 AccessToken");
return;
}
if (currentFileService.getIsUnInitialized()) {
log.debug("当前启用 OneDrive 未初始化成功, 跳过自动刷新 AccessToken");
return;
}
StorageTypeEnum currentStorageTypeEnum = currentFileService.getStorageTypeEnum();
try {
refreshOneDriveToken(currentStorageTypeEnum);
} catch (Exception e) {
log.debug("刷新 " + currentStorageTypeEnum.getDescription() + " Token 失败.", e);
log.debug("尝试调用 OneDrive 自动刷新 AccessToken 定时任务");
AbstractFileService currentFileService = systemConfigService.getCurrentFileService();
if (!(currentFileService instanceof OneDriveServiceImpl
|| currentFileService instanceof OneDriveChinaServiceImpl)) {
log.debug("当前启用存储类型, 不是 OneDrive, 跳过自动刷新 AccessToken");
return;
}
if (currentFileService.getIsUnInitialized()) {
log.debug("当前启用 OneDrive 未初始化成功, 跳过自动刷新 AccessToken");
return;
}
StorageTypeEnum currentStorageTypeEnum = currentFileService.getStorageTypeEnum();
try {
refreshOneDriveToken(currentStorageTypeEnum);
} catch (Exception e) {
log.debug("刷新 " + currentStorageTypeEnum.getDescription() + " Token 失败.", e);
}
} catch (Throwable e) {
log.debug("尝试调用 OneDrive 自动刷新 AccessToken 定时任务出现未知异常", e);
}
}
/**

View File

@@ -5,7 +5,10 @@ import im.zhaojun.common.model.dto.FileItemDTO;
import im.zhaojun.common.model.dto.SiteConfigDTO;
import im.zhaojun.common.model.enums.StorageTypeEnum;
import im.zhaojun.common.util.HttpUtil;
import im.zhaojun.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -15,6 +18,7 @@ import java.util.Objects;
/**
* @author zhaojun
*/
@Slf4j
@Service
public class SystemService {
@@ -40,7 +44,20 @@ public class SystemService {
for (FileItemDTO fileItemDTO : fileItemList) {
if (ZFileConstant.README_FILE_NAME.equalsIgnoreCase(fileItemDTO.getName())) {
siteConfigDTO.setReadme(HttpUtil.getTextContent(fileItemDTO.getUrl()));
String textContent = null;
try {
textContent = HttpUtil.getTextContent(fileItemDTO.getUrl());
} catch (HttpClientErrorException httpClientErrorException) {
log.debug("尝试重新获取文档区缓存中链接后仍失败", httpClientErrorException);
try {
String fullPath = StringUtils.removeDuplicateSeparator(fileItemDTO.getPath() + "/" + fileItemDTO.getName());
FileItemDTO fileItem = fileService.getFileItem(fullPath);
textContent = HttpUtil.getTextContent(fileItem.getUrl());
} catch (Exception e) {
log.debug("尝试重新获取文档区链接后仍失败, 已置为空", e);
}
}
siteConfigDTO.setReadme(textContent);
}
}
return siteConfigDTO;