Skip to content

Commit

Permalink
Fix everything needed for correct build
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Aug 28, 2022
1 parent d0dea59 commit 62a4c91
Show file tree
Hide file tree
Showing 53 changed files with 490 additions and 152 deletions.
22 changes: 18 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
node_modules
**/node_modules
dist
**/dist

Dockerfile
docker-compose.yml
support
backend/dist
frontend/dist
shared/dist
**/.angular

.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*

yarn-error.log
temp

.vscode
.git
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ services:

PICSUR_DB_HOST: picsur_postgres
# PICSUR_DB_PORT: 5432
# PICSUR_DB_USER: picsur
# PICSUR_DB_USERNAME: picsur
# PICSUR_DB_PASSWORD: picsur
# PICSUR_DB_NAME: picsur
# PICSUR_DB_DATABASE: picsur

# PICSUR_ADMIN_PASSWORD: picsur

Expand Down
5 changes: 2 additions & 3 deletions backend/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"spec": false
},
"compilerOptions": {
"tsConfigPath": "tsconfig.build.json"
},
"exec": "pog"
"tsConfigPath": "tsconfig.json"
}
}
2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"start:dev": "yarn clean && nest start --watch --exec \"node --es-module-specifier-resolution=node\"",
"start:debug": "nest start --debug --watch --exec \"node --es-module-specifier-resolution=node\"",
"start:prod": "node --es-module-specifier-resolution=node dist/main",
"typeorm": "typeorm-ts-node-esm",
"migrate": "yarn typeorm migration:generate -d ./src/datasource.ts",
"format": "prettier --write \"src/**/*.ts\"",
"clean": "rimraf dist",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
Expand Down
10 changes: 3 additions & 7 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { ServeStaticModule } from '@nestjs/serve-static';
import { TypeOrmModule } from '@nestjs/typeorm';
import cors from 'cors';
import { IncomingMessage, ServerResponse } from 'http';
import { EarlyConfigModule } from './config/early/early-config.module';
import { ServeStaticConfigService } from './config/early/serve-static.config.service';
import { TypeOrmConfigService } from './config/early/type-orm.config.service';
import { DatabaseModule } from './database/database.module';
import { PicsurLoggerModule } from './logger/logger.module';
import { AuthManagerModule } from './managers/auth/auth.module';
import { DemoManagerModule } from './managers/demo/demo.module';
Expand Down Expand Up @@ -37,15 +36,12 @@ const imageCorsOverride = (

@Module({
imports: [
TypeOrmModule.forRootAsync({
useExisting: TypeOrmConfigService,
imports: [EarlyConfigModule],
}),
PicsurLoggerModule,
ServeStaticModule.forRootAsync({
useExisting: ServeStaticConfigService,
imports: [EarlyConfigModule],
}),
PicsurLoggerModule,
DatabaseModule,
AuthManagerModule,
DemoManagerModule,
PicsurRoutesModule,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/collections/image-db/image-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EImageDerivativeBackend } from '../../models/entities/image-derivative.entity';
import { EImageFileBackend } from '../../models/entities/image-file.entity';
import { EImageBackend } from '../../models/entities/image.entity';
import { EImageDerivativeBackend } from '../../database/entities/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/image-file.entity';
import { EImageBackend } from '../../database/entities/image.entity';
import { ImageDBService } from './image-db.service';
import { ImageFileDBService } from './image-file-db.service';

Expand Down
6 changes: 3 additions & 3 deletions backend/src/collections/image-db/image-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { InjectRepository } from '@nestjs/typeorm';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { In, Repository } from 'typeorm';
import { EImageDerivativeBackend } from '../../models/entities/image-derivative.entity';
import { EImageFileBackend } from '../../models/entities/image-file.entity';
import { EImageBackend } from '../../models/entities/image.entity';
import { EImageDerivativeBackend } from '../../database/entities/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/image-file.entity';
import { EImageBackend } from '../../database/entities/image.entity';

@Injectable()
export class ImageDBService {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/collections/image-db/image-file-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { InjectRepository } from '@nestjs/typeorm';
import { ImageEntryVariant } from 'picsur-shared/dist/dto/image-entry-variant.enum';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { LessThan, Repository } from 'typeorm';
import { EImageDerivativeBackend } from '../../models/entities/image-derivative.entity';
import { EImageFileBackend } from '../../models/entities/image-file.entity';
import { EImageDerivativeBackend } from '../../database/entities/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/image-file.entity';

const A_DAY_IN_SECONDS = 24 * 60 * 60;

Expand Down
4 changes: 2 additions & 2 deletions backend/src/collections/preference-db/preference-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EarlyConfigModule } from '../../config/early/early-config.module';
import { ESysPreferenceBackend } from '../../models/entities/sys-preference.entity';
import { EUsrPreferenceBackend } from '../../models/entities/usr-preference.entity';
import { ESysPreferenceBackend } from '../../database/entities/sys-preference.entity';
import { EUsrPreferenceBackend } from '../../database/entities/usr-preference.entity';
import { PreferenceCommonService } from './preference-common.service';
import { PreferenceDefaultsService } from './preference-defaults.service';
import { SysPreferenceService } from './sys-preference-db.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { SysPreference } from 'picsur-shared/dist/dto/sys-preferences.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import { Repository } from 'typeorm';
import {
ESysPreferenceBackend,
ESysPreferenceSchema
} from '../../database/entities/sys-preference.entity';
import {
SysPreferenceList,
SysPreferenceValueTypes
} from '../../models/constants/syspreferences.const';
import {
ESysPreferenceBackend,
ESysPreferenceSchema
} from '../../models/entities/sys-preference.entity';
import { MutexFallBack } from '../../models/util/mutex-fallback';
import { PreferenceCommonService } from './preference-common.service';
import { PreferenceDefaultsService } from './preference-defaults.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { UsrPreference } from 'picsur-shared/dist/dto/usr-preferences.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import { Repository } from 'typeorm';
import {
EUsrPreferenceBackend,
EUsrPreferenceSchema
} from '../../database/entities/usr-preference.entity';
import {
UsrPreferenceList,
UsrPreferenceValueTypes
} from '../../models/constants/usrpreferences.const';
import {
EUsrPreferenceBackend,
EUsrPreferenceSchema
} from '../../models/entities/usr-preference.entity';
import { MutexFallBack } from '../../models/util/mutex-fallback';
import { PreferenceCommonService } from './preference-common.service';
import { PreferenceDefaultsService } from './preference-defaults.service';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/role-db/role-db.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { HasFailed } from 'picsur-shared/dist/types';
import { EarlyConfigModule } from '../../config/early/early-config.module';
import { HostConfigService } from '../../config/early/host.config.service';
import { ERoleBackend } from '../../database/entities/role.entity';
import {
ImmutableRolesList,
SystemRoleDefaults,
SystemRolesList
} from '../../models/constants/roles.const';
import { ERoleBackend } from '../../models/entities/role.entity';
import { RolesService } from './role-db.service';

@Module({
Expand Down
5 changes: 3 additions & 2 deletions backend/src/collections/role-db/role-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
} from 'picsur-shared/dist/types';
import { makeUnique } from 'picsur-shared/dist/util/unique';
import { In, Repository } from 'typeorm';
import { ERoleBackend } from '../../database/entities/role.entity';
import { Permissions } from '../../models/constants/permissions.const';
import {
ImmutableRolesList,
UndeletableRolesList
} from '../../models/constants/roles.const';
import { ERoleBackend } from '../../models/entities/role.entity';

@Injectable()
export class RolesService {
Expand All @@ -24,7 +24,8 @@ export class RolesService {
constructor(
@InjectRepository(ERoleBackend)
private readonly rolesRepository: Repository<ERoleBackend>,
) {}
) {
}

public async create(
name: string,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/user-db/user-db.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HasFailed } from 'picsur-shared/dist/types';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { AuthConfigService } from '../../config/early/auth.config.service';
import { EarlyConfigModule } from '../../config/early/early-config.module';
import { EUserBackend } from '../../models/entities/user.entity';
import { EUserBackend } from '../../database/entities/user.entity';
import { PreferenceModule } from '../preference-db/preference-db.module';
import { RolesModule } from '../role-db/role-db.module';
import { UsersService } from './user-db.service';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/user-db/user-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { makeUnique } from 'picsur-shared/dist/util/unique';
import { Repository } from 'typeorm';
import { EUserBackend } from '../../database/entities/user.entity';
import { Permissions } from '../../models/constants/permissions.const';
import {
DefaultRolesList,
Expand All @@ -22,7 +23,6 @@ import {
LockedLoginUsersList,
UndeletableUsersList
} from '../../models/constants/special-users.const';
import { EUserBackend } from '../../models/entities/user.entity';
import { GetCols } from '../../models/util/collection';
import { SysPreferenceService } from '../preference-db/sys-preference-db.service';
import { RolesService } from '../role-db/role-db.service';
Expand Down
5 changes: 3 additions & 2 deletions backend/src/config/early/auth.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ParseString } from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix } from '../config.static';

@Injectable()
export class AuthConfigService {
constructor(private readonly configService: ConfigService) {}

public getDefaultAdminPassword(): string {
return this.configService.get<string>(
`${EnvPrefix}ADMIN_PASSWORD`,
return ParseString(
this.configService.get(`${EnvPrefix}ADMIN_PASSWORD`),
'admin',
);
}
Expand Down
9 changes: 7 additions & 2 deletions backend/src/config/early/early-jwt.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ParseString } from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix } from '../config.static';

@Injectable()
export class EarlyJwtConfigService {
constructor(private readonly configService: ConfigService) {}

public getJwtSecret(): string | undefined {
return this.configService.get<string>(`${EnvPrefix}JWT_SECRET`);
return (
ParseString(this.configService.get(`${EnvPrefix}JWT_SECRET`)) ?? undefined
);
}

public getJwtExpiresIn(): string | undefined {
return this.configService.get<string>(`${EnvPrefix}JWT_EXPIRY`);
return (
ParseString(this.configService.get(`${EnvPrefix}JWT_EXPIRY`)) ?? undefined
);
}
}
32 changes: 13 additions & 19 deletions backend/src/config/early/host.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
ParseBool,
ParseInt,
ParseString
} from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix } from '../config.static';

@Injectable()
export class HostConfigService {
private readonly logger = new Logger('HostConfigService');

constructor(private readonly configService: ConfigService) {
this.logger.log('Production: ' + this.isProduction());
this.logger.log('Host: ' + this.getHost());
this.logger.log('Port: ' + this.getPort());
this.logger.log('Demo: ' + this.isDemo());
this.logger.log('Demo Interval: ' + this.getDemoInterval() / 1000 + 's');
}

public getHost(): string {
const host = this.configService.get<string>(`${EnvPrefix}HOST`, '0.0.0.0');
return host;
return ParseString(this.configService.get(`${EnvPrefix}HOST`), '0.0.0.0');
}

public getPort(): number {
const port = this.configService.get<number>(`${EnvPrefix}PORT`, 8080);
return port;
return ParseInt(this.configService.get(`${EnvPrefix}PORT`), 8080);
}

public isDemo() {
const enabled = this.configService.get<boolean>(`${EnvPrefix}DEMO`, false);
return enabled;
return ParseBool(this.configService.get(`${EnvPrefix}DEMO`), false);
}

public getDemoInterval() {
const interval = this.configService.get<number>(
`${EnvPrefix}DEMO_INTERVAL`,
return ParseInt(
this.configService.get(`${EnvPrefix}DEMO_INTERVAL`),
1000 * 60 * 5,
);
return interval;
}

public isProduction() {
const enabled = this.configService.get<boolean>(
`${EnvPrefix}PRODUCTION`,
false,
);
return enabled;
return ParseBool(this.configService.get(`${EnvPrefix}PRODUCTION`), false);
}

public getVersion() {
const version = this.configService.get<string>(
`npm_package_version`,
'0.0.0',
);
return version;
return ParseString(this.configService.get(`npm_package_version`), '0.0.0');
}
}
5 changes: 3 additions & 2 deletions backend/src/config/early/multipart.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ParseInt } from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix } from '../config.static';

@Injectable()
Expand All @@ -11,8 +12,8 @@ export class MultipartConfigService {
}

public getMaxFileSize(): number {
return this.configService.get<number>(
`${EnvPrefix}MAX_FILE_SIZE`,
return ParseInt(
this.configService.get(`${EnvPrefix}MAX_FILE_SIZE`),
128000000,
);
}
Expand Down
10 changes: 6 additions & 4 deletions backend/src/config/early/serve-static.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ServeStaticModuleOptionsFactory
} from '@nestjs/serve-static';
import { join } from 'path';
import { ParseString } from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix, PackageRoot } from '../config.static';

@Injectable()
Expand All @@ -20,11 +21,12 @@ export class ServeStaticConfigService
}

public getStaticDirectory(): string {
const directory = this.configService.get<string>(
`${EnvPrefix}STATIC_FRONTEND_ROOT`,
this.defaultLocation,
return ParseString(
this.configService.get(
`${EnvPrefix}STATIC_FRONTEND_ROOT`,
this.defaultLocation,
),
);
return directory;
}

public createLoggerOptions(): ServeStaticModuleOptions[] {
Expand Down
Loading

0 comments on commit 62a4c91

Please sign in to comment.