added new features 3.0
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Body, Controller, Delete, Get, Param, Post, Query, Req, Res } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Delete, Get, Inject, Param, Post, Query, Req, Res } from '@nestjs/common';
|
||||
import type { Request, Response } from 'express';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { CurrentUser } from '../common/decorators/current-user.decorator';
|
||||
@@ -6,6 +6,8 @@ import { Public } from '../common/decorators/public.decorator';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import type { AuthUser } from '../users/user.types';
|
||||
import { SessionService } from '../auth/session.service';
|
||||
import { extractSessionToken } from '../auth/guards/session.guard';
|
||||
import { APP_CONFIG, type AppConfig } from '../config/config.tokens';
|
||||
import type { AuthenticatedRequest } from '../auth/authenticated-request';
|
||||
import { MarketplaceService } from './marketplace.service';
|
||||
import { ModulesService } from './modules.service';
|
||||
@@ -18,6 +20,7 @@ export class MarketplaceController {
|
||||
private readonly marketplaceService: MarketplaceService,
|
||||
private readonly sessionService: SessionService,
|
||||
private readonly modulesService: ModulesService,
|
||||
@Inject(APP_CONFIG) private readonly config: AppConfig,
|
||||
) {}
|
||||
|
||||
@Get('providers')
|
||||
@@ -46,11 +49,13 @@ export class MarketplaceController {
|
||||
configuration: ModuleRecord['configuration']; configurationReady: boolean;
|
||||
} }> {
|
||||
const branch = await this.marketplaceService.defaultBranch(provider, owner, repository);
|
||||
const archive = await this.marketplaceService.downloadRepositoryArchive(provider, owner, repository, branch);
|
||||
const { archive, commit } = await this.marketplaceService.downloadRepositoryArchive(provider, owner, repository, branch);
|
||||
const manifest = await this.modulesService.validatePackage(archive);
|
||||
const module = await this.modulesService.findByModuleId(manifest.id) ??
|
||||
await this.modulesService.install(archive, actor, request.ip ?? null);
|
||||
await this.marketplaceService.recordInstallation(provider, owner, repository, module.id, branch);
|
||||
if (await this.modulesService.findByModuleId(manifest.id)) {
|
||||
throw new BadRequestException('Ein Modul mit dieser ID ist bereits installiert');
|
||||
}
|
||||
const module = await this.modulesService.install(archive, actor, request.ip ?? null);
|
||||
await this.marketplaceService.recordInstallation(provider, owner, repository, module.id, branch, commit);
|
||||
return {
|
||||
module: {
|
||||
id: module.id,
|
||||
@@ -105,9 +110,14 @@ export class MarketplaceController {
|
||||
actor,
|
||||
request.ip ?? null,
|
||||
report,
|
||||
async () => {
|
||||
report('commit', 'Neue Version wird registriert', 96);
|
||||
await this.marketplaceService.commitInstalledBranch(
|
||||
moduleId, update.provider, update.owner, update.repository, update.branch, update.commit,
|
||||
update.previousBranch, update.previousCommit,
|
||||
);
|
||||
},
|
||||
);
|
||||
report('commit', 'Neue Version wird registriert', 96);
|
||||
await this.marketplaceService.commitInstalledBranch(moduleId, update.provider, update.owner, update.repository, update.branch, update.commit);
|
||||
this.marketplaceService.finishOperation(operationId, actor.id, true);
|
||||
return { module };
|
||||
} catch (error) {
|
||||
@@ -152,7 +162,7 @@ export class MarketplaceController {
|
||||
destination.searchParams.set('reason', 'callback');
|
||||
} else {
|
||||
try {
|
||||
const token = request.cookies?.mpm_session as string | undefined;
|
||||
const token = extractSessionToken(request, this.config.security.cookieSecure);
|
||||
const session = token ? await this.sessionService.findValid(token) : null;
|
||||
if (!session) {
|
||||
destination.searchParams.set('marketplace', 'error');
|
||||
|
||||
Reference in New Issue
Block a user