Search in sources :

Example 6 with AbstractHttpDownBootstrap

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;
}
Also used : AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with AbstractHttpDownBootstrap

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;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) BootstrapException(lee.study.down.exception.BootstrapException) ResultInfo(lee.study.down.model.ResultInfo) HttpDownInfo(lee.study.down.model.HttpDownInfo)

Aggregations

AbstractHttpDownBootstrap (lee.study.down.boot.AbstractHttpDownBootstrap)7 ResultInfo (lee.study.down.model.ResultInfo)4 TaskInfo (lee.study.down.model.TaskInfo)4 HttpDownInfo (lee.study.down.model.HttpDownInfo)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BootstrapException (lee.study.down.exception.BootstrapException)1 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)1