diff --git a/common/src/main/java/lee/study/down/model/TaskInfo.java b/common/src/main/java/lee/study/down/model/TaskInfo.java index 27bcfb59..4db26939 100644 --- a/common/src/main/java/lee/study/down/model/TaskInfo.java +++ b/common/src/main/java/lee/study/down/model/TaskInfo.java @@ -44,4 +44,16 @@ public void reset() { chunkInfo.setPauseTime(0); }); } + + public void refresh() { + lastTime = System.currentTimeMillis(); + chunkInfoList.forEach((chunkInfo) -> { + chunkInfo.setLastTime(lastTime); + }); + } + + public void refresh(ChunkInfo chunkInfo) { + lastTime = System.currentTimeMillis(); + chunkInfo.setLastTime(lastTime); + } } diff --git a/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java b/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java index cda1706c..5d7fbe10 100644 --- a/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java +++ b/core/src/main/java/lee/study/down/handle/HttpDownInitializer.java @@ -71,11 +71,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception synchronized (chunkInfo) { Channel nowChannel = (Channel) bootstrap .getAttr(chunkInfo, HttpDownBootstrap.ATTR_CHANNEL); - LargeMappedByteBuffer nowMapBuffer = (LargeMappedByteBuffer) bootstrap - .getAttr(chunkInfo, HttpDownBootstrap.ATTR_MAP_BUFFER); if (chunkInfo.getStatus() == HttpDownStatus.RUNNING && nowChannel == ctx.channel()) { - nowMapBuffer.put(byteBuf.nioBuffer()); + mappedBuffer.put(byteBuf.nioBuffer()); //文件已下载大小 chunkInfo.setDownSize(chunkInfo.getDownSize() + readableBytes); taskInfo.setDownSize(taskInfo.getDownSize() + readableBytes); @@ -92,6 +90,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception chunkInfo.setLastTime(System.currentTimeMillis()); LOGGER.debug("分段下载完成:" + chunkInfo.getIndex() + "\t" + chunkInfo.getDownSize() + "\t" + taskInfo.getStatus()); + taskInfo.refresh(chunkInfo); callback.onChunkDone(bootstrap.getHttpDownInfo(), chunkInfo); synchronized (taskInfo) { if (taskInfo.getStatus() == HttpDownStatus.RUNNING @@ -106,6 +105,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception //文件下载完成回调 taskInfo.setStatus(HttpDownStatus.DONE); LOGGER.debug("下载完成:" + chunkInfo.getIndex() + "\t" + chunkInfo.getDownSize()); + taskInfo.refresh(); callback.onDone(bootstrap.getHttpDownInfo()); } } diff --git a/core/src/main/java/lee/study/down/util/HttpDownUtil.java b/core/src/main/java/lee/study/down/util/HttpDownUtil.java index 5434c2fc..f3cf7b85 100644 --- a/core/src/main/java/lee/study/down/util/HttpDownUtil.java +++ b/core/src/main/java/lee/study/down/util/HttpDownUtil.java @@ -69,7 +69,6 @@ public void channelRead(ChannelHandlerContext ctx0, Object msg0) //206表示支持断点下载 if (httpResponse.status().equals(HttpResponseStatus.PARTIAL_CONTENT)) { taskInfo.setSupportRange(true); - taskInfo.setConnections(16); } ctx0.channel().close(); cdl.countDown(); diff --git a/ui/src/main/java/lee/study/down/content/ConfigContent.java b/ui/src/main/java/lee/study/down/content/ConfigContent.java index 5b41e4ab..ea209084 100644 --- a/ui/src/main/java/lee/study/down/content/ConfigContent.java +++ b/ui/src/main/java/lee/study/down/content/ConfigContent.java @@ -47,10 +47,12 @@ public void init() { } if (configContent == null) { configContent = new ConfigInfo(); - //默认30秒无响应重试 - configContent.setTimeout(30); //默认代理端口 configContent.setProxyPort(9999); + //默认分段数 + configContent.setConnections(16); + //默认30秒无响应重试 + configContent.setTimeout(30); save(); } } diff --git a/ui/src/main/java/lee/study/down/model/ConfigInfo.java b/ui/src/main/java/lee/study/down/model/ConfigInfo.java index f64bd6ae..7956aefa 100644 --- a/ui/src/main/java/lee/study/down/model/ConfigInfo.java +++ b/ui/src/main/java/lee/study/down/model/ConfigInfo.java @@ -5,12 +5,13 @@ import lombok.Data; @Data -public class ConfigInfo implements Serializable{ +public class ConfigInfo implements Serializable { private static final long serialVersionUID = 4780168673614933999L; private boolean guideFlag; //是否需要新手引导教程 private int proxyPort; //代理端口号 + private int connections; //默认分段数 private int timeout; //超时重试时间 private boolean secProxyEnable; //二级代理开关 private ProxyConfig secProxyConfig; //二级代理设置 diff --git a/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java b/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java index a5f3ce74..49beea87 100644 --- a/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java +++ b/ui/src/main/java/lee/study/down/mvc/controller/HttpDownController.java @@ -44,6 +44,9 @@ public ResultInfo getTask(@RequestParam String id) throws Exception { if (taskInfo == null) { resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在"); } else { + if (taskInfo.isSupportRange()) { + taskInfo.setConnections(ContentManager.CONFIG.get().getConnections()); + } taskInfo.setFilePath(ContentManager.CONFIG.get().getLastPath()); resultInfo.setData(taskInfo); } diff --git a/ui/src/main/java/lee/study/down/mvc/form/ConfigForm.java b/ui/src/main/java/lee/study/down/mvc/form/ConfigForm.java index 874f5889..2a236b2d 100644 --- a/ui/src/main/java/lee/study/down/mvc/form/ConfigForm.java +++ b/ui/src/main/java/lee/study/down/mvc/form/ConfigForm.java @@ -12,6 +12,7 @@ public class ConfigForm { private boolean guideFlag; //是否需要新手引导教程 private int proxyPort; //代理端口号 private int timeout; //超时重试时间 + private int connections; //默认分段数 private boolean secProxyEnable; //二级代理开关 private ProxyConfigForm secProxyConfig; //二级代理设置 private String lastPath; //最后保存文件的路径 diff --git a/ui/src/main/java/lee/study/down/update/GithubUpdateCheck.java b/ui/src/main/java/lee/study/down/update/GithubUpdateCheck.java index a5991dd6..092de884 100644 --- a/ui/src/main/java/lee/study/down/update/GithubUpdateCheck.java +++ b/ui/src/main/java/lee/study/down/update/GithubUpdateCheck.java @@ -1,6 +1,6 @@ package lee.study.down.update; -import lee.study.down.model.HttpDownInfo; +import lee.study.down.model.UpdateInfo; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -8,7 +8,7 @@ public class GithubUpdateCheck implements UpdateCheck { @Override - public HttpDownInfo check() throws Exception { + public UpdateInfo check() throws Exception { Document document = Jsoup.connect("https://github.com/monkeyWie/proxyee-down/releases").get(); Elements elements = document.select(".release-title.text-normal"); elements.forEach((e) -> System.out.println(e.text())); diff --git a/ui/src/main/java/lee/study/down/update/UpdateCheck.java b/ui/src/main/java/lee/study/down/update/UpdateCheck.java index 69817d8a..03487b8a 100644 --- a/ui/src/main/java/lee/study/down/update/UpdateCheck.java +++ b/ui/src/main/java/lee/study/down/update/UpdateCheck.java @@ -1,7 +1,7 @@ package lee.study.down.update; -import lee.study.down.model.HttpDownInfo; +import lee.study.down.model.UpdateInfo; public interface UpdateCheck { - HttpDownInfo check() throws Exception; + UpdateInfo check() throws Exception; } diff --git a/ui/view/src/components/ConfigPage.vue b/ui/view/src/components/ConfigPage.vue index 80a6fe81..0ece07dd 100644 --- a/ui/view/src/components/ConfigPage.vue +++ b/ui/view/src/components/ConfigPage.vue @@ -6,6 +6,18 @@ + + + + + + + @@ -112,9 +124,6 @@ this.$refs['form'].validate((valid) => { if (valid) { this.load = true; - if (!this.form.secProxyEnable) { - - } this.$http.post('api/setConfigInfo', this.form) .then((response) => { let result = response.data; @@ -152,4 +161,14 @@ .num-input { width: 15%; } + + .el-slider { + display: inline-block; + padding-left: 5px; + width: 70%; + } + + .item { + padding-left: 5px; + } diff --git a/ui/view/src/components/TaskList.vue b/ui/view/src/components/TaskList.vue index a6ba05f8..974e3e82 100644 --- a/ui/view/src/components/TaskList.vue +++ b/ui/view/src/components/TaskList.vue @@ -107,7 +107,12 @@ if (task.status == 7 || task.status == 5) { return this.speedAvg(task); } else { - return this.speedInterval(task); + let speed = this.speedInterval(task); + if (task.speedCount > 5 || speed > 0) { + return speed; + } else { + return this.speedAvg(task); + } } }, speedAvg(task) { @@ -133,7 +138,7 @@ if (task.status == 5) { return '暂停中'; } - let speed = this.speedInterval(task); + let speed = this.speed(task); if (speed) { return Util.timeFmt((task.totalSize - task.downSize) / speed); } else { @@ -208,7 +213,8 @@ this.$message(result.msg); } }); - }).catch(()=>{}); + }).catch(() => { + }); }, }, created() { @@ -218,17 +224,34 @@ } let msg = eval('(' + e.data + ')'); if (msg) { - /*this.tasks = msg.sort((task1, task2) => { - return task1.startTime - task2.startTime; - });*/ this.tasks = msg.map((task1) => { this.tasks.forEach((task2) => { if (task2.id == task1.id) { task1.intervalTime = task1.lastTime - task2.lastTime; task1.intervalDownSize = task1.downSize - task2.downSize; + task1.speedCount = task2.speedCount; + if (task1.intervalDownSize == 0) { + if (!task1.speedCount) { + task1.speedCount = 1; + } else { + task1.speedCount++; + } + } else { + task1.speedCount = 1; + } task1.chunkInfoList.forEach((chunk, index) => { chunk.intervalTime = chunk.lastTime - task2.chunkInfoList[index].lastTime; chunk.intervalDownSize = chunk.downSize - task2.chunkInfoList[index].downSize; + chunk.speedCount = task2.chunkInfoList[index].speedCount; + if (chunk.intervalDownSize == 0) { + if (!chunk.speedCount) { + chunk.speedCount = 1; + } else { + chunk.speedCount++; + } + } else { + chunk.speedCount = 1; + } }); } return false;