2025-02-21 18:30:13 +08:00
|
|
|
import BaseController from "./BaseController";
|
|
|
|
import VersionService from "../service/VersionService";
|
2025-02-23 02:11:17 +08:00
|
|
|
import { fail, success } from "../utils/response";
|
|
|
|
import VersionDao from "../dao/VersionDao";
|
2025-02-21 18:30:13 +08:00
|
|
|
|
|
|
|
class VersionController extends BaseController {
|
|
|
|
private readonly _versionService: VersionService;
|
2025-02-23 02:11:17 +08:00
|
|
|
private readonly _versionDao: VersionDao;
|
2025-02-21 18:30:13 +08:00
|
|
|
|
2025-02-23 02:11:17 +08:00
|
|
|
constructor(versionService: VersionService, versionDao: VersionDao) {
|
2025-02-21 18:30:13 +08:00
|
|
|
super();
|
|
|
|
this._versionService = versionService;
|
2025-02-23 02:11:17 +08:00
|
|
|
this._versionDao = versionDao;
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getVersions(req: ControllerParam) {
|
|
|
|
this._versionService
|
|
|
|
.getFrpVersionsByGitHub()
|
|
|
|
.then(data => {
|
|
|
|
req.event.reply(req.channel, success(data));
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this._versionService.getFrpVersionByLocalJson().then(localData => {
|
|
|
|
req.event.reply(req.channel, success(localData));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2025-02-23 02:11:17 +08:00
|
|
|
|
|
|
|
getDownloadedVersions(req: ControllerParam) {
|
|
|
|
this._versionDao.findAll().then(data => {
|
|
|
|
req.event.reply(req.channel, success(data));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadFrpVersion(req: ControllerParam) {
|
|
|
|
this._versionService
|
|
|
|
.downloadFrpVersion(req.args.githubReleaseId, progress => {
|
|
|
|
req.event.reply(
|
|
|
|
req.channel,
|
|
|
|
success({
|
|
|
|
percent: progress.percent,
|
|
|
|
githubReleaseId: req.args.githubReleaseId,
|
|
|
|
completed: progress.percent >= 1
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(r => {
|
|
|
|
console.log(2);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDownloadedVersion(req: ControllerParam) {
|
|
|
|
this._versionService
|
|
|
|
.deleteFrpVersion(req.args.githubReleaseId)
|
|
|
|
.then(() => {
|
|
|
|
req.event.reply(req.channel, success());
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
req.event.reply(req.channel, fail());
|
|
|
|
});
|
|
|
|
}
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default VersionController;
|