-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
735a1fe
commit aeee02d
Showing
5 changed files
with
194 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using TASVideos.Core.Services.ExternalMediaPublisher; | ||
using TASVideos.Core.Services.Wiki; | ||
using TASVideos.Core.Services.Youtube; | ||
using TASVideos.Core.Settings; | ||
using TASVideos.Data; | ||
using TASVideos.Data.Entity; | ||
using TASVideos.MovieParsers; | ||
|
@@ -23,6 +24,8 @@ public class SubmitModel : BasePageModel | |
private readonly IYoutubeSync _youtubeSync; | ||
private readonly IMovieFormatDeprecator _deprecator; | ||
private readonly IQueueService _queueService; | ||
private readonly AppSettings _settings; | ||
private DateTime _earliestTimestamp; | ||
|
||
public SubmitModel( | ||
ApplicationDbContext db, | ||
|
@@ -33,7 +36,8 @@ public SubmitModel( | |
ITASVideoAgent tasVideoAgent, | ||
IYoutubeSync youtubeSync, | ||
IMovieFormatDeprecator deprecator, | ||
IQueueService queueService) | ||
IQueueService queueService, | ||
AppSettings settings) | ||
{ | ||
_db = db; | ||
_publisher = publisher; | ||
|
@@ -44,6 +48,7 @@ public SubmitModel( | |
_youtubeSync = youtubeSync; | ||
_deprecator = deprecator; | ||
_queueService = queueService; | ||
_settings = settings; | ||
} | ||
|
||
[BindProperty] | ||
|
@@ -183,4 +188,26 @@ private async Task ValidateModel() | |
} | ||
} | ||
} | ||
|
||
public string[] Notice(int userId) => new string[] | ||
{ | ||
"We limit submissions to " + | ||
_settings.SubmissionRate.Submissions + | ||
" in " + | ||
_settings.SubmissionRate.Days + | ||
" days per user. ", | ||
"You will be able to submit again on " + | ||
_earliestTimestamp.AddDays(_settings.SubmissionRate.Days) | ||
}; | ||
|
||
public bool SubmissionAllowed(int userId) | ||
{ | ||
_earliestTimestamp = _db.Submissions | ||
.Where(s => s.Submitter != null && s.SubmitterId == userId) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
adelikat
Collaborator
|
||
.OrderByDescending(s => s.CreateTimestamp) | ||
.ToList() | ||
.ElementAt(_settings.SubmissionRate.Submissions - 1) | ||
.CreateTimestamp; | ||
return _earliestTimestamp < DateTime.UtcNow.AddDays(-_settings.SubmissionRate.Days); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This queries all the submissions by the author, most people don't have so many but some people do (like me!)
More efficient is to query all the submissions in the last 24 hours, then do your logic against those results