修改文件大小转换,使其支持XiB单位;新增下载完成通知;新增任务状态:压缩中

This commit is contained in:
chuzhongzai 2023-09-14 11:37:19 +08:00
parent e2fce692bd
commit 8742e59ebe
7 changed files with 21 additions and 9 deletions

View File

@ -15,6 +15,8 @@ public class GalleryTask {
public static byte COMPRESS_COMPLETE = 4;
public static byte COMPRESSING = 5;
public static byte DOWNLOAD_ALL = 3;
public static byte DOWNLOAD_PREVIEW = 2;

View File

@ -1,5 +1,6 @@
package com.lion.lionwebsite.Service;
import com.lion.lionwebsite.Domain.Gallery;
import com.lion.lionwebsite.Util.Response;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.request.SendMessage;
@ -24,6 +25,10 @@ public class PushService {
sendToMe(String.format("用户%s提交下载%s, 下载失败:%s", username, link, response.get("data")));
}
public void downloadComplete(Gallery gallery){
sendToMe(gallery.getLink() + "下载完成");
}
public void storageNodeOnline(){
sendToMe("存储节点上线");
}

View File

@ -308,11 +308,16 @@ public class RemoteService {
if(!gallery.getName().equals(galleryTask.getName()) && galleryTask.getName() != null)
gallery.setName(galleryTask.getName());
if(galleryTask.getStatus() == GalleryTask.COMPRESS_COMPLETE)
if(galleryTask.getStatus() == GalleryTask.COMPRESS_COMPLETE) {
gallery.setStatus("下载完成");
pushService.downloadComplete(gallery);
}
else if(galleryTask.getStatus() == GalleryTask.COMPRESSING)
gallery.setStatus("压缩中");
else if(galleryTask.getProceeding() != 0)
gallery.setStatus("下载中");
log.info(gallery.getName() + "下载进度:" + gallery.getProceeding() + "/" + gallery.getPages());
galleryMapper.updateGallery(gallery);
}

View File

@ -63,14 +63,14 @@ public class CustomUtil {
String preNum = "";
String unit = "";
Pattern patternWithDot = Pattern.compile("(\\d+.\\d+)([A-Z]+)");
Pattern patternWithDot = Pattern.compile("(\\d+.\\d+)(([A-Z]|[a-z])+)");
Matcher matcherWithDot = patternWithDot.matcher(fileSizeString);
if(matcherWithDot.find()){
preNum = matcherWithDot.group(1);
unit = matcherWithDot.group(2);
}
else {
Pattern patternWithoutDot = Pattern.compile("(\\d+)([A-Z]+)");
Pattern patternWithoutDot = Pattern.compile("(\\d+)(([A-Z]|[a-z])+)");
Matcher matcherWithoutDot = patternWithoutDot.matcher(fileSizeString);
if (matcherWithoutDot.find()) {
preNum = matcherWithoutDot.group(1);
@ -82,9 +82,9 @@ public class CustomUtil {
return switch (unit) {
case "B" -> (long) num;
case "KB" -> (long) (ONE_KB * num);
case "MB" -> (long) (ONE_MB * num);
case "GB" -> (long) (ONE_GB * num);
case "KB", "KiB" -> (long) (ONE_KB * num);
case "MB", "MiB" -> (long) (ONE_MB * num);
case "GB", "GiB" -> (long) (ONE_GB * num);
default -> 0;
};
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long