use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class HttpDownController method deleteTask.
@RequestMapping("/deleteTask")
public ResultInfo deleteTask(@RequestParam String id, @RequestParam boolean delFile) throws Exception {
ResultInfo resultInfo = new ResultInfo();
AbstractHttpDownBootstrap bootstrap = ContentManager.DOWN.getBoot(id);
if (bootstrap == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
} else {
bootstrap.delete(delFile);
}
return resultInfo;
}
use of lee.study.down.boot.AbstractHttpDownBootstrap 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