Added Repository Quota setting

This commit is contained in:
Johannes Erwerle 2026-04-20 19:03:17 +02:00
parent 755e313c61
commit 3a4f5a0394
10 changed files with 102 additions and 2 deletions

View file

@ -3,6 +3,7 @@ from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from django.conf import settings
from pathlib import Path
import msgpack
from .tasks import update_user
@ -28,6 +29,9 @@ class BorgRepository(models.Model):
)
user = models.ForeignKey(User, on_delete=models.CASCADE)
quota = models.IntegerField(default=500)
used_quota = models.IntegerField(default=-1)
class Meta:
constraints = [
models.UniqueConstraint(
@ -95,6 +99,21 @@ class BorgRepository(models.Model):
return output
def refresh_quota(self):
hints_files = self.path.glob("hints.*")
try:
hint = next(hints_files)
data = hint.open(mode="rb").read()
unpacked = msgpack.unpackb(data, strict_map_key=False, raw=True)
quota_used = unpacked[b"storage_quota_use"]
self.used_quota = int(quota_used / 10**9)
except StopIteration:
# No hints file found, therefore the repo is probably not initialized
self.used_quota = -1
class Voucher(models.Model):
used = models.BooleanField(default=False)