use of lee.study.down.model.HttpDownInfo in project proxyee-down by monkeyWie.
the class HttpDownController method getTask.
@RequestMapping("/getTask")
public ResultInfo getTask(@RequestParam String id) throws Exception {
ResultInfo resultInfo = new ResultInfo();
HttpDownInfo httpDownInfo = ContentManager.DOWN.getDownInfo(id);
if (httpDownInfo != null) {
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
Map<String, Object> data = new HashMap<>();
data.put("task", NewTaskForm.parse(httpDownInfo));
// 检查是否有相同大小的文件
List<HttpDownInfo> sameTasks = ContentManager.DOWN.getDownInfos().stream().filter(downInfo -> HttpDownStatus.WAIT != downInfo.getTaskInfo().getStatus() && HttpDownStatus.DONE != downInfo.getTaskInfo().getStatus() && downInfo.getTaskInfo().getTotalSize() == taskInfo.getTotalSize()).collect(Collectors.toList());
data.put("sameTasks", NewTaskForm.parse(sameTasks));
resultInfo.setData(data);
}
return resultInfo;
}
use of lee.study.down.model.HttpDownInfo in project proxyee-down by monkeyWie.
the class GithubUpdateService method update.
@Override
public AbstractHttpDownBootstrap update(UpdateInfo updateInfo, HttpDownCallback callback) throws Exception {
HttpRequestInfo requestInfo = HttpDownUtil.buildGetRequest(updateInfo.getUrl());
TaskInfo taskInfo = HttpDownUtil.getTaskInfo(requestInfo, null, null, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup).setConnections(64).setFileName("proxyee-down-jar.zip").setFilePath(HttpDownConstant.HOME_PATH.substring(0, HttpDownConstant.HOME_PATH.length() - 1));
HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, null);
AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, 5, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, callback);
FileUtil.deleteIfExists(bootstrap.getHttpDownInfo().getTaskInfo().buildTaskFilePath());
bootstrap.startDown();
return bootstrap;
}
use of lee.study.down.model.HttpDownInfo in project proxyee-down by monkeyWie.
the class HttpDownController method doUpdate.
@RequestMapping("/doUpdate")
public ResultInfo doUpdate() throws Exception {
ResultInfo resultInfo = new ResultInfo();
if (updateInfo == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("没有可用版本进行更新");
return resultInfo;
}
if (updateBootstrap != null) {
updateBootstrap.close();
updateBootstrap = null;
}
try {
updateBootstrap = updateService.update(updateInfo, new HttpDownCallback() {
@Override
public void onDone(HttpDownInfo httpDownInfo) throws Exception {
String zipPath = httpDownInfo.getTaskInfo().buildTaskFilePath();
String unzipDir = "proxyee-down-" + updateInfo.getVersionStr();
String unzipPath = unzipDir + "/main/proxyee-down-core.jar";
// 下载完解压
FileUtil.unzip(zipPath, null, unzipPath);
// 复制出来
Files.copy(Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipPath), Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator + "proxyee-down-core.jar.bak"));
// 删除临时的文件
FileUtil.deleteIfExists(zipPath);
FileUtil.deleteIfExists(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipDir);
// 通知客户端
ContentManager.WS.sendMsg(new WsForm(WsDataType.UPDATE_PROGRESS, httpDownInfo.getTaskInfo()));
// 清空更新下载信息
updateBootstrap = null;
}
});
} catch (TimeoutException e) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("检测更新超时,请重试");
return resultInfo;
}
return resultInfo;
}
use of lee.study.down.model.HttpDownInfo in project proxyee-down by monkeyWie.
the class HttpDownController method commonStartTask.
public static ResultInfo commonStartTask(NewTaskForm taskForm) throws Exception {
ResultInfo resultInfo = new ResultInfo();
AbstractHttpDownBootstrap bootstrap = ContentManager.DOWN.getBoot(taskForm.getId());
HttpDownInfo httpDownInfo = bootstrap.getHttpDownInfo();
// 覆盖下载
if (!StringUtils.isEmpty(taskForm.getOldId())) {
AbstractHttpDownBootstrap oldBootstrap = ContentManager.DOWN.getBoot(taskForm.getOldId());
if (oldBootstrap == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
return resultInfo;
} else {
// 暂停之前的下载任务
oldBootstrap.pauseDown();
// 修改request
oldBootstrap.getHttpDownInfo().setRequest(httpDownInfo.getRequest());
oldBootstrap.getHttpDownInfo().setProxyConfig(httpDownInfo.getProxyConfig());
Map<String, Object> attr = oldBootstrap.getHttpDownInfo().getAttrs();
if (attr == null) {
attr = new HashMap<>();
oldBootstrap.getHttpDownInfo().setAttrs(attr);
}
attr.put(NewTaskForm.KEY_UNZIP_FLAG, taskForm.isUnzip());
attr.put(NewTaskForm.KEY_UNZIP_PATH, taskForm.getUnzipPath());
// 移除新的下载任务
ContentManager.DOWN.removeBoot(taskForm.getId());
// 持久化
ContentManager.DOWN.save();
// 用新链接继续下载
oldBootstrap.continueDown();
}
} else {
if (StringUtils.isEmpty(taskForm.getFileName())) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("文件名不能为空");
return resultInfo;
}
if (StringUtils.isEmpty(taskForm.getFilePath())) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("路径不能为空");
return resultInfo;
}
buildDefaultValues(taskForm);
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
synchronized (taskInfo) {
if (taskInfo.getStatus() != HttpDownStatus.WAIT) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务已添加至下载列表");
}
taskInfo.setFileName(taskForm.getFileName());
taskInfo.setFilePath(taskForm.getFilePath());
Map<String, Object> attr = httpDownInfo.getAttrs();
if (attr == null) {
attr = new HashMap<>();
httpDownInfo.setAttrs(attr);
}
attr.put(NewTaskForm.KEY_UNZIP_FLAG, taskForm.isUnzip());
attr.put(NewTaskForm.KEY_UNZIP_PATH, taskForm.getUnzipPath());
if (taskInfo.isSupportRange()) {
taskInfo.setConnections(taskForm.getConnections());
} else {
taskInfo.setConnections(1);
}
try {
bootstrap.startDown();
} catch (BootstrapException e) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg(e.getMessage());
return resultInfo;
}
// 记录存储路径
String lastPath = ContentManager.CONFIG.get().getLastPath();
if (!taskForm.getFilePath().equalsIgnoreCase(lastPath)) {
ContentManager.CONFIG.get().setLastPath(taskForm.getFilePath());
ContentManager.CONFIG.save();
}
}
}
return resultInfo;
}
Aggregations