Uids: change uids to be much shorter and base62 for non-chunks.

This commit is contained in:
Tom Hacohen 2020-03-10 16:40:42 +02:00
parent 3beb7ac4bb
commit d587f8185b
3 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1,29 @@
# Generated by Django 3.0.3 on 2020-03-10 14:38
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0019_collectionmember'),
]
operations = [
migrations.AlterField(
model_name='collection',
name='uid',
field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]{24}')]),
),
migrations.AlterField(
model_name='collectionitem',
name='uid',
field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]{24}')]),
),
migrations.AlterField(
model_name='collectionitemchunk',
name='uid',
field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Expected a 256bit base64url.', regex='^[a-zA-Z0-9\\-_]{43}=?$')]),
),
]

View File

@ -0,0 +1,24 @@
# Generated by Django 3.0.3 on 2020-03-10 14:39
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0020_auto_20200310_1438'),
]
operations = [
migrations.AlterField(
model_name='collection',
name='uid',
field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]')]),
),
migrations.AlterField(
model_name='collectionitem',
name='uid',
field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]')]),
),
]

View File

@ -20,7 +20,8 @@ from django.core.validators import RegexValidator
from django.utils.functional import cached_property from django.utils.functional import cached_property
UidValidator = RegexValidator(regex=r'[a-zA-Z0-9\-_=]{43}', message='Not a valid UID. Expected a 256bit base64url.') Base64Url256BitValidator = RegexValidator(regex=r'^[a-zA-Z0-9\-_]{43}=?$', message='Expected a 256bit base64url.')
UidValidator = RegexValidator(regex=r'[a-zA-Z0-9]', message='Not a valid UID')
class Collection(models.Model): class Collection(models.Model):
@ -61,7 +62,7 @@ def chunk_directory_path(instance, filename):
class CollectionItemChunk(models.Model): class CollectionItemChunk(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False, uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[UidValidator]) max_length=44, validators=[Base64Url256BitValidator])
item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE) item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE)
order = models.CharField(max_length=100, blank=False, null=False) order = models.CharField(max_length=100, blank=False, null=False)
chunkFile = models.FileField(upload_to=chunk_directory_path, max_length=150, unique=True) chunkFile = models.FileField(upload_to=chunk_directory_path, max_length=150, unique=True)