Skip to content

Commit

Permalink
update packages and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Nov 28, 2023
1 parent 1e9dad9 commit d7241fa
Show file tree
Hide file tree
Showing 30 changed files with 4,524 additions and 4,233 deletions.
74 changes: 37 additions & 37 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,65 +21,65 @@
"purge": "rm -rf dist && rm -rf node_modules"
},
"dependencies": {
"@fastify/helmet": "^10.1.1",
"@fastify/multipart": "^7.6.1",
"@fastify/reply-from": "^9.3.0",
"@fastify/static": "^6.10.2",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^2.3.4",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.1.0",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-fastify": "^10.0.0",
"@nestjs/schedule": "^3.0.0",
"@fastify/helmet": "^11.1.1",
"@fastify/multipart": "^8.0.0",
"@fastify/reply-from": "^9.4.0",
"@fastify/static": "^6.12.0",
"@nestjs/common": "^10.2.10",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.10",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.2",
"@nestjs/platform-fastify": "^10.2.10",
"@nestjs/schedule": "^4.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/throttler": "^4.0.0",
"@nestjs/typeorm": "^9.0.1",
"bcrypt": "^5.1.0",
"@nestjs/throttler": "^5.0.1",
"@nestjs/typeorm": "^10.0.1",
"bcrypt": "^5.1.1",
"bmp-img": "^1.2.1",
"cors": "^2.8.5",
"extensionless": "^1.4.5",
"file-type": "^18.5.0",
"extensionless": "^1.7.3",
"file-type": "^18.7.0",
"is-docker": "^3.0.0",
"ms": "2.1.3",
"node-fetch": "^3.3.1",
"node-fetch": "^3.3.2",
"p-timeout": "^6.1.2",
"passport": "^0.6.0",
"passport": "^0.7.0",
"passport-headerapikey": "^1.2.2",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"passport-strategy": "^1.0.0",
"pg": "^8.11.0",
"pg": "^8.11.3",
"picsur-shared": "*",
"posix.js": "^0.1.1",
"qoi-img": "^2.1.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.1",
"rimraf": "^5.0.5",
"rxjs": "^7.8.1",
"sharp": "^0.32.1",
"sharp": "^0.32.6",
"stream-parser": "^0.3.1",
"thunks": "^4.9.6",
"typeorm": "0.3.16",
"zod": "^3.21.4"
"typeorm": "0.3.17",
"zod": "^3.22.4"
},
"devDependencies": {
"@nestjs/cli": "^10.0.1",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.13",
"@types/multer": "^1.4.7",
"@types/node": "^20.3.1",
"@types/passport-jwt": "^3.0.8",
"@types/passport-local": "^1.0.35",
"@types/passport-strategy": "^0.2.35",
"@nestjs/cli": "^10.2.1",
"@nestjs/schematics": "^10.0.3",
"@nestjs/testing": "^10.2.10",
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/multer": "^1.4.11",
"@types/node": "^20.10.0",
"@types/passport-jwt": "^3.0.13",
"@types/passport-local": "^1.0.38",
"@types/passport-strategy": "^0.2.38",
"@types/sharp": "^0.32.0",
"@types/supertest": "^2.0.12",
"prettier": "^2.8.8",
"@types/supertest": "^2.0.16",
"prettier": "^3.1.0",
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion backend/src/config/late/jwt.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class JwtConfigService implements JwtOptionsFactory {
await this.prefService.getStringPreference('jwt_expires_in'),
);

let milliseconds = ms(expiresIn as any);
let milliseconds = ms(expiresIn as string);
if (isNaN(milliseconds)) {
milliseconds = 1000 * 60 * 60 * 24; // 1 day
}
Expand Down
12 changes: 12 additions & 0 deletions backend/src/decorators/easy-throttle.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Throttle } from '@nestjs/throttler';

export const EasyThrottle = (
limit: number,
ttl?: number,
): MethodDecorator & ClassDecorator =>
Throttle({
default: {
limit,
ttl: ttl ?? 60,
},
});
8 changes: 6 additions & 2 deletions backend/src/layers/PicsurLayers.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import { ZodValidationPipe } from './validate/zod-validator.pipe';
@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 60,
throttlers: [
{
limit: 60,
ttl: 60,
},
],
}),
],
providers: [
Expand Down
2 changes: 1 addition & 1 deletion backend/src/layers/throttler/PicsurThrottler.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FT, Fail } from 'picsur-shared/dist/types/failable';

@Injectable()
export class PicsurThrottlerGuard extends ThrottlerGuard {
protected override throwThrottlingException(): void {
protected override throwThrottlingException(): Promise<void> {
throw Fail(FT.RateLimit);
}
}
2 changes: 1 addition & 1 deletion backend/src/managers/image/image-converter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ImageConverterService {
if (HasFailed(memLimit) || HasFailed(timeLimit)) {
return Fail(FT.Internal, 'Failed to get conversion limits');
}
let timeLimitMS = ms(timeLimit as any);
let timeLimitMS = ms(timeLimit as string);
if (isNaN(timeLimitMS) || timeLimitMS === 0) timeLimitMS = 15 * 1000; // 15 seconds

const sharpWrapper = new SharpWrapper(timeLimitMS, memLimit);
Expand Down
3 changes: 2 additions & 1 deletion backend/src/managers/image/image-manager.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ImageManagerModule implements OnModuleInit {
return;
}

let after_ms = ms(remove_derivatives_after as any);
let after_ms = ms(remove_derivatives_after as string);
if (isNaN(after_ms) || after_ms === 0) {
this.logger.log('remove_derivatives_after is 0, skipping cron');
return;
Expand All @@ -59,6 +59,7 @@ export class ImageManagerModule implements OnModuleInit {
const result = await this.imageFileDB.cleanupDerivatives(after_ms / 1000);
if (HasFailed(result)) {
result.print(this.logger);
return;
}

if (result > 0) this.logger.log(`Cleaned up ${result} derivatives`);
Expand Down
5 changes: 2 additions & 3 deletions backend/src/managers/image/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ export class ImageManagerService {
// Util stuff ==================================================================

private async getFileTypeFromBuffer(image: Buffer): AsyncFailable<FileType> {
const filetypeResult: FileTypeResult | undefined = await fileTypeFromBuffer(
image,
);
const filetypeResult: FileTypeResult | undefined =
await fileTypeFromBuffer(image);

let mime: string | undefined;
if (filetypeResult === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/api/apikeys/apikeys.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import {
ApiKeyCreateResponse,
ApiKeyDeleteRequest,
Expand All @@ -14,6 +13,7 @@ import {
import { Permission } from 'picsur-shared/dist/dto/permissions.enum';
import { ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { ApiKeyDbService } from '../../../collections/apikey-db/apikey-db.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import {
HasPermission,
RequiredPermissions,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class ApiKeysController {

@Post('create')
@Returns(ApiKeyCreateResponse)
@Throttle(10)
@EasyThrottle(10)
async createApiKey(
@ReqUserID() userID: string,
): Promise<ApiKeyCreateResponse> {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/routes/api/pref/sys-pref.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Body, Controller, Get, Logger, Param, Post } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import {
GetPreferenceResponse,
MultiplePreferencesResponse,
Expand All @@ -8,6 +7,7 @@ import {
} from 'picsur-shared/dist/dto/api/pref.dto';
import { ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { SysPreferenceDbService } from '../../../collections/preference-db/sys-preference-db.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import { RequiredPermissions } from '../../../decorators/permissions.decorator';
import { Returns } from '../../../decorators/returns.decorator';
import { Permission } from '../../../models/constants/permissions.const';
Expand All @@ -21,7 +21,7 @@ export class SysPrefController {

@Get()
@Returns(MultiplePreferencesResponse)
@Throttle(20)
@EasyThrottle(20)
async getAllSysPrefs(): Promise<MultiplePreferencesResponse> {
const prefs = ThrowIfFailed(await this.prefService.getAllPreferences());

Expand All @@ -41,7 +41,7 @@ export class SysPrefController {

@Post(':key')
@Returns(UpdatePreferenceResponse)
@Throttle(30)
@EasyThrottle(30)
async setSysPref(
@Param('key') key: string,
@Body() body: UpdatePreferenceRequest,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/routes/api/pref/usr-pref.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Body, Controller, Get, Logger, Param, Post } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import {
GetPreferenceResponse,
MultiplePreferencesResponse,
Expand All @@ -8,6 +7,7 @@ import {
} from 'picsur-shared/dist/dto/api/pref.dto';
import { ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { UsrPreferenceDbService } from '../../../collections/preference-db/usr-preference-db.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import { RequiredPermissions } from '../../../decorators/permissions.decorator';
import { ReqUserID } from '../../../decorators/request-user.decorator';
import { Returns } from '../../../decorators/returns.decorator';
Expand All @@ -22,7 +22,7 @@ export class UsrPrefController {

@Get()
@Returns(MultiplePreferencesResponse)
@Throttle(20)
@EasyThrottle(20)
async getAllUsrPrefs(
@ReqUserID() userid: string,
): Promise<MultiplePreferencesResponse> {
Expand Down Expand Up @@ -51,7 +51,7 @@ export class UsrPrefController {

@Post(':key')
@Returns(UpdatePreferenceResponse)
@Throttle(30)
@EasyThrottle(30)
async setUsrPref(
@Param('key') key: string,
@ReqUserID() userid: string,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/routes/api/roles/roles.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Body, Controller, Get, Logger, Post } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import {
RoleCreateRequest,
RoleCreateResponse,
Expand All @@ -12,9 +11,10 @@ import {
RoleUpdateResponse,
SpecialRolesResponse,
} from 'picsur-shared/dist/dto/api/roles.dto';
import { Fail, FT, ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { FT, Fail, ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { RoleDbService } from '../../../collections/role-db/role-db.service';
import { UserDbService } from '../../../collections/user-db/user-db.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import { RequiredPermissions } from '../../../decorators/permissions.decorator';
import { Returns } from '../../../decorators/returns.decorator';
import { Permission } from '../../../models/constants/permissions.const';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class RolesController {

@Post('update')
@Returns(RoleUpdateResponse)
@Throttle(20)
@EasyThrottle(20)
async updateRole(
@Body() body: RoleUpdateRequest,
): Promise<RoleUpdateResponse> {
Expand All @@ -75,7 +75,7 @@ export class RolesController {

@Post('create')
@Returns(RoleCreateResponse)
@Throttle(10)
@EasyThrottle(10)
async createRole(
@Body() role: RoleCreateRequest,
): Promise<RoleCreateResponse> {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/routes/api/usage/usage.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Controller, Logger, Post, Req, Res } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import type { FastifyReply, FastifyRequest } from 'fastify';
import { Fail, FT, ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { FT, Fail, ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { UsageConfigService } from '../../../config/late/usage.config.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import { NoPermissions } from '../../../decorators/permissions.decorator';
import { ReturnsAnything } from '../../../decorators/returns.decorator';

Expand All @@ -15,7 +15,7 @@ export class UsageController {

@Post(['report', 'report/*'])
@ReturnsAnything()
@Throttle(120)
@EasyThrottle(120)
async deleteRole(
@Req() req: FastifyRequest,
@Res({
Expand Down
6 changes: 3 additions & 3 deletions backend/src/routes/api/user/user-manage.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Body, Controller, Get, Logger, Post } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import {
GetSpecialUsersResponse,
UserCreateRequest,
Expand All @@ -15,6 +14,7 @@ import {
} from 'picsur-shared/dist/dto/api/user-manage.dto';
import { ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { UserDbService } from '../../../collections/user-db/user-db.service';
import { EasyThrottle } from '../../../decorators/easy-throttle.decorator';
import { RequiredPermissions } from '../../../decorators/permissions.decorator';
import { Returns } from '../../../decorators/returns.decorator';
import { Permission } from '../../../models/constants/permissions.const';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class UserAdminController {

@Post('create')
@Returns(UserCreateResponse)
@Throttle(10)
@EasyThrottle(10)
async register(
@Body() create: UserCreateRequest,
): Promise<UserCreateResponse> {
Expand Down Expand Up @@ -80,7 +80,7 @@ export class UserAdminController {

@Post('update')
@Returns(UserUpdateResponse)
@Throttle(20)
@EasyThrottle(20)
async setPermissions(
@Body() body: UserUpdateRequest,
): Promise<UserUpdateResponse> {
Expand Down
Loading

0 comments on commit d7241fa

Please sign in to comment.