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);
}
};
}
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;
}
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;
}
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;
}
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;
}
Aggregations