summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/TimeService.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2024-12-07 10:22:45 -0500
committerHazelnoot <acomputerdog@gmail.com>2024-12-07 10:22:49 -0500
commitffc2737478c6f9efd5de9fbaf526b13164727f87 (patch)
tree416a391cdd024e11ad34dfc7707d28dcbbecce19 /packages/backend/src/core/TimeService.ts
parentmerge: Fix Content-Length resetting for partial content length requests (!796) (diff)
downloadsharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.tar.gz
sharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.tar.bz2
sharkey-ffc2737478c6f9efd5de9fbaf526b13164727f87.zip
implement SkRateLimiterService with Leaky Bucket rate limiting
Diffstat (limited to 'packages/backend/src/core/TimeService.ts')
-rw-r--r--packages/backend/src/core/TimeService.ts27
1 files changed, 27 insertions, 0 deletions
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();
+ }
+}