Skip to content

Commit

Permalink
feat(server): add limit to update app state depends on subscription s…
Browse files Browse the repository at this point in the history
…tate

Signed-off-by: maslow <wangfugen@126.com>
  • Loading branch information
maslow committed Mar 19, 2023
1 parent 2c84173 commit 39447d8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ body:
- [Google Translate](https://translate.google.com/)
- [Baidu Translate](https://fanyi.baidu.com/)
- [YouDao Translate](https://fanyi.baidu.com/)
- ChatGPT
- type: checkboxes
attributes:
Expand Down
21 changes: 11 additions & 10 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ title: "[Feature] Feature title "
description: I want to suggest a feature for this project.
labels: [ "feature" ]
body:
# - type: markdown
# attributes:
# value: |
# For better global communication, Please write in English.
# (为了更好的国际化交流,请您使用英语描述您的问题。)
- type: markdown
attributes:
value: |
For better global communication, Please write in English.
(为了更好的国际化交流,请您使用英语描述您的问题。)
# You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation:
# (你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:)
# - [Google Translate](https://translate.google.com/)
# - [Baidu Translate](https://fanyi.baidu.com/)
# - [YouDao Translate](https://fanyi.baidu.com/)
You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation:
(你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:)
- [Google Translate](https://translate.google.com/)
- [Baidu Translate](https://fanyi.baidu.com/)
- [YouDao Translate](https://fanyi.baidu.com/)
- ChatGPT
- type: checkboxes
attributes:
Expand Down
21 changes: 11 additions & 10 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ title: "[Question] Question title "
description: I have a question that isn't answered in docs or issue.
labels: [ "question" ]
body:
# - type: markdown
# attributes:
# value: |
# For better global communication, Please write in English.
# (为了更好的国际化交流,请您使用英语描述您的问题。)
- type: markdown
attributes:
value: |
For better global communication, Please write in English.
(为了更好的国际化交流,请您使用英语描述您的问题。)
# You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation:
# (你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:)
# - [Google Translate](https://translate.google.com/)
# - [Baidu Translate](https://fanyi.baidu.com/)
# - [YouDao Translate](https://fanyi.baidu.com/)
You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation:
(你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:)
- [Google Translate](https://translate.google.com/)
- [Baidu Translate](https://fanyi.baidu.com/)
- [YouDao Translate](https://fanyi.baidu.com/)
- ChatGPT
- type: checkboxes
attributes:
Expand Down
9 changes: 9 additions & 0 deletions server/src/application/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ApplicationService } from './application.service'
import { FunctionService } from '../function/function.service'
import { StorageService } from 'src/storage/storage.service'
import { RegionService } from 'src/region/region.service'
import { SubscriptionPhase } from '@prisma/client'

@ApiTags('Application')
@Controller('applications')
Expand Down Expand Up @@ -130,6 +131,14 @@ export class ApplicationController {
return ResponseUtil.error(error)
}

// check if the corresponding subscription status has expired
const app = await this.appService.findOne(appid, {
subscription: true,
})
if (app.subscription.phase !== SubscriptionPhase.Valid) {
return ResponseUtil.error('subscription has expired, you can not update')
}

// update app
const res = await this.appService.update(appid, dto)
if (res === null) {
Expand Down
3 changes: 2 additions & 1 deletion server/src/subscription/subscription.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ export class SubscriptionController {
const MAX_RENEWAL_AT = Date.now() + bundle.maxRenewalTime * 1000
const newExpiredAt = subscription.expiredAt.getTime() + duration * 1000
if (newExpiredAt > MAX_RENEWAL_AT) {
const dateStr = new Date(MAX_RENEWAL_AT).toLocaleString()
return ResponseUtil.error(
`max renewal time is ${MAX_RENEWAL_AT} for bundle ${bundle.name}`,
`max renewal time is ${dateStr} for bundle ${bundle.name}`,
)
}

Expand Down

0 comments on commit 39447d8

Please sign in to comment.