Search in sources :

Example 1 with AbstractHttpDownBootstrap

use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.

the class DownContent method init.

/**
 * 从配置文件中加载信息
 */
public void init() {
    downContent = new ConcurrentHashMap<>();
    if (FileUtil.exists(HttpDownConstant.TASK_RECORD_PATH)) {
        try {
            List<HttpDownInfo> records = (List<HttpDownInfo>) ByteUtil.deserialize(HttpDownConstant.TASK_RECORD_PATH);
            for (HttpDownInfo httpDownInfo : records) {
                AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, ContentManager.CONFIG.get().getRetryCount(), HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, HttpDownConstant.httpDownCallback);
                TaskInfo taskInfo = httpDownInfo.getTaskInfo();
                if (taskInfo.getStatus() == HttpDownStatus.WAIT) {
                    continue;
                }
                // 下载未完成
                if (taskInfo.getStatus() != HttpDownStatus.DONE) {
                    String taskDetailPath = taskInfo.buildTaskRecordFilePath();
                    String taskDetailBakPath = taskInfo.buildTaskRecordBakFilePath();
                    // 存在下载进度信息则更新,否则重新下载
                    if (FileUtil.existsAny(taskDetailPath, taskDetailBakPath)) {
                        try {
                            taskInfo = (TaskInfo) ByteUtil.deserialize(taskDetailPath, taskDetailBakPath);
                            httpDownInfo.setTaskInfo(taskInfo);
                        } catch (IOException | ClassNotFoundException e) {
                            taskInfo.reset();
                        }
                    } else {
                        taskInfo.reset();
                    }
                    if (taskInfo.getStatus() != HttpDownStatus.FAIL) {
                        // 设置为暂停状态
                        taskInfo.setStatus(HttpDownStatus.PAUSE);
                        taskInfo.getChunkInfoList().forEach((chunk) -> {
                            if (chunk.getStatus() != HttpDownStatus.DONE) {
                                chunk.setStatus(HttpDownStatus.PAUSE);
                            }
                        });
                    }
                }
                putBoot(bootstrap);
            }
        } catch (Exception e) {
            LOGGER.warn("加载配置文件失败:", e);
        }
    }
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HttpDownInfo(lee.study.down.model.HttpDownInfo) IOException(java.io.IOException)

Example 2 with AbstractHttpDownBootstrap

use of lee.study.down.boot.AbstractHttpDownBootstrap 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 3 with AbstractHttpDownBootstrap

use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.

the class GithubUpdateService method update.

@Override
public AbstractHttpDownBootstrap update(UpdateInfo updateInfo, HttpDownCallback callback) throws Exception {
    HttpRequestInfo requestInfo = HttpDownUtil.buildGetRequest(updateInfo.getUrl());
    TaskInfo taskInfo = HttpDownUtil.getTaskInfo(requestInfo, null, null, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup).setConnections(64).setFileName("proxyee-down-jar.zip").setFilePath(HttpDownConstant.HOME_PATH.substring(0, HttpDownConstant.HOME_PATH.length() - 1));
    HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, null);
    AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, 5, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, callback);
    FileUtil.deleteIfExists(bootstrap.getHttpDownInfo().getTaskInfo().buildTaskFilePath());
    bootstrap.startDown();
    return bootstrap;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) HttpRequestInfo(lee.study.down.model.HttpRequestInfo) HttpDownInfo(lee.study.down.model.HttpDownInfo)

Example 4 with AbstractHttpDownBootstrap

use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.

the class DownContent method putBoot.

public void putBoot(HttpDownInfo httpDownInfo) {
    AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, ContentManager.CONFIG.get().getRetryCount(), HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, HttpDownConstant.httpDownCallback);
    TaskInfo taskInfo = bootstrap.getHttpDownInfo().getTaskInfo();
    if (taskInfo.isSupportRange()) {
        taskInfo.setConnections(ContentManager.CONFIG.get().getConnections());
    }
    taskInfo.setFilePath(ContentManager.CONFIG.get().getLastPath());
    putBoot(bootstrap);
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap)

Example 5 with AbstractHttpDownBootstrap

use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.

the class HttpDownController method continueTask.

@RequestMapping("/continueTask")
public ResultInfo continueTask(@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.continueDown();
    }
    return resultInfo;
}
Also used : AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) ResultInfo(lee.study.down.model.ResultInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AbstractHttpDownBootstrap (lee.study.down.boot.AbstractHttpDownBootstrap)7 ResultInfo (lee.study.down.model.ResultInfo)4 TaskInfo (lee.study.down.model.TaskInfo)4 HttpDownInfo (lee.study.down.model.HttpDownInfo)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BootstrapException (lee.study.down.exception.BootstrapException)1 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)1