Search in sources :

Example 6 with ResultInfo

use of lee.study.down.model.ResultInfo 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;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) Arrays(java.util.Arrays) HttpDownConstant(lee.study.down.constant.HttpDownConstant) BdyZip(lee.study.down.io.BdyZip) BdyZipEntry(lee.study.down.io.BdyZip.BdyZipEntry) RequestParam(org.springframework.web.bind.annotation.RequestParam) ContentManager(lee.study.down.content.ContentManager) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) ResultStatus(lee.study.down.model.ResultInfo.ResultStatus) FileUtil(lee.study.down.util.FileUtil) TaskInfo(lee.study.down.model.TaskInfo) UpdateService(lee.study.down.update.UpdateService) DirInfo(lee.study.down.model.DirInfo) DirForm(lee.study.down.mvc.form.DirForm) HttpDownApplication(lee.study.down.gui.HttpDownApplication) Map(java.util.Map) GithubUpdateService(lee.study.down.update.GithubUpdateService) HttpDownCallback(lee.study.down.dispatch.HttpDownCallback) Collectors(java.util.stream.Collectors) UnzipForm(lee.study.down.mvc.form.UnzipForm) RestController(org.springframework.web.bind.annotation.RestController) UpdateInfo(lee.study.down.model.UpdateInfo) List(java.util.List) WsForm(lee.study.down.mvc.form.WsForm) BootstrapException(lee.study.down.exception.BootstrapException) ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) HttpDownStatus(lee.study.down.constant.HttpDownStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) BdyUnzipCallback(lee.study.down.io.BdyZip.BdyUnzipCallback) ConfigInfo(lee.study.down.model.ConfigInfo) LinkedList(java.util.LinkedList) BuildTaskForm(lee.study.down.mvc.form.BuildTaskForm) Desktop(java.awt.Desktop) NewTaskForm(lee.study.down.mvc.form.NewTaskForm) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) HttpRequestInfo(lee.study.down.model.HttpRequestInfo) WsDataType(lee.study.down.mvc.ws.WsDataType) ResultInfo(lee.study.down.model.ResultInfo) IOException(java.io.IOException) File(java.io.File) UnzipInfo(lee.study.down.model.UnzipInfo) OsUtil(lee.study.down.util.OsUtil) DownContent(lee.study.down.content.DownContent) HttpDownInfo(lee.study.down.model.HttpDownInfo) Paths(java.nio.file.Paths) ConfigForm(lee.study.down.mvc.form.ConfigForm) HttpDownUtil(lee.study.down.util.HttpDownUtil) StringUtils(org.springframework.util.StringUtils) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResultInfo(lee.study.down.model.ResultInfo) HttpDownInfo(lee.study.down.model.HttpDownInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ResultInfo

use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.

the class HttpDownController method checkUpdate.

@RequestMapping("/checkUpdate")
public ResultInfo checkUpdate() throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    updateInfo = updateService.check(version);
    if (updateInfo == null) {
        resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("已经是最新版本");
        return resultInfo;
    }
    resultInfo.setData(updateInfo);
    return resultInfo;
}
Also used : ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ResultInfo

use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.

the class HttpDownController method getNewTask.

@RequestMapping("/getNewTask")
public ResultInfo getNewTask() throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    TaskInfo taskInfo = ContentManager.DOWN.getWaitTask();
    if (taskInfo != null) {
        resultInfo.setData(taskInfo.getId());
    }
    return resultInfo;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ResultInfo

use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.

the class HttpDownController method openTaskDir.

@RequestMapping("/openTaskDir")
public ResultInfo openTaskDir(@RequestParam String id) throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    TaskInfo taskInfo = ContentManager.DOWN.getTaskInfo(id);
    if (taskInfo != null) {
        if (FileUtil.exists(taskInfo.getFilePath())) {
            Desktop.getDesktop().open(new File(taskInfo.getFilePath()));
        } else {
            resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("目录不存在");
        }
    } else {
        resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
    }
    return resultInfo;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ResultInfo(lee.study.down.model.ResultInfo) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ResultInfo

use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.

the class HttpDownController method setConfigInfo.

@RequestMapping("/setConfigInfo")
public ResultInfo setConfigInfo(@RequestBody ConfigForm configForm) {
    ResultInfo resultInfo = new ResultInfo();
    int beforePort = ContentManager.CONFIG.get().getProxyPort();
    boolean beforeSecProxyEnable = ContentManager.CONFIG.get().isSecProxyEnable();
    ProxyConfig beforeSecProxyConfig = ContentManager.CONFIG.get().getSecProxyConfig();
    if (!configForm.isSecProxyEnable()) {
        configForm.setSecProxyConfig(null);
    }
    ConfigInfo configInfo = configForm.convert();
    ContentManager.CONFIG.set(configInfo);
    ContentManager.CONFIG.save();
    // 代理服务器需要重新启动
    if (beforePort != configInfo.getProxyPort() || beforeSecProxyEnable != configInfo.isSecProxyEnable() || (configInfo.isSecProxyEnable() && !configInfo.getSecProxyConfig().equals(beforeSecProxyConfig))) {
        new Thread(() -> {
            HttpDownApplication.getProxyServer().close();
            HttpDownApplication.getProxyServer().setProxyConfig(configInfo.getSecProxyConfig());
            HttpDownApplication.getProxyServer().start(configInfo.getProxyPort());
        }).start();
    }
    return resultInfo;
}
Also used : ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) ResultInfo(lee.study.down.model.ResultInfo) ConfigInfo(lee.study.down.model.ConfigInfo) 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