Reject photo uploads that were taken in the future

This commit is contained in:
jvyden 2022-04-03 17:31:50 -04:00
commit 02fa66be20
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 28 additions and 17 deletions

View file

@ -57,6 +57,8 @@ public class PhotosController : ControllerBase
if (photo.Subjects.Count > 4) return this.BadRequest();
if (photo.Timestamp > TimestampHelper.Timestamp) return this.BadRequest();
foreach (PhotoSubject subject in photo.Subjects)
{
subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);

View file

@ -25,6 +25,21 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
bool largeHashIsInvalidFile = false;
bool tooManyPhotoSubjects = false;
bool duplicatePhotoSubjects = false;
bool takenInTheFuture = true;
// Checks should generally be ordered in least computationally expensive to most.
if (photo.Subjects.Count > 4)
{
tooManyPhotoSubjects = true;
goto removePhoto;
}
if (photo.Timestamp > TimestampHelper.Timestamp)
{
takenInTheFuture = true;
goto removePhoto;
}
hashNullOrEmpty = string.IsNullOrEmpty
(photo.LargeHash) ||
@ -41,23 +56,6 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
photo.PlanHash,
};
noHashesExist = FileHelper.ResourcesNotUploaded(hashes.ToArray()).Length != 0;
if (noHashesExist) goto removePhoto;
LbpFile? file = LbpFile.FromHash(photo.LargeHash);
// Console.WriteLine(file.FileType, );
if (file == null || file.FileType != LbpFileType.Jpeg && file.FileType != LbpFileType.Png)
{
largeHashIsInvalidFile = true;
goto removePhoto;
}
if (photo.Subjects.Count > 4)
{
tooManyPhotoSubjects = true;
goto removePhoto;
}
List<int> subjectUserIds = new(4);
foreach (PhotoSubject subject in photo.Subjects)
{
@ -69,6 +67,17 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
subjectUserIds.Add(subject.UserId);
}
LbpFile? file = LbpFile.FromHash(photo.LargeHash);
// Console.WriteLine(file.FileType, );
if (file == null || file.FileType != LbpFileType.Jpeg && file.FileType != LbpFileType.Png)
{
largeHashIsInvalidFile = true;
goto removePhoto;
}
noHashesExist = FileHelper.ResourcesNotUploaded(hashes.ToArray()).Length != 0;
if (noHashesExist) goto removePhoto;
continue;
removePhoto: