Skip to content
Snippets Groups Projects
Commit 9083a7a8 authored by Xavier Jouslin de Noray's avatar Xavier Jouslin de Noray
Browse files

Version Request Broken: give the version for one plugin

Gitlab: #13
Change-Id: I32fcf48eada33c3049d79cb50abca20bd0c6e97f
parent f3604f05
No related branches found
No related tags found
No related merge requests found
...@@ -303,8 +303,12 @@ export class PluginsController { ...@@ -303,8 +303,12 @@ export class PluginsController {
.status(isUploadable ? StatusCodes.OK : StatusCodes.FORBIDDEN) .status(isUploadable ? StatusCodes.OK : StatusCodes.FORBIDDEN)
.send() .send()
) )
.catch(() => res.status(StatusCodes.INTERNAL_SERVER_ERROR).send()); .catch(e => {
console.log(e);
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
});
} catch (e) { } catch (e) {
console.log(e);
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send(); res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
} }
}); });
...@@ -407,16 +411,19 @@ export class PluginsController { ...@@ -407,16 +411,19 @@ export class PluginsController {
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
this.router.get('/versions/:id', async (req: Request, res: Response) => { this.router.get('/versions/:id', async (req: Request, res: Response) => {
try { try {
if (req.query.arch === undefined) { if (req.query.arch === undefined || req.params.id === undefined) {
res.status(StatusCodes.BAD_REQUEST).send(); res.status(StatusCodes.BAD_REQUEST).send();
return; return;
} }
const versions = await this.pluginsManager.getVersions(); const version = await this.pluginsManager.getVersion(
req.params.id,
req.query.arch as string
);
res res
.status( .status(
versions.length === 0 ? StatusCodes.NOT_FOUND : StatusCodes.OK version === undefined ? StatusCodes.NOT_FOUND : StatusCodes.OK
) )
.send(versions === undefined ? undefined : versions); .send(version === undefined ? undefined : [{version}]);
return; return;
} catch (e) { } catch (e) {
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send(); res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
......
...@@ -275,22 +275,29 @@ export class PluginsManager { ...@@ -275,22 +275,29 @@ export class PluginsManager {
); );
} }
async getVersions(): Promise<Array<{id: string; version: string}>> { async getVersion(id: string, arch: string): Promise<string | undefined> {
const plugin = await this.findPlugin(id, arch);
return plugin === undefined ? undefined : plugin.version;
}
async getVersions(
arch: string
): Promise<Array<{id: string; version: string}>> {
if (this.plugins.length === 0) { if (this.plugins.length === 0) {
await this.setPlugins(); await this.setPlugins();
} }
const versions: Array<{id: string; version: string}> = []; return this.plugins
for (const plugin of this.plugins) { .filter(
const version = plugin.version; (plugins: Plugins) =>
if (version !== undefined) { plugins.arches.includes(arch) && plugins.version !== undefined
versions.push({ )
.map((plugin: Plugins) => {
return {
id: plugin.id, id: plugin.id,
version, version: plugin.version,
};
}); });
} }
}
return versions;
}
private async setPlugins(): Promise<void> { private async setPlugins(): Promise<void> {
let dataDirectory = process.env.DATA_DIRECTORY; let dataDirectory = process.env.DATA_DIRECTORY;
......
...@@ -318,7 +318,7 @@ describe('Plugins manager service tests', function () { ...@@ -318,7 +318,7 @@ describe('Plugins manager service tests', function () {
{ id: 'plugin3', version: '3.0.0' }, { id: 'plugin3', version: '3.0.0' },
]; ];
const actualVersions = await pluginsManagerService.getVersions(); const actualVersions = await pluginsManagerService.getVersions('x64');
expect(actualVersions).toEqual(expectedVersions); expect(actualVersions).toEqual(expectedVersions);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment