mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-03 18:48:40 +00:00
Reject photo uploads that were taken in the future
This commit is contained in:
parent
ffae9a5ce6
commit
02fa66be20
2 changed files with 28 additions and 17 deletions
|
@ -57,6 +57,8 @@ public class PhotosController : ControllerBase
|
||||||
|
|
||||||
if (photo.Subjects.Count > 4) return this.BadRequest();
|
if (photo.Subjects.Count > 4) return this.BadRequest();
|
||||||
|
|
||||||
|
if (photo.Timestamp > TimestampHelper.Timestamp) return this.BadRequest();
|
||||||
|
|
||||||
foreach (PhotoSubject subject in photo.Subjects)
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
{
|
{
|
||||||
subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);
|
subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);
|
||||||
|
|
|
@ -25,6 +25,21 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
|
||||||
bool largeHashIsInvalidFile = false;
|
bool largeHashIsInvalidFile = false;
|
||||||
bool tooManyPhotoSubjects = false;
|
bool tooManyPhotoSubjects = false;
|
||||||
bool duplicatePhotoSubjects = 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
|
hashNullOrEmpty = string.IsNullOrEmpty
|
||||||
(photo.LargeHash) ||
|
(photo.LargeHash) ||
|
||||||
|
@ -41,23 +56,6 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
|
||||||
photo.PlanHash,
|
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);
|
List<int> subjectUserIds = new(4);
|
||||||
foreach (PhotoSubject subject in photo.Subjects)
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +67,17 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
|
||||||
subjectUserIds.Add(subject.UserId);
|
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;
|
continue;
|
||||||
|
|
||||||
removePhoto:
|
removePhoto:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue