feat(quota): added support for unlimited quota days (#2797)

This commit is contained in:
Robbin "Roboroads" Schepers
2026-04-04 04:42:46 +02:00
committed by GitHub
parent dc40ca413c
commit 6d8b2b7393
4 changed files with 31 additions and 26 deletions

View File

@@ -296,7 +296,7 @@ export class User {
requestedBy: {
id: this.id,
},
createdAt: AfterDate(movieDate),
...(movieQuotaDays ? { createdAt: AfterDate(movieDate) } : {}),
type: MediaType.MOVIE,
status: Not(MediaRequestStatus.DECLINED),
},
@@ -314,24 +314,28 @@ export class User {
tvDate.setDate(tvDate.getDate() - tvQuotaDays);
}
const tvQuotaStartDate = tvDate.toJSON();
const tvQuotaUsedQuery = requestRepository
.createQueryBuilder('request')
.leftJoin('request.requestedBy', 'requestedBy')
.where('request.type = :requestType', {
requestType: MediaType.TV,
})
.andWhere('requestedBy.id = :userId', {
userId: this.id,
})
.andWhere('request.status != :declinedStatus', {
declinedStatus: MediaRequestStatus.DECLINED,
});
if (tvQuotaDays) {
tvQuotaUsedQuery.andWhere('request.createdAt > :date', {
date: tvQuotaStartDate,
});
}
const tvQuotaUsed = tvQuotaLimit
? (
await requestRepository
.createQueryBuilder('request')
.leftJoin('request.seasons', 'seasons')
.leftJoin('request.requestedBy', 'requestedBy')
.where('request.type = :requestType', {
requestType: MediaType.TV,
})
.andWhere('requestedBy.id = :userId', {
userId: this.id,
})
.andWhere('request.createdAt > :date', {
date: tvQuotaStartDate,
})
.andWhere('request.status != :declinedStatus', {
declinedStatus: MediaRequestStatus.DECLINED,
})
await tvQuotaUsedQuery
.addSelect((subQuery) => {
return subQuery
.select('COUNT(season.id)', 'seasonCount')
@@ -351,10 +355,9 @@ export class User {
remaining: movieQuotaLimit
? Math.max(0, movieQuotaLimit - movieQuotaUsed)
: undefined,
restricted:
restricted: !!(
movieQuotaLimit && movieQuotaLimit - movieQuotaUsed <= 0
? true
: false,
),
},
tv: {
days: tvQuotaDays,
@@ -363,8 +366,7 @@ export class User {
remaining: tvQuotaLimit
? Math.max(0, tvQuotaLimit - tvQuotaUsed)
: undefined,
restricted:
tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0 ? true : false,
restricted: !!(tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0),
},
};
}

View File

@@ -79,6 +79,9 @@ const QuotaSelector = ({
onChange={(e) => setQuotaDays(Number(e.target.value))}
disabled={isDisabled}
>
<option value="0">
{intl.formatMessage(messages.unlimited)}
</option>
{[...Array(100)].map((_item, i) => (
<option value={i + 1} key={`${mediaType}-days-${i + 1}`}>
{i + 1}

View File

@@ -12,9 +12,9 @@ const messages = defineMessages('components.RequestModal.QuotaDisplay', {
movielimit: '{limit, plural, one {movie} other {movies}}',
seasonlimit: '{limit, plural, one {season} other {seasons}}',
allowedRequests:
'You are allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.',
'You are allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.',
allowedRequestsUser:
'This user is allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.',
'This user is allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.',
quotaLink:
'You can view a summary of your request limits on your <ProfileLink>profile page</ProfileLink>.',
quotaLinkUser:

View File

@@ -534,8 +534,8 @@
"components.RequestModal.AdvancedRequester.rootfolder": "Root Folder",
"components.RequestModal.AdvancedRequester.selecttags": "Select tags",
"components.RequestModal.AdvancedRequester.tags": "Tags",
"components.RequestModal.QuotaDisplay.allowedRequests": "You are allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.",
"components.RequestModal.QuotaDisplay.allowedRequestsUser": "This user is allowed to request <strong>{limit}</strong> {type} every <strong>{days}</strong> days.",
"components.RequestModal.QuotaDisplay.allowedRequests": "You are allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.",
"components.RequestModal.QuotaDisplay.allowedRequestsUser": "This user is allowed to request <strong>{limit}</strong> {type}{days, plural, =0 {} one { every day} other { every <strong>{days}</strong> days}}.",
"components.RequestModal.QuotaDisplay.movie": "movie",
"components.RequestModal.QuotaDisplay.movielimit": "{limit, plural, one {movie} other {movies}}",
"components.RequestModal.QuotaDisplay.notenoughseasonrequests": "Not enough season requests remaining",