♻️ backend: fix e2e editing session test, make ApplicationApiService a singleton (#525)
This commit is contained in:
@@ -14,6 +14,11 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
version = "1";
|
||||
name = "applicationsapi";
|
||||
|
||||
private static default: ApplicationsApiService;
|
||||
public static getDefault() {
|
||||
return this.default;
|
||||
}
|
||||
|
||||
public async doInit(): Promise<this> {
|
||||
const fastify = this.context.getProvider<WebServerAPI>("webserver").getServer();
|
||||
fastify.register((instance, _opts, next) => {
|
||||
@@ -70,10 +75,23 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationsApiService.default = this;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Get the configuration of a given `appId` or `undefined` if unknown */
|
||||
public getApplicationConfig(appId: string) {
|
||||
const apps = config.get<Application[]>("applications.plugins") || [];
|
||||
return apps.find(app => app.id === appId);
|
||||
}
|
||||
|
||||
/** Get the configuration of a given `appId` or throw an error if unknown */
|
||||
public requireApplicationConfig(appId: string) {
|
||||
const app = this.getApplicationConfig(appId);
|
||||
if (!app) throw new Error(`Unknown application.id ${JSON.stringify(appId)}`);
|
||||
return app;
|
||||
}
|
||||
|
||||
/** Send a request to the plugin by its application id
|
||||
* @param url Full URL that doesn't start with a `/`
|
||||
*/
|
||||
@@ -82,9 +100,7 @@ export default class ApplicationsApiService extends TdriveService<undefined> {
|
||||
url: string,
|
||||
appId: string,
|
||||
) {
|
||||
const apps = config.get<Application[]>("applications.plugins") || [];
|
||||
const app = apps.find(app => app.id === appId);
|
||||
if (!app) throw new Error(`Unknown application.id ${JSON.stringify(appId)}`);
|
||||
const app = this.requireApplicationConfig(appId);
|
||||
if (!app.internal_domain)
|
||||
throw new Error(`application.id ${JSON.stringify(appId)} missing an internal_domain`);
|
||||
const signature = jwt.sign(
|
||||
|
||||
@@ -61,6 +61,7 @@ import config from "config";
|
||||
import { MultipartFile } from "@fastify/multipart";
|
||||
import { UploadOptions } from "src/services/files/types";
|
||||
import { SortType } from "src/core/platform/services/search/api";
|
||||
import ApplicationsApiService from "../../applications-api";
|
||||
|
||||
export class DocumentsService {
|
||||
version: "1";
|
||||
@@ -976,9 +977,16 @@ export class DocumentsService {
|
||||
this.logger.error("invalid execution context");
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO: This needs to try in a loop depending on oo-connector response
|
||||
// when there is already a key
|
||||
if (
|
||||
!editorApplicationId ||
|
||||
!ApplicationsApiService.getDefault().getApplicationConfig(editorApplicationId)
|
||||
) {
|
||||
logger.error(`Missing or invalid application ID: ${JSON.stringify(editorApplicationId)}`);
|
||||
CrudException.throwMe(
|
||||
new Error("Unknown appId"),
|
||||
new CrudException("Missing or invalid application ID", 400),
|
||||
);
|
||||
}
|
||||
let newKey: string;
|
||||
try {
|
||||
newKey = EditingSessionKeyFormat.generate(
|
||||
|
||||
Reference in New Issue
Block a user