-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
修复默认的自定义集数获取规则错误 | ||
增加清理缓存功能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package ani.rss.action; | ||
|
||
import ani.rss.annotation.Auth; | ||
import ani.rss.annotation.Path; | ||
import ani.rss.entity.Ani; | ||
import ani.rss.util.AniUtil; | ||
import ani.rss.util.ConfigUtil; | ||
import cn.hutool.core.io.FileUtil; | ||
import cn.hutool.core.util.ArrayUtil; | ||
import cn.hutool.core.util.NumberUtil; | ||
import cn.hutool.core.util.ObjectUtil; | ||
import cn.hutool.http.server.HttpServerRequest; | ||
import cn.hutool.http.server.HttpServerResponse; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 缓存清理 | ||
*/ | ||
@Auth | ||
@Path("/clearCache") | ||
public class ClearCacheAction implements BaseAction { | ||
/** | ||
* 清理父级空文件夹 | ||
* | ||
* @param file | ||
*/ | ||
public static void clearParentFile(File file) { | ||
if (file.exists()) { | ||
return; | ||
} | ||
File parentFile = file.getParentFile(); | ||
String[] list = ObjectUtil.defaultIfNull(parentFile.list(), new String[]{}); | ||
if (ArrayUtil.isNotEmpty(list)) { | ||
return; | ||
} | ||
FileUtil.del(parentFile); | ||
clearParentFile(parentFile); | ||
} | ||
|
||
@Override | ||
public synchronized void doAction(HttpServerRequest request, HttpServerResponse response) throws IOException { | ||
File configDir = ConfigUtil.getConfigDir(); | ||
String configDirStr = configDir.toString().replace("\\", "/"); | ||
|
||
Set<String> covers = AniUtil.ANI_LIST | ||
.stream() | ||
.map(Ani::getCover) | ||
.map(s -> new File(configDirStr + "/files/" + s).toString().replace("\\", "/")) | ||
.collect(Collectors.toSet()); | ||
|
||
FileUtil.mkdir(configDirStr + "/files"); | ||
FileUtil.mkdir(configDirStr + "/img"); | ||
|
||
Set<File> files = FileUtil.loopFiles(configDirStr + "/files") | ||
.stream() | ||
.filter(file -> { | ||
String fileName = file.toString().replace("\\", "/"); | ||
return !covers.contains(fileName); | ||
}).collect(Collectors.toSet()); | ||
long filesSize = files.stream() | ||
.mapToLong(File::length) | ||
.sum(); | ||
long imgSize = FileUtil.size(new File(configDirStr + "/img")); | ||
|
||
long sumSize = filesSize + imgSize; | ||
|
||
if (sumSize < 1) { | ||
resultSuccessMsg("清理完成, 共清理{}MB", 0); | ||
return; | ||
} | ||
|
||
for (File file : files) { | ||
FileUtil.del(file); | ||
clearParentFile(file); | ||
} | ||
|
||
FileUtil.del(configDirStr + "/img"); | ||
|
||
resultSuccessMsg("清理完成, 共清理{}MB", NumberUtil.decimalFormat("0.00", sumSize / 1024.0 / 1024.0)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters