Search in sources :

Example 6 with TaskInfo

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

the class HttpDownHandleInterceptFactory method create.

@Override
public HttpProxyIntercept create() {
    return new HttpProxyIntercept() {

        @Override
        public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception {
            HttpRequest httpRequest = pipeline.getHttpRequest();
            ProxyConfig proxyConfig = ContentManager.CONFIG.get().getSecProxyConfig();
            TaskInfo taskInfo = HttpDownUtil.getTaskInfo(httpRequest, httpResponse.headers(), proxyConfig, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup);
            HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, httpRequest, proxyConfig);
            ContentManager.DOWN.putBoot(httpDownInfo);
            httpResponse.setStatus(HttpResponseStatus.OK);
            httpResponse.headers().clear();
            httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
            byte[] content;
            if (HttpUtil.checkHead(httpRequest, HttpHeaderNames.HOST, "^.*\\.baidupcs\\.com.*$")) {
                content = "<script>window.close();</script>".getBytes();
            } else {
                content = "<script>window.history.go(-1);</script>".getBytes();
            }
            httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length);
            clientChannel.writeAndFlush(httpResponse);
            HttpContent httpContent = new DefaultLastHttpContent();
            httpContent.content().writeBytes(content);
            clientChannel.writeAndFlush(httpContent);
            clientChannel.close();
            httpDownDispatch.dispatch(httpDownInfo);
        }
    };
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) TaskInfo(lee.study.down.model.TaskInfo) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Channel(io.netty.channel.Channel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpProxyIntercept(lee.study.proxyee.intercept.HttpProxyIntercept) ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) HttpDownInfo(lee.study.down.model.HttpDownInfo) HttpProxyInterceptPipeline(lee.study.proxyee.intercept.HttpProxyInterceptPipeline) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent)

Example 7 with TaskInfo

use of lee.study.down.model.TaskInfo 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 8 with TaskInfo

use of lee.study.down.model.TaskInfo 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 9 with TaskInfo

use of lee.study.down.model.TaskInfo 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 10 with TaskInfo

use of lee.study.down.model.TaskInfo 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)

Aggregations

TaskInfo (lee.study.down.model.TaskInfo)21 HttpDownInfo (lee.study.down.model.HttpDownInfo)6 ResultInfo (lee.study.down.model.ResultInfo)6 AbstractHttpDownBootstrap (lee.study.down.boot.AbstractHttpDownBootstrap)5 ChunkInfo (lee.study.down.model.ChunkInfo)5 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)5 IOException (java.io.IOException)4 BootstrapException (lee.study.down.exception.BootstrapException)4 WsForm (lee.study.down.mvc.form.WsForm)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 HttpResponse (io.netty.handler.codec.http.HttpResponse)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Channel (io.netty.channel.Channel)2 HttpContent (io.netty.handler.codec.http.HttpContent)2 MalformedURLException (java.net.MalformedURLException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 HttpDownCallback (lee.study.down.dispatch.HttpDownCallback)2