use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method delNewTask.
@RequestMapping("/delNewTask")
public ResultInfo delNewTask(@RequestParam String id) throws Exception {
ResultInfo resultInfo = new ResultInfo();
ContentManager.DOWN.removeBoot(id);
return resultInfo;
}
use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method getVersion.
@RequestMapping("/getVersion")
public ResultInfo getVersion() {
ResultInfo resultInfo = new ResultInfo();
resultInfo.setData(version);
return resultInfo;
}
use of lee.study.down.model.ResultInfo 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;
}
use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method bdyUnzip.
@RequestMapping("/bdyUnzip")
public ResultInfo bdyUnzip(@RequestParam String id, @RequestParam boolean ignore, @RequestBody UnzipForm unzipForm) throws IOException {
ResultInfo resultInfo = new ResultInfo();
File file = new File(unzipForm.getFilePath());
if (file.exists() && file.isFile()) {
if (!unzipForm.getFilePath().equalsIgnoreCase(unzipForm.getToPath())) {
if (ignore || BdyZip.isBdyZip(unzipForm.getFilePath())) {
UnzipInfo unzipInfo = new UnzipInfo().setId(id);
if (!FileUtil.exists(unzipForm.getToPath())) {
FileUtil.createDirSmart(unzipForm.getToPath());
}
if (!FileUtil.canWrite(unzipForm.getToPath())) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("无权访问解压路径,请修改路径或开放目录写入权限");
return resultInfo;
}
new Thread(() -> {
try {
BdyZip.unzip(unzipForm.getFilePath(), unzipForm.getToPath(), new BdyUnzipCallback() {
@Override
public void onStart() {
unzipInfo.setType(BdyZip.ON_START).setStartTime(System.currentTimeMillis());
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
@Override
public void onFix(long totalSize, long fixSize) {
unzipInfo.setType(BdyZip.ON_FIX).setTotalFixSize(totalSize).setFixSize(fixSize);
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
@Override
public void onFixDone(List<BdyZipEntry> list) {
unzipInfo.setType(BdyZip.ON_FIX_DONE).setTotalFileSize(list.stream().map(entry -> entry.getCompressedSize()).reduce((s1, s2) -> s1 + s2).get());
}
@Override
public void onEntryStart(BdyZipEntry entry) {
unzipInfo.setType(BdyZip.ON_ENTRY_START).setEntry(entry).setCurrFileSize(entry.getCompressedSize()).setCurrWriteSize(0);
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
@Override
public void onEntryWrite(long totalSize, long writeSize) {
unzipInfo.setType(BdyZip.ON_ENTRY_WRITE).setCurrWriteSize(unzipInfo.getCurrWriteSize() + writeSize).setTotalWriteSize(unzipInfo.getTotalWriteSize() + writeSize);
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
@Override
public void onDone() {
unzipInfo.setType(BdyZip.ON_DONE).setEndTime(System.currentTimeMillis());
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
@Override
public void onError(Exception e) {
unzipInfo.setType(BdyZip.ON_ERROR).setErrorMsg(e.toString());
ContentManager.WS.sendMsg(new WsForm(WsDataType.UNZIP_ING, unzipInfo));
}
});
} catch (Exception e) {
LOGGER.error("unzip error:", e);
}
}).start();
} else {
resultInfo.setStatus(ResultStatus.BAD.getCode());
resultInfo.setMsg("解压失败,请确认是否为百度云批量下载zip文件");
}
} else {
resultInfo.setStatus(ResultStatus.BAD.getCode());
resultInfo.setMsg("解压失败,文件路径与解压路径相同");
}
} else {
resultInfo.setStatus(ResultStatus.BAD.getCode());
resultInfo.setMsg("解压失败,文件不存在");
}
return resultInfo;
}
use of lee.study.down.model.ResultInfo in project proxyee-down by monkeyWie.
the class HttpDownController method doUpdate.
@RequestMapping("/doUpdate")
public ResultInfo doUpdate() throws Exception {
ResultInfo resultInfo = new ResultInfo();
if (updateInfo == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("没有可用版本进行更新");
return resultInfo;
}
if (updateBootstrap != null) {
updateBootstrap.close();
updateBootstrap = null;
}
try {
updateBootstrap = updateService.update(updateInfo, new HttpDownCallback() {
@Override
public void onDone(HttpDownInfo httpDownInfo) throws Exception {
String zipPath = httpDownInfo.getTaskInfo().buildTaskFilePath();
String unzipDir = "proxyee-down-" + updateInfo.getVersionStr();
String unzipPath = unzipDir + "/main/proxyee-down-core.jar";
// 下载完解压
FileUtil.unzip(zipPath, null, unzipPath);
// 复制出来
Files.copy(Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipPath), Paths.get(httpDownInfo.getTaskInfo().getFilePath() + File.separator + "proxyee-down-core.jar.bak"));
// 删除临时的文件
FileUtil.deleteIfExists(zipPath);
FileUtil.deleteIfExists(httpDownInfo.getTaskInfo().getFilePath() + File.separator + unzipDir);
// 通知客户端
ContentManager.WS.sendMsg(new WsForm(WsDataType.UPDATE_PROGRESS, httpDownInfo.getTaskInfo()));
// 清空更新下载信息
updateBootstrap = null;
}
});
} catch (TimeoutException e) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("检测更新超时,请重试");
return resultInfo;
}
return resultInfo;
}
Aggregations