feat: allow download small repositories for free

This commit is contained in:
tdurieux
2022-10-04 13:53:01 +02:00
parent f7a994b6dc
commit c90710fb6f
3 changed files with 31 additions and 2 deletions
+4 -1
View File
@@ -214,7 +214,7 @@ router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
}
});
function validateNewRepo(repoUpdate) {
function validateNewRepo(repoUpdate): void {
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
if (
!repoUpdate.repoId.match(validCharacters) ||
@@ -403,6 +403,9 @@ router.post("/", async (req: express.Request, res: express.Response) => {
});
}
}
if (repository.size < config.AUTO_DOWNLOAD_REPO_SIZE) {
repo.source.type = "GitHubDownload";
}
repo.conference = repoUpdate.conference;
await repo.save();
+23 -1
View File
@@ -24,7 +24,22 @@ router.get(
const repo = await getRepo(req, res);
if (!repo) return;
if (repo.source.type != "GitHubDownload") {
let download = false;
const conference = await repo.conference();
if (conference) {
download =
conference.quota.size > -1 &&
!!config.ENABLE_DOWNLOAD &&
repo.source.type == "GitHubDownload";
}
if (
repo.size.storage < config.FREE_DOWNLOAD_REPO_SIZE * 1024 &&
repo.source.type == "GitHubDownload"
) {
download = true;
}
if (!download) {
throw new AnonymousError("download_not_enabled", {
httpStatus: 403,
object: req.params.repoId,
@@ -124,6 +139,13 @@ router.get(
!!config.ENABLE_DOWNLOAD &&
repo.source.type == "GitHubDownload";
}
console.log(repo.size.storage, repo.source.type)
if (
repo.size.storage < config.FREE_DOWNLOAD_REPO_SIZE * 1024 &&
repo.source.type == "GitHubDownload"
) {
download = true;
}
res.header("Cache-Control", "no-cache");
res.json({