Skip to content

Commit

Permalink
Merge pull request #600 from VitNode/feat/export_plugin
Browse files Browse the repository at this point in the history
feat: Add export plugin
  • Loading branch information
aXenDeveloper authored Dec 9, 2024
2 parents 7275963 + 6a05401 commit 19541d6
Show file tree
Hide file tree
Showing 45 changed files with 632 additions and 87 deletions.
30 changes: 13 additions & 17 deletions apps/frontend/src/plugins/admin/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@
"desc": "We're detected changes in <bold>the plugin system</bold>. To apply these changes, you need to <bold>restart the server</bold>."
},
"dev": {
"overview": {
"title": "Overview"
},
"overview": "Overview",
"nav": {
"title": "Navigation in AdminCP",
"lang_key": "Lang Key: <key></key>",
Expand Down Expand Up @@ -363,6 +361,18 @@
"desc": "If you delete this permission, all children will be deleted too."
}
}
},
"export": {
"title": "Export Plugin",
"desc": "Choose version to export.",
"type": {
"rebuild": "Rebuild current version - {version}",
"new_version": "Create new version"
},
"version": "Version",
"version_code": "Version Code",
"success": "Plugin has been exported.",
"submit": "Export"
}
},
"create": {
Expand Down Expand Up @@ -411,20 +421,6 @@
"submit": "Yes, delete plugin",
"desc": "This action will delete <name></name> plugin created by <author></author> and all data associated with it.",
"info": "After the process is complete, you need to restart the server to apply the changes."
},
"download": {
"title": "Download Plugin",
"type": {
"rebuild": "Rebuild current version - {version}",
"new_version": "Create new version"
},
"version": {
"label": "Version"
},
"version_code": {
"label": "Version Code"
},
"submit": "Download"
}
},
"styles": {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"pg": "^8.13.1",
"rxjs": "^7.8.1",
"sharp": "^0.33.5",
"tar": "^7.4.3",
"ua-parser-js": "^2.0.0",
"vitnode-shared": "workspace:*"
}
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export const ABSOLUTE_PATHS = {
plugin: join(internalPaths.frontend, 'plugins', code),
templates: join(internalPaths.frontend, 'plugins', code, 'templates'),
languages: join(internalPaths.frontend, 'plugins', code, 'langs'),
default_page: join(
internalPaths.frontend,
'plugins',
code,
'templates',
'default-page.tsx',
),
admin_pages_auth: join(
internalPaths.frontend,
'app',
Expand Down Expand Up @@ -76,6 +83,7 @@ export const ABSOLUTE_PATHS = {
'(layout)',
code,
),
pages_root: join(internalPaths.frontend, 'src', 'app', code),
},
}),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { OnlyForDevelopment } from '@/guards/dev.guard';
import { Controllers } from '@/helpers/controller.decorator';
import { Body, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import {
Body,
Delete,
Get,
Param,
Post,
Put,
Query,
UseGuards,
} from '@nestjs/common';
import { ApiCreatedResponse, ApiOkResponse } from '@nestjs/swagger';
import {
CreateLanguagesAdminBody,
Expand Down Expand Up @@ -32,6 +42,7 @@ export class LanguagesAdminController {
description: 'Create language',
})
@Post()
@UseGuards(OnlyForDevelopment)
async createLang(
@Body() body: CreateLanguagesAdminBody,
): Promise<LanguagesAdminObj> {
Expand All @@ -42,6 +53,7 @@ export class LanguagesAdminController {
description: 'Delete language',
})
@Delete(':id')
@UseGuards(OnlyForDevelopment)
async deleteLang(@Param('id') id: string) {
await this.deleteService.delete(+id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ShowNavPluginsAdminService } from './services/show.service';
plugin_code: 'plugins',
isAdmin: true,
route: 'nav',
isDev: true,
})
export class NavPluginsAdminController {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ShowPermissionsAdminPluginsAdminService } from './services/show.service
plugin_code: 'plugins',
isAdmin: true,
route: 'permissions-admin',
isDev: true,
})
export class PermissionsAdminPluginsAdminController {
constructor(
Expand Down
31 changes: 30 additions & 1 deletion packages/backend/src/core/admin/plugins/plugins.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import type { Response } from 'express';

import { OnlyForDevelopment } from '@/guards/dev.guard';
import { Controllers } from '@/helpers/controller.decorator';
import { Body, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import {
Body,
Delete,
Get,
Param,
Post,
Put,
Query,
Res,
UseGuards,
} from '@nestjs/common';
import { ApiCreatedResponse, ApiOkResponse } from '@nestjs/swagger';
import { EditPluginsAdminBody } from 'vitnode-shared/admin/plugin.dto';
import {
CreatePluginsAdminBody,
ExportPluginsAdminBody,
ShowPluginAdmin,
ShowPluginsAdminObj,
ShowPluginsAdminQuery,
Expand All @@ -12,6 +26,7 @@ import {
import { CreatePluginsAdminService } from './services/create.service';
import { DeletePluginsAdminService } from './services/delete.service';
import { EditPluginsAdminService } from './services/edit.service';
import { ExportPluginsAdminService } from './services/export.service';
import { ItemPluginsAdminService } from './services/item.service';
import { ShowPluginsAdminService } from './services/show.service';

Expand All @@ -23,10 +38,12 @@ export class PluginsAdminController {
private readonly deleteService: DeletePluginsAdminService,
private readonly itemService: ItemPluginsAdminService,
private readonly editService: EditPluginsAdminService,
private readonly exportService: ExportPluginsAdminService,
) {}

@ApiCreatedResponse({ description: 'Plugin created', type: ShowPluginAdmin })
@Post()
@UseGuards(OnlyForDevelopment)
async createPlugin(
@Body() body: CreatePluginsAdminBody,
): Promise<ShowPluginAdmin> {
Expand All @@ -35,6 +52,7 @@ export class PluginsAdminController {

@ApiOkResponse({ description: 'Plugin deleted' })
@Delete(':id')
@UseGuards(OnlyForDevelopment)
async deletePlugin(@Param('id') id: string): Promise<void> {
await this.deleteService.delete(+id);
}
Expand All @@ -51,6 +69,17 @@ export class PluginsAdminController {
return await this.editService.edit({ code, body });
}

@ApiOkResponse({ description: 'Plugin exported' })
@Post(':code/export')
@UseGuards(OnlyForDevelopment)
async exportPlugin(
@Param('code') code: string,
@Body() body: ExportPluginsAdminBody,
@Res() res: Response,
): Promise<void> {
await this.exportService.export({ code, body, res });
}

@ApiOkResponse({ type: ShowPluginAdmin, description: 'Plugin details' })
@Get(':code')
async itemPlugin(@Param('code') code: string): Promise<ShowPluginAdmin> {
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/admin/plugins/plugins.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PluginsAdminController } from './plugins.controller';
import { CreatePluginsAdminService } from './services/create.service';
import { DeletePluginsAdminService } from './services/delete.service';
import { EditPluginsAdminService } from './services/edit.service';
import { ExportPluginsAdminService } from './services/export.service';
import { ItemPluginsAdminService } from './services/item.service';
import { ShowPluginsAdminService } from './services/show.service';

Expand All @@ -20,6 +21,7 @@ import { ShowPluginsAdminService } from './services/show.service';
DeletePluginsAdminService,
ItemPluginsAdminService,
EditPluginsAdminService,
ExportPluginsAdminService,
],
controllers: [PluginsAdminController],
imports: [NavPluginsAdminModule, PermissionsAdminPluginsAdminModule],
Expand Down
Loading

0 comments on commit 19541d6

Please sign in to comment.