Skip to content

Commit

Permalink
Add route splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Dec 25, 2022
1 parent 7c9bf1f commit d7b4bc1
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 48 deletions.
9 changes: 6 additions & 3 deletions backend/src/routes/api/info/info.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SupportedImageFileTypes,
} from 'picsur-shared/dist/dto/mimes.dto';
import { TrackingState } from 'picsur-shared/dist/dto/tracking-state.enum';
import { ThrowIfFailed } from 'picsur-shared/dist/types';
import { FallbackIfFailed } from 'picsur-shared/dist/types';
import { HostConfigService } from '../../../config/early/host.config.service';
import { NoPermissions } from '../../../decorators/permissions.decorator';
import { Returns } from '../../../decorators/returns.decorator';
Expand All @@ -29,14 +29,17 @@ export class InfoController {
@Get()
@Returns(InfoResponse)
async getInfo(): Promise<InfoResponse> {
const trackingID = ThrowIfFailed(await this.usageService.getTrackingID());
const trackingID = FallbackIfFailed(
await this.usageService.getTrackingID(),
null,
) ?? undefined;

return {
demo: this.hostConfig.isDemo(),
production: this.hostConfig.isProduction(),
version: this.hostConfig.getVersion(),
tracking: {
id: trackingID ?? undefined,
id: trackingID,
state: TrackingState.Detailed,
},
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "1500kb",
"maximumError": "2mb"
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
Expand Down
28 changes: 14 additions & 14 deletions frontend/src/app/app.routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { PRoutes } from './models/dto/picsur-routes.dto';
import { ErrorsRouteModule } from './routes/errors/errors.module';
import { ImagesRouteModule } from './routes/images/images.module';
import { ProcessingRouteModule } from './routes/processing/processing.module';
import { SettingsRouteModule } from './routes/settings/settings.module';
import { UploadRouteModule } from './routes/upload/upload.module';
import { UserRouteModule } from './routes/user/user.module';
import { ViewRouteModule } from './routes/view/view.module';

const routes: PRoutes = [
{
Expand All @@ -17,31 +10,38 @@ const routes: PRoutes = [
},
{
path: 'upload',
loadChildren: () => UploadRouteModule,
loadChildren: () =>
import('./routes/upload/upload.module').then((m) => m.default),
},
{
path: 'processing',
loadChildren: () => ProcessingRouteModule,
loadChildren: () =>
import('./routes/processing/processing.module').then((m) => m.default),
},
{
path: 'view',
loadChildren: () => ViewRouteModule,
loadChildren: () =>
import('./routes/view/view.module').then((m) => m.default),
},
{
path: 'user',
loadChildren: () => UserRouteModule,
loadChildren: () =>
import('./routes/user/user.module').then((m) => m.default),
},
{
path: 'images',
loadChildren: () => ImagesRouteModule,
loadChildren: () =>
import('./routes/images/images.module').then((m) => m.default),
},
{
path: 'settings',
loadChildren: () => SettingsRouteModule,
loadChildren: () =>
import('./routes/settings/settings.module').then((m) => m.default),
},
{
path: 'error',
loadChildren: () => ErrorsRouteModule,
loadChildren: () =>
import('./routes/errors/errors.module').then((m) => m.default),
},
];

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/routes/errors/errors.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import { ErrorsRoutingModule } from './errors.routing.module';
declarations: [E404Component, E401Component],
imports: [CommonModule, ErrorsRoutingModule],
})
export class ErrorsRouteModule {}
export default class ErrorsRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/images/images.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ import { ImagesRoutingModule } from './images.routing.module';
PipesModule,
],
})
export class ImagesRouteModule {}
export default class ImagesRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/processing/processing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ import { ProcessingRoutingModule } from './processing.routing.module';
MatProgressSpinnerModule,
],
})
export class ProcessingRouteModule {}
export default class ProcessingRouteModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ import { SettingsApiKeysRoutingModule } from './settings-apikeys.routing.module'
FabModule,
],
})
export class SettingsApiKeysRouteModule {}
export default class SettingsApiKeysRouteModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import { SettingsGeneralRoutingModule } from './settings-general.routing.module'
declarations: [SettingsGeneralComponent],
imports: [CommonModule, SettingsGeneralRoutingModule, PrefOptionModule],
})
export class SettingsGeneralRouteModule {}
export default class SettingsGeneralRouteModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ import { SettingsRolesRoutingModule } from './settings-roles.routing.module';
ValuesPickerModule,
],
})
export class SettingsRolesRouteModule {}
export default class SettingsRolesRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/settings/settings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ import { SettingsSidebarComponent } from './sidebar/settings-sidebar.component';
],
exports: [SettingsRoutingModule],
})
export class SettingsRouteModule {}
export default class SettingsRouteModule {}
24 changes: 12 additions & 12 deletions frontend/src/app/routes/settings/settings.routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import { Permission } from 'picsur-shared/dist/dto/permissions.enum';
import { PermissionGuard } from 'src/app/guards/permission.guard';
import { PRoutes } from 'src/app/models/dto/picsur-routes.dto';
import { SidebarResolverService } from 'src/app/services/sidebar-resolver/sidebar-resolver.service';
import { SettingsApiKeysRouteModule } from './apikeys/settings-apikeys.module';
import { SettingsGeneralRouteModule } from './general/settings-general.module';
import { SettingsRolesRouteModule } from './roles/settings-roles.module';
import { SettingsShareXRouteModule } from './sharex/settings-sharex.module';
import { SettingsSidebarComponent } from './sidebar/settings-sidebar.component';
import { SettingsSysprefRouteModule } from './sys-pref/settings-sys-pref.module';
import { SettingsUsersRouteModule } from './users/settings-users.module';

const SettingsRoutes: PRoutes = [
{
Expand All @@ -23,7 +17,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'general',
loadChildren: () => SettingsGeneralRouteModule,
loadChildren: () =>
import('./general/settings-general.module').then((m) => m.default),
data: {
permissions: [Permission.Settings],
page: {
Expand All @@ -35,7 +30,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'apikeys',
loadChildren: () => SettingsApiKeysRouteModule,
loadChildren: () =>
import('./apikeys/settings-apikeys.module').then((m) => m.default),
data: {
permissions: [Permission.ApiKey],
page: {
Expand All @@ -47,7 +43,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'sharex',
loadChildren: () => SettingsShareXRouteModule,
loadChildren: () =>
import('./sharex/settings-sharex.module').then((m) => m.default),
data: {
permissions: [Permission.ApiKey],
page: {
Expand All @@ -59,7 +56,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'users',
loadChildren: () => SettingsUsersRouteModule,
loadChildren: () =>
import('./users/settings-users.module').then((m) => m.default),
data: {
permissions: [Permission.UserAdmin],
page: {
Expand All @@ -71,7 +69,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'roles',
loadChildren: () => SettingsRolesRouteModule,
loadChildren: () =>
import('./roles/settings-roles.module').then((m) => m.default),
data: {
permissions: [Permission.RoleAdmin],
page: {
Expand All @@ -83,7 +82,8 @@ const SettingsRoutes: PRoutes = [
},
{
path: 'system',
loadChildren: () => SettingsSysprefRouteModule,
loadChildren: () =>
import('./sys-pref/settings-sys-pref.module').then((m) => m.default),
data: {
permissions: [Permission.SysPrefAdmin],
page: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import { SettingsShareXRoutingModule } from './settings-sharex.routing.module';
MatProgressSpinnerModule,
],
})
export class SettingsShareXRouteModule {}
export default class SettingsShareXRouteModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import { SettingsSysprefRoutingModule } from './settings-sys-pref.routing.module
declarations: [SettingsSysprefComponent],
imports: [CommonModule, SettingsSysprefRoutingModule, PrefOptionModule],
})
export class SettingsSysprefRouteModule {}
export default class SettingsSysprefRouteModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ import { SettingsUsersRoutingModule } from './settings-users.routing.module';
ValuesPickerModule,
],
})
export class SettingsUsersRouteModule {}
export default class SettingsUsersRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/upload/upload.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ import { UploadRoutingModule } from './upload.routing.module';
NgxDropzoneModule,
],
})
export class UploadRouteModule {}
export default class UploadRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import { UserRoutingModule } from './user.routing.module';
ReactiveFormsModule,
],
})
export class UserRouteModule {}
export default class UserRouteModule {}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/view/view.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ import { ViewRoutingModule } from './view.routing.module';
PipesModule,
],
})
export class ViewRouteModule {}
export default class ViewRouteModule {}
10 changes: 6 additions & 4 deletions frontend/src/app/services/usage/usage.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Inject, Injectable } from '@angular/core';
import { NAVIGATOR } from '@ng-web-apis/common';
import * as ackee from 'ackee-tracker';
import { InfoService } from '../api/info.service';
import { LOCATION, NAVIGATOR, WINDOW } from '@ng-web-apis/common';
import { Logger } from '../logger/logger.service';
import { InfoService } from '../api/info.service';
import type { AckeeInstance } from 'ackee-tracker';

@Injectable({
providedIn: 'root',
Expand All @@ -13,7 +13,7 @@ export class UsageService {
private doNotTrack = false;
private SITE_ID = 'c0fa67c0-fb82-42a7-af7e-ef3df28adeb4';

private instance?: ackee.AckeeInstance;
private instance?: AckeeInstance;

constructor(
@Inject(NAVIGATOR) private readonly navigator: Navigator,
Expand All @@ -32,6 +32,8 @@ export class UsageService {
private async setup() {
if (this.doNotTrack) return;

const ackee = await import('ackee-tracker');

this.instance = ackee.create('/api/usage/report', {
ignoreLocalhost: false,
ignoreOwnVisits: false,
Expand Down
13 changes: 13 additions & 0 deletions shared/src/types/failable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ export function ThrowIfFailed<V>(failable: Failable<V>): V {
return failable;
}

export function FallbackIfFailed<V>(
failable: Failable<V>,
fallback: V,
logger?: { warn: (...args: any) => any },
): V {
if (HasFailed(failable)) {
if (logger) logger.warn(failable.print());
return fallback;
}

return failable;
}

export function Map<T, U>(
failable: Failable<T>,
mapper: (value: T) => U,
Expand Down

0 comments on commit d7b4bc1

Please sign in to comment.