use of lee.study.down.model.ResultInfo 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.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method getStartTasks.
@RequestMapping("/getStartTasks")
public ResultInfo getStartTasks() throws Exception {
ResultInfo resultInfo = new ResultInfo();
resultInfo.setData(DownContent.setUrl(ContentManager.DOWN.getStartTasks()));
return resultInfo;
}
use of lee.study.down.model.ResultInfo 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;
}
use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method getConfigInfo.
@RequestMapping("/getConfigInfo")
public ResultInfo getConfigInfo() {
ResultInfo resultInfo = new ResultInfo();
resultInfo.setData(ContentManager.CONFIG.get());
return resultInfo;
}
use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class OpenController method open.
@RequestMapping("createTask")
public ResultInfo open(@RequestBody CreateTaskForm createTaskForm) throws Exception {
ResultInfo resultInfo = HttpDownController.commonBuildTask(createTaskForm.getRequest());
if (resultInfo.getStatus() == ResultStatus.SUCC.getCode()) {
TaskInfo taskInfo = ContentManager.DOWN.getTaskInfo(resultInfo.getData().toString());
NewTaskForm taskForm = new NewTaskForm();
taskForm.setId(taskInfo.getId());
if (!StringUtils.isEmpty(createTaskForm.getFileName())) {
taskForm.setFileName(createTaskForm.getFileName());
} else {
taskForm.setFileName(taskInfo.getFileName());
}
if (!StringUtils.isEmpty(taskInfo.getFilePath())) {
taskForm.setFilePath(taskInfo.getFilePath());
} else {
taskForm.setFilePath(createTaskForm.getFilePath());
}
taskForm.setUnzip(createTaskForm.getUnzipFlag() == 1);
taskForm.setUnzipPath(createTaskForm.getUnzipPath());
taskForm.setConnections(createTaskForm.getConnections());
resultInfo = HttpDownController.commonStartTask(taskForm);
}
return resultInfo;
}
Aggregations