From 39447d88752fe91b08ac99bb1db30bc201c1eb36 Mon Sep 17 00:00:00 2001 From: maslow Date: Sun, 19 Mar 2023 18:03:04 +0800 Subject: [PATCH] feat(server): add limit to update app state depends on subscription state Signed-off-by: maslow --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + .github/ISSUE_TEMPLATE/feature_request.yml | 21 ++++++++++--------- .github/ISSUE_TEMPLATE/question.yml | 21 ++++++++++--------- .../src/application/application.controller.ts | 9 ++++++++ .../subscription/subscription.controller.ts | 3 ++- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 8153128144..8f2e9fdb0e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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: diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 961b6dcd04..01c20d0ca2 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -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: diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml index 4bf029eb7e..4179495eb8 100644 --- a/.github/ISSUE_TEMPLATE/question.yml +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -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: diff --git a/server/src/application/application.controller.ts b/server/src/application/application.controller.ts index 7124b0e9a5..683d9dc91e 100644 --- a/server/src/application/application.controller.ts +++ b/server/src/application/application.controller.ts @@ -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') @@ -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) { diff --git a/server/src/subscription/subscription.controller.ts b/server/src/subscription/subscription.controller.ts index fdc00d7b2a..bad1cec280 100644 --- a/server/src/subscription/subscription.controller.ts +++ b/server/src/subscription/subscription.controller.ts @@ -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}`, ) }