mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-20 16:34:44 +02:00
feat: allow download small repositories for free
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user