diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-12-07 10:22:45 -0500 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-12-07 10:22:49 -0500 |
| commit | ffc2737478c6f9efd5de9fbaf526b13164727f87 (patch) | |
| tree | 416a391cdd024e11ad34dfc7707d28dcbbecce19 /packages/backend/src/core | |
| parent | merge: Fix Content-Length resetting for partial content length requests (!796) (diff) | |
| download | sharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.tar.gz sharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.tar.bz2 sharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.zip | |
implement SkRateLimiterService with Leaky Bucket rate limiting
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/CoreModule.ts | 6 | ||||
| -rw-r--r-- | packages/backend/src/core/EnvService.ts | 20 | ||||
| -rw-r--r-- | packages/backend/src/core/TimeService.ts | 27 |
3 files changed, 53 insertions, 0 deletions
diff --git a/packages/backend/src/core/CoreModule.ts b/packages/backend/src/core/CoreModule.ts index c083068392..b18db7f366 100644 --- a/packages/backend/src/core/CoreModule.ts +++ b/packages/backend/src/core/CoreModule.ts @@ -14,6 +14,8 @@ import { AbuseReportNotificationService } from '@/core/AbuseReportNotificationSe import { SystemWebhookService } from '@/core/SystemWebhookService.js'; import { UserSearchService } from '@/core/UserSearchService.js'; import { WebhookTestService } from '@/core/WebhookTestService.js'; +import { TimeService } from '@/core/TimeService.js'; +import { EnvService } from '@/core/EnvService.js'; import { AccountMoveService } from './AccountMoveService.js'; import { AccountUpdateService } from './AccountUpdateService.js'; import { AnnouncementService } from './AnnouncementService.js'; @@ -381,6 +383,8 @@ const $SponsorsService: Provider = { provide: 'SponsorsService', useExisting: Sp ChannelFollowingService, RegistryApiService, ReversiService, + TimeService, + EnvService, ChartLoggerService, FederationChart, @@ -680,6 +684,8 @@ const $SponsorsService: Provider = { provide: 'SponsorsService', useExisting: Sp ChannelFollowingService, RegistryApiService, ReversiService, + TimeService, + EnvService, FederationChart, NotesChart, diff --git a/packages/backend/src/core/EnvService.ts b/packages/backend/src/core/EnvService.ts new file mode 100644 index 0000000000..8cc3b95735 --- /dev/null +++ b/packages/backend/src/core/EnvService.ts @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Injectable } from '@nestjs/common'; + +/** + * Provides access to the process environment variables. + * This exists for testing purposes, so that a test can mock the environment without corrupting state for other tests. + */ +@Injectable() +export class EnvService { + /** + * Passthrough to process.env + */ + public get env() { + return process.env; + } +} diff --git a/packages/backend/src/core/TimeService.ts b/packages/backend/src/core/TimeService.ts new file mode 100644 index 0000000000..59c3d4c12b --- /dev/null +++ b/packages/backend/src/core/TimeService.ts @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Injectable } from '@nestjs/common'; + +/** + * Provides abstractions to access the current time. + * Exists for unit testing purposes, so that tests can "simulate" any given time for consistency. + */ +@Injectable() +export class TimeService { + /** + * Returns Date.now() + */ + public get now() { + return Date.now(); + } + + /** + * Returns a new Date instance. + */ + public get date() { + return new Date(); + } +} |