Search in sources :

Example 16 with ResultInfo

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

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

Example 18 with 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;
}
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)

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

Example 20 with 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;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) NewTaskForm(lee.study.down.mvc.form.NewTaskForm) ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResultInfo (lee.study.down.model.ResultInfo)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 TaskInfo (lee.study.down.model.TaskInfo)8 AbstractHttpDownBootstrap (lee.study.down.boot.AbstractHttpDownBootstrap)7 HttpDownInfo (lee.study.down.model.HttpDownInfo)6 TimeoutException (java.util.concurrent.TimeoutException)5 BootstrapException (lee.study.down.exception.BootstrapException)5 File (java.io.File)4 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)4 LinkedHashMap (java.util.LinkedHashMap)4 HttpDownCallback (lee.study.down.dispatch.HttpDownCallback)4 ConfigInfo (lee.study.down.model.ConfigInfo)4 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)4 NewTaskForm (lee.study.down.mvc.form.NewTaskForm)4 Desktop (java.awt.Desktop)3 Files (java.nio.file.Files)3 Paths (java.nio.file.Paths)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3