Search in sources :

Example 1 with ResultInfo

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

the class HttpDownController method pauseTask.

@RequestMapping("/pauseTask")
public ResultInfo pauseTask(@RequestParam String id) throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    AbstractHttpDownBootstrap bootstrap = ContentManager.DOWN.getBoot(id);
    if (bootstrap == null) {
        resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
    } else {
        bootstrap.pauseDown();
    }
    return resultInfo;
}
Also used : AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ResultInfo

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

the class HttpDownController method open.

@RequestMapping("/open")
public ResultInfo open(@RequestParam String url) throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    if (ContentManager.CONFIG.get().getUiModel() == 1) {
        OsUtil.openBrowse(url);
    }
    resultInfo.setData(ContentManager.CONFIG.get().getUiModel());
    return resultInfo;
}
Also used : ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ResultInfo

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

the class HttpDownController method getChildDirList.

@RequestMapping("/getChildDirList")
public ResultInfo getChildDirList(@RequestBody(required = false) DirForm body) {
    ResultInfo resultInfo = new ResultInfo();
    List<DirInfo> data = new LinkedList<>();
    resultInfo.setData(data);
    File[] files;
    if (body == null || StringUtils.isEmpty(body.getPath())) {
        if (OsUtil.isMac()) {
            files = new File("/Users").listFiles(file -> file.isDirectory() && file.getName().indexOf(".") != 0);
        } else {
            files = File.listRoots();
        }
    } else {
        File file = new File(body.getPath());
        if (file.exists() && file.isDirectory()) {
            files = file.listFiles();
        } else {
            resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("路径不存在");
            return resultInfo;
        }
    }
    if (files != null && files.length > 0) {
        boolean isFileList = "file".equals(body.getModel());
        for (File tempFile : files) {
            if (tempFile.isFile()) {
                if (isFileList) {
                    data.add(new DirInfo(StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath() : tempFile.getName(), tempFile.getAbsolutePath(), true));
                }
            } else if (tempFile.isDirectory() && (tempFile.getParent() == null || !tempFile.isHidden()) && (OsUtil.isWindows() || tempFile.getName().indexOf(".") != 0)) {
                DirInfo dirInfo = new DirInfo(StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath() : tempFile.getName(), tempFile.getAbsolutePath(), tempFile.listFiles() == null ? true : Arrays.stream(tempFile.listFiles()).noneMatch(file -> file != null && (file.isDirectory() || isFileList) && !file.isHidden()));
                data.add(dirInfo);
            }
        }
    }
    return resultInfo;
}
Also used : 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) DirInfo(lee.study.down.model.DirInfo) ResultInfo(lee.study.down.model.ResultInfo) File(java.io.File) LinkedList(java.util.LinkedList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ResultInfo

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

the class HttpDownController method commonBuildTask.

public static ResultInfo commonBuildTask(BuildTaskForm form) throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    Map<String, String> heads = new LinkedHashMap<>();
    if (form.getHeads() != null) {
        for (Map<String, String> head : form.getHeads()) {
            String key = head.get("key");
            String value = head.get("value");
            if (!StringUtils.isEmpty(head.get("key")) && !StringUtils.isEmpty(head.get("value"))) {
                heads.put(key, value);
            }
        }
    }
    try {
        HttpRequestInfo requestInfo = HttpDownUtil.buildGetRequest(form.getUrl(), heads, form.getBody());
        TaskInfo taskInfo = HttpDownUtil.getTaskInfo(requestInfo, null, ContentManager.CONFIG.get().getSecProxyConfig(), HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup);
        HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, ContentManager.CONFIG.get().getSecProxyConfig());
        ContentManager.DOWN.putBoot(httpDownInfo);
        resultInfo.setData(taskInfo.getId());
    } catch (MalformedURLException e) {
        resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("链接格式不正确");
    } catch (TimeoutException e) {
        resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("连接超时,请重试");
    } catch (Exception e) {
        throw new RuntimeException("buildTask error:" + form.toString(), e);
    }
    return resultInfo;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) MalformedURLException(java.net.MalformedURLException) HttpRequestInfo(lee.study.down.model.HttpRequestInfo) ResultInfo(lee.study.down.model.ResultInfo) HttpDownInfo(lee.study.down.model.HttpDownInfo) TimeoutException(java.util.concurrent.TimeoutException) BootstrapException(lee.study.down.exception.BootstrapException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with ResultInfo

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

the class HttpDownController method restart.

@RequestMapping("/restart")
public ResultInfo restart() throws Exception {
    ResultInfo resultInfo = new ResultInfo();
    // 通知父进程重启
    System.out.println("proxyee-down-update");
    return resultInfo;
}
Also used : 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