-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Showing
20 changed files
with
114 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.paw filter=lfs diff=lfs merge=lfs -text | ||
demo-data.zip filter=lfs diff=lfs merge=lfs -text |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Observable } from 'rxjs' | ||
|
||
import { CanActivate, UseGuards, applyDecorators } from '@nestjs/common' | ||
|
||
import { banInDemo } from '~/utils' | ||
|
||
class DemoGuard implements CanActivate { | ||
canActivate(): boolean | Promise<boolean> | Observable<boolean> { | ||
banInDemo() | ||
return true | ||
} | ||
} | ||
export const BanInDemo = applyDecorators(UseGuards(DemoGuard)) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ErrorCodeEnum } from '~/constants/error-code.constant' | ||
|
||
import { BusinessException } from './business.exception' | ||
|
||
export class BanInDemoExcpetion extends BusinessException { | ||
constructor() { | ||
super(ErrorCodeEnum.BanInDemo) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
export enum ErrorCodeEnum { | ||
SlugNotAvailable = 'slug_not_available', | ||
|
||
BanInDemo = 'ban_in_demo', | ||
} | ||
|
||
export const ErrorCode = Object.freeze<Record<ErrorCodeEnum, [string, number]>>( | ||
{ | ||
[ErrorCodeEnum.SlugNotAvailable]: ['slug 不可用', 400], | ||
|
||
[ErrorCodeEnum.BanInDemo]: ['Demo 模式下此操作不可用', 400], | ||
}, | ||
) |
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { resolve } from 'path' | ||
|
||
import { Module } from '@nestjs/common' | ||
import { Cron, CronExpression } from '@nestjs/schedule' | ||
|
||
import { AssetService } from '~/processors/helper/helper.asset.service' | ||
|
||
import { BackupModule } from '../backup/backup.module' | ||
import { BackupService } from '../backup/backup.service' | ||
|
||
@Module({ | ||
imports: [BackupModule], | ||
}) | ||
export class DemoModule { | ||
constructor( | ||
private readonly backupService: BackupService, | ||
private readonly assetService: AssetService, | ||
) { | ||
this.reset() | ||
} | ||
@Cron(CronExpression.EVERY_DAY_AT_1AM) | ||
reset() { | ||
this.backupService.restore( | ||
resolve(this.assetService.embedAssetPath, 'demo-data.zip'), | ||
) | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { isInDemoMode } from '~/app.config' | ||
import { BanInDemoExcpetion } from '~/common/exceptions/ban-in-demo.exception' | ||
|
||
/** | ||
* 检查是否在 demo 模式下,禁用此功能 | ||
*/ | ||
export const banInDemo = () => { | ||
if (isInDemoMode) { | ||
throw new BanInDemoExcpetion() | ||
} | ||
} |
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