Skip to content

Commit

Permalink
Merge pull request #166 from jamebal/develop
Browse files Browse the repository at this point in the history
feat: 登陆页面和博客页面新增自定义页脚html
  • Loading branch information
jamebal authored Oct 24, 2024
2 parents 7348dca + 57a6791 commit 9e1395f
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 57 deletions.
64 changes: 36 additions & 28 deletions src/main/java/com/jmal/clouddisk/lucene/LuceneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,34 +234,40 @@ private void createIndexFiles(List<String> fileIdList) {
}

private void updateIndex(boolean readContent, FileIntroVO fileIntroVO) {
String username = userService.getUserNameById(fileIntroVO.getUserId());
File file = Paths.get(fileProperties.getRootDir(), username, fileIntroVO.getPath(), fileIntroVO.getName()).toFile();
boolean isContent = checkFileContent(file);
if (!readContent && isContent) {
pushCreateIndexContentQueue(fileIntroVO.getId());
}
if (!readContent && !isContent) {
rebuildIndexTaskService.incrementIndexedTaskSize();
}
FileIndex fileIndex = new FileIndex(file, fileIntroVO);
fileIndex.setTagName(getTagName(fileIntroVO));
setFileIndex(fileIndex);
String content = null;
if (readContent) {
content = readFileContent(file, fileIntroVO.getId());
if (StrUtil.isBlank(content)) {
try {
String username = userService.getUserNameById(fileIntroVO.getUserId());
File file = Paths.get(fileProperties.getRootDir(), username, fileIntroVO.getPath(), fileIntroVO.getName()).toFile();
boolean isContent = checkFileContent(file);
if (!readContent && isContent) {
pushCreateIndexContentQueue(fileIntroVO.getId());
}
if (!readContent && !isContent) {
rebuildIndexTaskService.incrementIndexedTaskSize();
}
FileIndex fileIndex = new FileIndex(file, fileIntroVO);
fileIndex.setTagName(getTagName(fileIntroVO));
setFileIndex(fileIndex);
String content = null;
if (readContent) {
content = readFileContent(file, fileIntroVO.getId());
if (StrUtil.isBlank(content)) {
updateIndexStatus(fileIntroVO, IndexStatus.INDEXED);
return;
}
}
updateIndexDocument(indexWriter, fileIndex, content);
if (StrUtil.isNotBlank(content)) {
log.debug("添加索引, filepath: {}", file.getAbsoluteFile());
startProcessFilesToBeIndexed();
}
} catch (Exception e) {
log.warn("updateIndexError: {}", e.getMessage());
} finally {
updateIndexStatus(fileIntroVO, IndexStatus.INDEXED);
if (readContent) {
rebuildIndexTaskService.incrementIndexedTaskSize();
updateIndexStatus(fileIntroVO, IndexStatus.INDEXED);
return;
}
}
updateIndexDocument(indexWriter, fileIndex, content);
if (StrUtil.isNotBlank(content)) {
log.debug("添加索引, filepath: {}", file.getAbsoluteFile());
startProcessFilesToBeIndexed();
rebuildIndexTaskService.incrementIndexedTaskSize();
}
updateIndexStatus(fileIntroVO, IndexStatus.INDEXED);
}

/**
Expand Down Expand Up @@ -716,15 +722,17 @@ public void processFilesToBeIndexed() throws IOException {

private void processFileThreaded(FileIntroVO fileIntroVO) {
long size = fileIntroVO.getSize();

if (RebuildIndexTaskService.isSyncFile()) {
// 单线程处理
updateIndex(true, fileIntroVO);
} else {
if (RebuildIndexTaskService.isSyncFile() || size > 20 * 1024 * 1024) {
// 大文件线程
// 根据文件大小选择多线程处理
if (size > 20 * 1024 * 1024) {
// 大文件,使用专门线程池处理
executorUpdateBigContentIndexService.execute(() -> updateIndex(true, fileIntroVO));
} else {
// 小文件线程
// 小文件,使用普通线程池处理
executorUpdateContentIndexService.execute(() -> updateIndex(true, fileIntroVO));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.jmal.clouddisk.util.ResponseResult;
import com.jmal.clouddisk.util.ResultUtil;
import com.jmal.clouddisk.util.ThrottleExecutor;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.Getter;
Expand Down Expand Up @@ -261,7 +263,7 @@ public void run() {
public void rebuildingIndexCompleted() {
if (!hasUnIndexedTasks() && NOT_INDEX_TASK_SIZE.get() > 0) {
setPercentMap(100d, 100d);
log.debug("重建索引完成, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", INDEXED_TASK_SIZE, NOT_INDEX_TASK_SIZE);
log.info("重建索引完成, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", INDEXED_TASK_SIZE, NOT_INDEX_TASK_SIZE);
restIndexedTasks();
pushMessage();
}
Expand All @@ -288,10 +290,10 @@ public void incrementIndexedTaskSize() {
delayResetIndex();
}

private void delayResetIndex() {
public void delayResetIndex() {
synchronized (RebuildIndexTaskService.class) {
if (throttleExecutor == null) {
throttleExecutor = new ThrottleExecutor(3000);
throttleExecutor = new ThrottleExecutor(10000);
}
}
throttleExecutor.schedule(this::rebuildingIndexCompleted);
Expand Down Expand Up @@ -413,7 +415,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
if (StrUtil.isBlank(username)) {
return super.visitFile(dir, attrs);
}
syncFileVisitorService.execute(() -> createFile(username, dir));
processFile(dir, username);
return super.preVisitDirectory(dir, attrs);
}

Expand All @@ -424,21 +426,31 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
if (StrUtil.isBlank(username)) {
return super.visitFile(file, attrs);
}
syncFileVisitorService.execute(() -> createFile(username, file));
processFile(file, username);
return super.visitFile(file, attrs);
}

private void createFile(String username, Path file) {
private void processFile(Path file, String username) {
// 使用 RxJava 执行异步文件创建
Flowable.fromCallable(() -> createFile(username, file))
.subscribeOn(Schedulers.io())
.doOnError(e -> log.warn("Error processing file: {}", file, e))
.subscribe();
}

private boolean createFile(String username, Path file) {
try {
commonFileService.createFile(username, file.toFile(), null, null);
return true;
} catch (Exception e) {
log.error("{}{}", e.getMessage(), file, e);
log.error("createFile error {}{}", e.getMessage(), file, e);
FileDocument fileDocument = commonFileService.getFileDocument(username, file.toFile().getAbsolutePath());
if (fileDocument != null) {
// 需要移除删除标记
removeDeletedFlag(Collections.singletonList(fileDocument.getId()));
}
}
return false;
}
}

Expand All @@ -455,7 +467,7 @@ private void setPercentMap(Double syncPercent, Double indexingPercent) {

private void pushMessage() {
commonFileService.pushMessage(getRecipient(null), PERCENT_MAP, RebuildIndexTaskService.MSG_SYNCED);
log.debug("推送消息: {}, isSyncFile: {}, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", PERCENT_MAP, isSyncFile(), INDEXED_TASK_SIZE.get(), NOT_INDEX_TASK_SIZE.get());
log.info("推送消息: {}, isSyncFile: {}, INDEXED_TASK_SIZE, {}, NOT_INDEX_TASK_SIZE: {}", PERCENT_MAP, isSyncFile(), INDEXED_TASK_SIZE.get(), NOT_INDEX_TASK_SIZE.get());
}

private class FileCountVisitor extends SimpleFileVisitor<Path> {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/jmal/clouddisk/model/WebsiteSettingDO.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class WebsiteSettingDO {
* 公网备案号 展示文本
*/
String networkRecordNumberStr;

/**
* 页脚html
*/
String footerHtml;

/**
* iframe预览配置
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jmal/clouddisk/model/WebsiteSettingDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class WebsiteSettingDTO {
*/
String networkRecordNumberStr;

/**
* 页脚html
*/
String footerHtml;

/**
* iframe预览配置
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public WebsiteSettingDTO getWebsiteRecord() {
websiteSettingDTO1.setNetworkRecordNumberStr(websiteSettingDTO.getNetworkRecordNumberStr());
websiteSettingDTO1.setNetdiskName(websiteSettingDTO.getNetdiskName());
websiteSettingDTO1.setNetdiskLogo(websiteSettingDTO.getNetdiskLogo());
websiteSettingDTO1.setFooterHtml(websiteSettingDTO.getFooterHtml());
return websiteSettingDTO1;
}

Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/static/articles/css/dark/index-2.0.3.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ body {
}
/*article-footer*/

footer {
color: #c7c8cf;
}
footer a {
color: #c4c6c9;
}
.layui-laypage a, .layui-laypage span {
border: 1px solid #181d27;
background-color: #252d38;
Expand Down
16 changes: 9 additions & 7 deletions src/main/resources/static/articles/css/light/index-2.0.3.css
Original file line number Diff line number Diff line change
Expand Up @@ -1012,28 +1012,30 @@ html {
color: #555;
padding-right: .625rem;
}
/*article-footer*/
footer, footer p {
font-size: .8125rem;
}

footer {
position: relative;
bottom: 10px;
padding: 10px 10px 10px 10px;
width: 100%;
color: rgba(68,68,68,0.65);
margin: 0 auto;
overflow: hidden;
text-align: center;
-webkit-transition: 0.5s ease all;
transition: 0.5s ease all;
}
footer .copyright {

/*article-footer*/
#footer p {
font-size: .8125rem;
}

#footer .copyright {
color: #444444;
margin-top: 16px;
font-size: .75rem;
}
footer a {
#footer a {
color: rgba(68,68,68,0.65);
padding: 0;
transition: all .28s ease;
Expand Down
19 changes: 11 additions & 8 deletions src/main/resources/templates/component/footer.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<footer id="footer" class="clearfix" xmlns:th="http://www.thymeleaf.org">
<br><br><br>
<div class="copyright">
<p><span th:text="${setting.copyright}"></span></p>
<p style="margin-top: 5px;">
<a href="http://beian.miit.gov.cn" target="_blank" th:text="${setting.recordPermissionNum}"></a>
<a target="_blank" style="margin-left: 5px;" th:href="'http://www.beian.gov.cn/portal/registerSystemInfo?recordcode='+${setting.networkRecordNumber}"><img th:if="${setting.isShowBeian()}" style="width: 15px;" th:src="${setting.siteUrl} + '/img/beian.png'" /><span th:text="${setting.networkRecordNumberStr}"></span></a>
</p>
<footer xmlns:th="http://www.thymeleaf.org">
<div id="footer" th:if="${setting.footerHtml == null || setting.footerHtml.length == 0}">
<br><br>
<div class="copyright">
<p><span th:text="${setting.copyright}"></span></p>
<p style="margin-top: 5px;">
<a href="http://beian.miit.gov.cn" target="_blank" th:text="${setting.recordPermissionNum}"></a>
<a target="_blank" style="margin-left: 5px;" th:href="'http://www.beian.gov.cn/portal/registerSystemInfo?recordcode='+${setting.networkRecordNumber}"><img th:if="${setting.isShowBeian()}" style="width: 15px;" th:src="${setting.siteUrl} + '/img/beian.png'" /><span th:text="${setting.networkRecordNumberStr}"></span></a>
</p>
</div>
</div>
<div th:if="${setting.footerHtml != null && setting.footerHtml.length > 0}" th:utext="${setting.footerHtml}"></div>
</footer>

0 comments on commit 9e1395f

Please sign in to comment.