mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-26 14:13:38 +01:00
fix: admit replacement sources and account for resolved storage
This commit is contained in:
1 parent
6eb4406575
commit
d7a5243054
10 files changed
+151
-10
No files matched your search
@@ -547,8 +547,11 @@ router.post(
|
||||
repo.model.anonymizeDate = new Date();
|
||||
}
|
||||
|
||||
await assertConferenceAdmission(String(repo.model.owner), repo.repoId, repoUpdate.conference);
|
||||
if (repo.model.billingManaged) await reserveRepository(String(repo.model.owner), repo.repoId, repo.model.size?.storage || 0, repoUpdate.conference);
|
||||
const needsAdmission = sourceChanged || reactivating || repoUpdate.conference !== repo.model.conference;
|
||||
if (needsAdmission) {
|
||||
await assertConferenceAdmission(String(repo.model.owner), repo.repoId, repoUpdate.conference);
|
||||
if (repo.model.billingManaged && !sourceChanged) await reserveRepository(String(repo.model.owner), repo.repoId, repo.model.size?.storage || 0, repoUpdate.conference);
|
||||
}
|
||||
|
||||
if (sourceChanged) {
|
||||
const parsedRepository = gh(repoUpdate.fullName);
|
||||
@@ -591,6 +594,11 @@ router.post(
|
||||
repo.model.source.repositoryName =
|
||||
repository.fullName || repoUpdate.fullName;
|
||||
repo.model.anonymizeDate = new Date();
|
||||
if (repo.model.billingManaged) {
|
||||
const files = await repo.source.getFiles();
|
||||
await reserveRepository(String(repo.model.owner), repo.repoId,
|
||||
files.reduce((sum, file) => sum + (file.size || 0), 0), repoUpdate.conference);
|
||||
}
|
||||
await repo.remove({ accessRevision: previousAccessRevision });
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,15 @@ router.get("/dashboard", async (req, res) => {
|
||||
router.get("/quota", async (req, res) => {
|
||||
try {
|
||||
const user = await getUser(req);
|
||||
const ready = await user.quotaRepositories();
|
||||
let ready = await user.quotaRepositories();
|
||||
const limits = config.BILLING_ENABLED ? await allowance(user.id) : null;
|
||||
if (limits) {
|
||||
const funded = [];
|
||||
for (const repository of ready) {
|
||||
if ((await allowance(user.id, repository.repoId, repository.conference)).scope === limits.scope) funded.push(repository);
|
||||
}
|
||||
ready = funded;
|
||||
}
|
||||
|
||||
let totalStorage = 0;
|
||||
let totalFiles = 0;
|
||||
@@ -127,7 +135,6 @@ router.get("/quota", async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
const limits = config.BILLING_ENABLED ? await allowance(user.id) : null;
|
||||
const reserved = limits ? await BillingQuota.findById(limits.scope).lean() : null;
|
||||
res.json({
|
||||
storage: {
|
||||
|
||||
Reference in new issue
Block a user