Skip to content

Commit

Permalink
feat: Add app type into main settings in AdminCP
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Dec 18, 2024
1 parent 8f1dc32 commit 848e9f0
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apps/frontend/src/plugins/admin/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
"contact_email": {
"label": "Contact Email",
"desc": "This email address will be applied to the contact form and other contact points on your website."
},
"app_type": {
"label": "App Type"
}
},
"email": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ABSOLUTE_PATHS } from '@/app.module';
import { core_config } from '@/database/schema/config';
import { ConfigHelperService } from '@/helpers/config.service';
import { InternalDatabaseService } from '@/utils/database/internal_database.service';
import { Injectable, InternalServerErrorException } from '@nestjs/common';
Expand Down Expand Up @@ -99,6 +100,7 @@ export class EditMainSettingsAdminService {
site_name,
site_short_name,
contact_email,
app_type,
}: MainSettingsAdminBody): Promise<MainSettingsAdminBody> {
await this.configHelper.updateConfig({
site_name,
Expand All @@ -120,11 +122,16 @@ export class EditMainSettingsAdminService {
site_short_name,
});

await this.databaseService.db.update(core_config).set({
app_type,
});

return {
site_description,
site_name,
site_short_name,
contact_email,
app_type,
};
}
}
2 changes: 2 additions & 0 deletions packages/backend/src/core/middleware/services/show.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { InternalDatabaseService } from '@/utils/database/internal_database.serv
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { AppTypeMainSettingsAdmin } from 'vitnode-shared/admin/settings/main.enum';
import { ManifestWithLang } from 'vitnode-shared/manifest.dto';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';

Expand Down Expand Up @@ -78,6 +79,7 @@ export class ShowMiddlewareService {
const configFromDb = await this.configService.getConfig();

return {
app_type: configFromDb.app_type as AppTypeMainSettingsAdmin,
logos: {
logo_dark: configFromDb.logo_dark,
logo_light: configFromDb.logo_light,
Expand Down
17 changes: 16 additions & 1 deletion packages/backend/src/database/schema/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { relations, sql } from 'drizzle-orm';
import { pgTable } from 'drizzle-orm/pg-core';
import { pgEnum, pgTable } from 'drizzle-orm/pg-core';

import { core_files } from './files';

export const appTypeEnum = pgEnum('app_type', [
'website',
'article',
'book',
'music.album',
'music.playlist',
'music.radio_station',
'music.song',
'profile',
'video.episode',
'video.movie',
'video.tv_show',
]);

export const core_config = pgTable('core_config', t => ({
app_type: appTypeEnum().notNull().default('website'),
restart_server: t.boolean().notNull().default(false),
editor_sticky: t.boolean().notNull().default(true),
site_name: t.varchar({ length: 150 }).notNull().default('VitNode'),
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/database/schema/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const core_groups = pgTable('core_groups', t => ({
color: t.varchar({ length: 19 }),
files_allow_upload: t.boolean().notNull().default(true),
files_total_max_storage: t.integer().notNull().default(500000),
files_max_storage_for_submit: t.integer().notNull().default(10000),
files_max_storage_for_submit: t.integer().notNull().default(5000),
}));
8 changes: 7 additions & 1 deletion packages/frontend/src/components/form/fields/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ export function AutoFormSelect({

const buttonPlaceholder = () => {
const current = values.find(item => item[0] === field.value);
const item = current?.[1];
let item = current?.[1];

if (current) {
return labels?.[current[0]] ?? item;
}
const currentV2 = values.find(item => item[1] === field.value);
if (currentV2) {
item = currentV2[1];

return labels?.[currentV2[0]] ?? item;
}

return item ?? t('select_option');
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { AutoForm } from '@/components/form/auto-form';
import { AutoFormInput } from '@/components/form/fields/input';
import { AutoFormSelect } from '@/components/form/fields/select';
import { AutoFormStringLanguageInput } from '@/components/form/fields/text-language-input';
import { useTranslations } from 'next-intl';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';
Expand Down Expand Up @@ -42,6 +43,11 @@ export const ContentMainSettingsCoreAdmin = (props: ShowMiddlewareObj) => {
label: t('contact_email.label'),
description: t('contact_email.desc'),
},
{
id: 'app_type',
label: t('app_type.label'),
component: AutoFormSelect,
},
]}
formSchema={formSchema}
onSubmit={onSubmit}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { zodLanguageInput } from '@/helpers/zod';
import { useTranslations } from 'next-intl';
import { toast } from 'sonner';
import { AppTypeMainSettingsAdmin } from 'vitnode-shared/admin/settings/main.enum';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';
import { z } from 'zod';

Expand All @@ -16,6 +17,7 @@ export const useSettingsCoreAdmin = (data: ShowMiddlewareObj) => {
.default(data.site_description ?? [])
.optional(),
contact_email: z.string().email().default(data.contact_email),
app_type: z.nativeEnum(AppTypeMainSettingsAdmin).default(data.app_type),
});

const onSubmit = async (values: z.infer<typeof formSchema>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useCreateEditFormGroupsMembersAdmin = ({
files_max_storage_for_submit: z.coerce
.number()
.min(-1)
.default(data?.content.files_max_storage_for_submit ?? 10000),
.default(data?.content.files_max_storage_for_submit ?? 5000),
}),
});

Expand Down
5 changes: 4 additions & 1 deletion packages/frontend/src/views/layout/root-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const generateMetadataRootLayout = async ({
};

try {
const { site_name, site_short_name } = await getMiddlewareData();
const { site_name, site_short_name, languages } = await getMiddlewareData();
const language = languages.find(lang => lang.code === locale);

return {
...metadata,
Expand All @@ -38,6 +39,8 @@ export const generateMetadataRootLayout = async ({
},
openGraph: {
title: site_name,
type: 'website',
locale: language ? language.code : 'en_US',
},
};
} catch (_) {
Expand Down
15 changes: 14 additions & 1 deletion packages/shared/src/admin/settings/main.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsArray, IsEmail, IsOptional, IsString } from 'class-validator';
import {
IsArray,
IsEmail,
IsEnum,
IsOptional,
IsString,
} from 'class-validator';

import { StringLanguage } from '../../string-language.dto';
import { AppTypeMainSettingsAdmin } from './main.enum';

export class MainSettingsAdminBody {
@ApiProperty({
enum: AppTypeMainSettingsAdmin,
})
@IsEnum(AppTypeMainSettingsAdmin)
app_type: AppTypeMainSettingsAdmin;

@ApiProperty()
@IsEmail()
contact_email: string;
Expand Down
13 changes: 13 additions & 0 deletions packages/shared/src/admin/settings/main.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum AppTypeMainSettingsAdmin {
ARTICLE = 'article',
BOOK = 'book',
MUSIC_ALBUM = 'music.album',
MUSIC_PLAYLIST = 'music.playlist',
MUSIC_RADIO_STATION = 'music.radio_station',
MUSIC_SONG = 'music.song',
PROFILE = 'profile',
VIDEO_EPISODE = 'video.episode',
VIDEO_MOVIE = 'video.movie',
VIDEO_TV_SHOW = 'video.tv_show',
WEBSITE = 'website',
}

0 comments on commit 848e9f0

Please sign in to comment.