mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-16 10:07:20 +02:00
feat: allow download small repositories for free
This commit is contained in:
@@ -9,6 +9,8 @@ interface Config {
|
|||||||
DEFAULT_QUOTA: number;
|
DEFAULT_QUOTA: number;
|
||||||
MAX_FILE_SIZE: number;
|
MAX_FILE_SIZE: number;
|
||||||
MAX_REPO_SIZE: number;
|
MAX_REPO_SIZE: number;
|
||||||
|
AUTO_DOWNLOAD_REPO_SIZE: number;
|
||||||
|
FREE_DOWNLOAD_REPO_SIZE: number;
|
||||||
AUTH_CALLBACK: string;
|
AUTH_CALLBACK: string;
|
||||||
/**
|
/**
|
||||||
* Allow to download repository and files
|
* Allow to download repository and files
|
||||||
@@ -38,6 +40,8 @@ const config: Config = {
|
|||||||
DEFAULT_QUOTA: 2 * 1024 * 1024 * 1024 * 8,
|
DEFAULT_QUOTA: 2 * 1024 * 1024 * 1024 * 8,
|
||||||
MAX_FILE_SIZE: 100 * 1024 * 1024, // in b, 10MB
|
MAX_FILE_SIZE: 100 * 1024 * 1024, // in b, 10MB
|
||||||
MAX_REPO_SIZE: 60000, // in kb, 60MB
|
MAX_REPO_SIZE: 60000, // in kb, 60MB
|
||||||
|
AUTO_DOWNLOAD_REPO_SIZE: 150, // in kb, 150kb
|
||||||
|
FREE_DOWNLOAD_REPO_SIZE: 150, // in kb, 150kb
|
||||||
ENABLE_DOWNLOAD: true,
|
ENABLE_DOWNLOAD: true,
|
||||||
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
||||||
ANONYMIZATION_MASK: "XXXX",
|
ANONYMIZATION_MASK: "XXXX",
|
||||||
|
|||||||
@@ -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\-\_]+$/;
|
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
|
||||||
if (
|
if (
|
||||||
!repoUpdate.repoId.match(validCharacters) ||
|
!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;
|
repo.conference = repoUpdate.conference;
|
||||||
|
|
||||||
await repo.save();
|
await repo.save();
|
||||||
|
|||||||
@@ -24,7 +24,22 @@ router.get(
|
|||||||
const repo = await getRepo(req, res);
|
const repo = await getRepo(req, res);
|
||||||
if (!repo) return;
|
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", {
|
throw new AnonymousError("download_not_enabled", {
|
||||||
httpStatus: 403,
|
httpStatus: 403,
|
||||||
object: req.params.repoId,
|
object: req.params.repoId,
|
||||||
@@ -124,6 +139,13 @@ router.get(
|
|||||||
!!config.ENABLE_DOWNLOAD &&
|
!!config.ENABLE_DOWNLOAD &&
|
||||||
repo.source.type == "GitHubDownload";
|
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.header("Cache-Control", "no-cache");
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
Reference in New Issue
Block a user