feat(core): Support community packages in scaling-mode (#10228)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-08-05 11:52:06 +02:00
committed by GitHub
parent afa43e75f6
commit 88086a41ff
19 changed files with 187 additions and 129 deletions

View File

@@ -1,11 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import config from '@/config';
import {
RESPONSE_ERROR_MESSAGES,
STARTER_TEMPLATE_NAME,
UNKNOWN_FAILURE_REASON,
} from '@/constants';
import { Delete, Get, Middleware, Patch, Post, RestController, GlobalScope } from '@/decorators';
import { Delete, Get, Patch, Post, RestController, GlobalScope } from '@/decorators';
import { NodeRequest } from '@/requests';
import type { InstalledPackages } from '@db/entities/InstalledPackages';
import type { CommunityPackages } from '@/Interfaces';
@@ -40,17 +38,6 @@ export class CommunityPackagesController {
private readonly eventService: EventService,
) {}
// TODO: move this into a new decorator `@IfConfig('executions.mode', 'queue')`
@Middleware()
checkIfCommunityNodesEnabled(req: Request, res: Response, next: NextFunction) {
if (config.getEnv('executions.mode') === 'queue' && req.method !== 'GET')
res.status(400).json({
status: 'error',
message: 'Package management is disabled when running in "queue" mode',
});
else next();
}
@Post('/')
@GlobalScope('communityPackage:install')
async installPackage(req: NodeRequest.Post) {
@@ -99,7 +86,7 @@ export class CommunityPackagesController {
let installedPackage: InstalledPackages;
try {
installedPackage = await this.communityPackagesService.installNpmModule(
installedPackage = await this.communityPackagesService.installPackage(
parsed.packageName,
parsed.version,
);
@@ -207,7 +194,7 @@ export class CommunityPackagesController {
}
try {
await this.communityPackagesService.removeNpmModule(name, installedPackage);
await this.communityPackagesService.removePackage(name, installedPackage);
} catch (error) {
const message = [
`Error removing package "${name}"`,
@@ -252,7 +239,7 @@ export class CommunityPackagesController {
}
try {
const newInstalledPackage = await this.communityPackagesService.updateNpmModule(
const newInstalledPackage = await this.communityPackagesService.updatePackage(
this.communityPackagesService.parseNpmPackageName(name).packageName,
previouslyInstalledPackage,
);