Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(frontend)!: Remove themes folder #384

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
RUN npm i -g turbo@~2.0.3
RUN npm i -g turbo@~2.0.4
COPY . .
RUN turbo telemetry disable
RUN turbo prune backend --docker
Expand Down
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@react-email/render": "^0.0.15",
"bcrypt": "^5.1.1",
"express": "^4.19.2",
"graphql": "^16.8.1",
"graphql": "^16.8.2",
"nodemailer": "^6.9.13",
"react": "^18.3.1",
"reflect-metadata": "^0.2.2",
Expand All @@ -50,7 +50,7 @@
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.5.28",
"@swc/core": "^1.6.1",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.7",
"@types/express": "^4.17.21",
Expand Down
47 changes: 0 additions & 47 deletions backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ type Mutation {
admin__core_staff_moderators__create(group_id: Int, unrestricted: Boolean!, user_id: Int): ShowAdminStaffModerators!
admin__core_staff_moderators__delete(id: Int!): String!
admin__core_theme_editor__edit(colors: ColorsEditAdminThemeEditor!): String!
admin__core_themes__create(author: String!, author_url: String, name: String!, support_url: String!): ShowAdminThemes!
admin__core_themes__delete(id: Int!): String!
admin__core_themes__download(id: Int!, version: String, version_code: Int): String!
admin__core_themes__edit(author: String!, author_url: String, id: Int!, name: String!, support_url: String!): ShowAdminThemes!
admin__core_themes__upload(file: Upload!, id: Int): ShowAdminThemes!
admin__install__create_database: String!
admin_sessions__sign_out: String!
core_editor_files__delete(id: Int!, security_key: String): String!
Expand All @@ -209,7 +204,6 @@ type Mutation {
core_members__sign_up(email: String!, name: String!, newsletter: Boolean, password: String!): SignUpCoreMembersObj!
core_sessions__sign_in(admin: Boolean, email: String!, password: String!, remember: Boolean): String!
core_sessions__sign_out: String!
core_themes__change(id: Int!): String!
}

type NavAdminPluginsAuthorization {
Expand Down Expand Up @@ -246,7 +240,6 @@ type Query {
admin__core_plugins__show(code: String, cursor: Int, first: Int, last: Int, search: String, sortBy: ShowAdminPluginsSortByArgs): ShowAdminPluginsObj!
admin__core_staff_administrators__show(cursor: Int, first: Int, last: Int, sortBy: ShowAdminStaffAdministratorsSortByArgs): ShowAdminStaffAdministratorsObj!
admin__core_staff_moderators__show(cursor: Int, first: Int, last: Int, sortBy: ShowAdminStaffModeratorsSortByArgs): ShowAdminStaffModeratorsObj!
admin__core_themes__show(cursor: Int, first: Int, last: Int, sortBy: ShowAdminThemesSortByArgs): ShowAdminThemesObj!
admin__install__layout: LayoutAdminInstallObj!
admin__sessions__authorization: AuthorizationAdminSessionsObj!
blog_categories__show(cursor: Int, first: Int, last: Int): ShowBlogCategoriesObj!
Expand All @@ -260,7 +253,6 @@ type Query {
core_sessions__devices__show: [ShowCoreSessionDevicesObj!]!
core_settings__show: ShowSettingsObj!
core_theme_editor__show: ShowCoreThemeEditorObj!
core_themes__show(cursor: Int, first: Int, last: Int): ShowCoreThemesObj!
}

type ShowAdminEmailSettingsServiceObj {
Expand Down Expand Up @@ -454,33 +446,6 @@ enum ShowAdminStaffModeratorsSortingColumnEnum {
updated
}

type ShowAdminThemes {
author: String!
author_url: String
created: DateTime!
default: Boolean!
id: Int!
name: String!
protected: Boolean!
support_url: String!
version: String
version_code: Int
}

type ShowAdminThemesObj {
edges: [ShowAdminThemes!]!
pageInfo: PageInfo!
}

input ShowAdminThemesSortByArgs {
column: ShowAdminThemesSortingColumnEnum!
direction: SortDirectionEnum!
}

enum ShowAdminThemesSortingColumnEnum {
created
}

type ShowBlogCategories {
color: String!
description: [TextLanguage!]
Expand Down Expand Up @@ -638,23 +603,11 @@ type ShowCoreThemeEditorObj {
colors: ColorsShowCoreThemeEditor!
}

type ShowCoreThemes {
default: Boolean!
id: Int!
name: String!
}

type ShowCoreThemesObj {
edges: [ShowCoreThemes!]!
pageInfo: PageInfo!
}

type ShowSettingsObj {
site_copyright: [TextLanguage!]!
site_description: [TextLanguage!]!
site_name: String!
site_short_name: String!
theme_id: Float
}

type SignUpCoreMembersObj {
Expand Down
27 changes: 5 additions & 22 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export const configForAppModule = () => {
known_device: {
name: "vitnode-device",
expiresIn: 365 // 1 year
},
theme_id: {
name: "vitnode-theme-id",
expiresIn: 365 // 1 year
}
}
};
Expand All @@ -61,17 +57,7 @@ export const ABSOLUTE_PATHS = {
temp: join(internalPaths.uploads, "temp")
},
frontend: {
init: internalPaths.frontend,
themes: join(internalPaths.frontend, "themes"),
theme: ({ theme_id }: { theme_id: number }) => ({
root: join(internalPaths.frontend, "themes", theme_id.toString()),
config: join(
internalPaths.frontend,
"themes",
theme_id.toString(),
"config.json"
)
})
init: internalPaths.frontend
},
backend: join(process.cwd(), "src"),
plugins: internalPaths.plugins,
Expand Down Expand Up @@ -119,17 +105,15 @@ export const ABSOLUTE_PATHS = {
),
default_page: join(
internalPaths.frontend,
"themes",
"1",
"plugins",
code,
"templates",
"default-page.tsx"
),
pages: join(internalPaths.frontend, "app", "[locale]", "(main)", code),
templates: join(internalPaths.frontend, "themes", "1", code),
templates: join(internalPaths.frontend, "plugins", code, "templates"),
plugin: join(internalPaths.frontend, "plugins", code),
language: join(internalPaths.frontend, "plugins", code, "langs"),
theme: ({ theme_id }: { theme_id: number }) =>
join(internalPaths.frontend, "themes", theme_id.toString(), code)
language: join(internalPaths.frontend, "plugins", code, "langs")
}
})
};
Expand All @@ -149,7 +133,6 @@ export interface ConfigType {
rebuild_required: {
langs: boolean;
plugins: boolean;
themes: boolean;
};
settings: {
email: {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/functions/rebuild-required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConfigType, configPath, getConfigFile } from "@/config";
export const setRebuildRequired = async ({
set
}: {
set: "langs" | "plugins" | "themes";
set: "langs" | "plugins";
}) => {
const config = getConfigFile();

Expand Down
2 changes: 0 additions & 2 deletions backend/src/plugins/core/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "./sessions/sessions.module";
import { AdminSettingsModule } from "./settings/settings.module";
import { AdminPluginsModule } from "./plugins/plugins.module";
import { AdminThemesModule } from "./themes/themes.module";
import { AdminMetadataModule } from "./metadata/metadata.module";
import { AdminFilesModule } from "./files/files.module";
import { AdminGroupsModule } from "./groups/groups.module";
Expand All @@ -25,7 +24,6 @@ import { AdminEmailModule } from "./email/email.module";
AdminSessionsModule,
AdminSettingsModule,
AdminPluginsModule,
AdminThemesModule,
AdminMetadataModule,
AdminFilesModule,
AdminGroupsModule,
Expand Down
2 changes: 0 additions & 2 deletions backend/src/plugins/core/admin/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as files from "./schema/files";
import * as admins from "./schema/admins";
import * as moderators from "./schema/moderators";
import * as plugins from "./schema/plugins";
import * as themes from "./schema/themes";
import * as nav from "./schema/nav";

export default {
Expand All @@ -18,6 +17,5 @@ export default {
...admins,
...moderators,
...plugins,
...themes,
...nav
};
22 changes: 0 additions & 22 deletions backend/src/plugins/core/admin/database/schema/themes.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as fs from "fs";

import { Injectable } from "@nestjs/common";
import { count } from "drizzle-orm";
import { CustomError } from "@vitnode/backend";
Expand All @@ -11,10 +9,8 @@ import {
} from "@/plugins/core/admin/database/schema/groups";
import { core_admin_permissions } from "@/plugins/core/admin/database/schema/admins";
import { core_moderators_permissions } from "../../database/schema/moderators";
import { core_themes } from "../../database/schema/themes";
import { core_nav, core_nav_name } from "../../database/schema/nav";
import { DatabaseService } from "@/database/database.service";
import { ABSOLUTE_PATHS } from "@/config";

@Injectable()
export class CreateDatabaseAdminInstallService {
Expand Down Expand Up @@ -58,26 +54,6 @@ export class CreateDatabaseAdminInstallService {
}
]);

// Create plugins
const coreVersions: Record<number, string> = JSON.parse(
fs.readFileSync(ABSOLUTE_PATHS.plugin({ code: "core" }).versions, "utf8")
);

const coreVersionCode = +Object.keys(coreVersions).sort().reverse()[0];
const coreVersion: string = coreVersions[coreVersionCode];

// Create default theme
await this.databaseService.db.insert(core_themes).values({
name: "Default Theme",
version: coreVersion,
version_code: coreVersionCode,
author: "VitNode",
author_url: "https://vitnode.com/",
support_url: "https://github.com/aXenDeveloper/vitnode/issues",
protected: true,
default: true
});

// Create default groups
const groupCount = await this.databaseService.db
.select({
Expand Down
14 changes: 0 additions & 14 deletions backend/src/plugins/core/admin/plugins/delete/delete.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ export class DeleteAdminPluginsService {
);
});

// Frontend - Delete Templates
const themes = await this.databaseService.db.query.core_themes.findMany({
columns: {
id: true
}
});
themes.forEach(({ id }) => {
this.deleteFolderWhenExists(
ABSOLUTE_PATHS.plugin({ code }).frontend.theme({
theme_id: id
})
);
});

await this.databaseService.db
.delete(core_plugins)
.where(eq(core_plugins.code, code));
Expand Down
28 changes: 2 additions & 26 deletions backend/src/plugins/core/admin/plugins/upload/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import { ConfigPlugin } from "../plugins.module";

import { core_plugins } from "../../database/schema/plugins";
import { DatabaseService } from "@/database/database.service";
import { ChangeTemplatesAdminThemesService } from "../../themes/change_templates.service";
import { ABSOLUTE_PATHS } from "@/config";
import { migrate } from "@/utils/actions/migrate";

@Injectable()
export class UploadAdminPluginsService extends ChangeTemplatesAdminThemesService {
export class UploadAdminPluginsService {
protected path: string = join(process.cwd());
protected tempPath: string = join(
ABSOLUTE_PATHS.uploads.temp,
Expand All @@ -30,9 +29,7 @@ export class UploadAdminPluginsService extends ChangeTemplatesAdminThemesService
constructor(
private readonly databaseService: DatabaseService,
private readonly changeFilesService: ChangeFilesAdminPluginsService
) {
super();
}
) {}

protected async removeTempFolder(): Promise<void> {
// Delete temp folder
Expand Down Expand Up @@ -172,27 +169,6 @@ export class UploadAdminPluginsService extends ChangeTemplatesAdminThemesService
})
);

// Copy templates
const themes = await this.databaseService.db.query.core_themes.findMany({
columns: {
id: true
}
});
if (fs.existsSync(join(this.tempPath, "frontend", "templates"))) {
await Promise.all(
themes.map(async ({ id }) => {
await this.changeTemplates({
tempPath: join(this.tempPath, "frontend", "templates"),
destinationPath: ABSOLUTE_PATHS.plugin({
code: config.code
}).frontend.theme({
theme_id: id
})
});
})
);
}

// Copy language
const languages =
await this.databaseService.db.query.core_languages.findMany({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Args, Context, Mutation, Resolver } from "@nestjs/graphql";
import { Args, Mutation, Resolver } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { Ctx } from "@vitnode/backend";

import { EditAdminThemeEditorService } from "./edit.service";
import { EditAdminThemeEditorArgs } from "./dto/edit.args";
Expand All @@ -14,9 +13,8 @@ export class EditAdminThemeEditorResolver {
@Mutation(() => String)
@UseGuards(AdminAuthGuards)
async admin__core_theme_editor__edit(
@Context() ctx: Ctx,
@Args() args: EditAdminThemeEditorArgs
): Promise<string> {
return this.service.edit(ctx, args);
return this.service.edit(args);
}
}
Loading
Loading