@@ -202,8 +202,8 @@ <h3 id="methods">
202202
203203 < tr >
204204 < td class ="col-md-4 ">
205- < div class ="io-line "> Defined in < a href ="" data-line ="73 "
206- class ="link-to-prism "> src/app.controller.ts:73 </ a > </ div >
205+ < div class ="io-line "> Defined in < a href ="" data-line ="20 "
206+ class ="link-to-prism "> src/app.controller.ts:20 </ a > </ div >
207207 </ td >
208208 </ tr >
209209
@@ -267,7 +267,7 @@ <h3 id="methods">
267267 < tr >
268268 < td class ="col-md-4 ">
269269 < span class ="modifier-icon icon ion-ios-reset "> </ span >
270- < code > update(res: Response, project?: < a href ="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string " target ="_blank " > string </ a > , current?: < a href ="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string " target ="_blank "> string</ a > )</ code >
270+ < code > update(res: Response, project?: < a href ="../undefineds/ProjectsList.html " target ="_self " > ProjectsList </ a > , current?: < a href ="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string " target ="_blank "> string</ a > )</ code >
271271 </ td >
272272 </ tr >
273273
@@ -281,8 +281,8 @@ <h3 id="methods">
281281
282282 < tr >
283283 < td class ="col-md-4 ">
284- < div class ="io-line "> Defined in < a href ="" data-line ="81 "
285- class ="link-to-prism "> src/app.controller.ts:81 </ a > </ div >
284+ < div class ="io-line "> Defined in < a href ="" data-line ="28 "
285+ class ="link-to-prism "> src/app.controller.ts:28 </ a > </ div >
286286 </ td >
287287 </ tr >
288288
@@ -317,7 +317,7 @@ <h3 id="methods">
317317 < tr >
318318 < td > project</ td >
319319 < td >
320- < code > < a href ="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string " target ="_blank " > string </ a > </ code >
320+ < code > < a href ="../miscellaneous/enumerations.html#ProjectsList " target ="_self " > ProjectsList </ a > </ code >
321321 </ td >
322322
323323 < td >
@@ -357,64 +357,11 @@ <h3 id="methods">
357357
358358 < div class ="tab-pane fade tab-source-code " id ="source ">
359359 < pre class ="line-numbers compodoc-sourcecode "> < code class ="language-typescript "> import { BadRequestException, Controller, Get, Param, Query, Res } from '@nestjs/common';
360- import { AppService } from './app.service';
360+ import { AppService, ProjectsList } from './app.service';
361361import { Response } from 'express';
362362import { AbstractController } from '~/_common/abstracts/abstract.controller';
363363import { Public } from './_common/decorators/public.decorator';
364364import { ApiBearerAuth, ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger';
365- import { LRUCache } from 'lru-cache';
366-
367- interface GithubAuthor {
368- login: string;
369- id: number;
370- node_id: string;
371- avatar_url: string;
372- gravatar_id: string;
373- url: string;
374- html_url: string;
375- followers_url: string;
376- following_url: string;
377- gists_url: string;
378- starred_url: string;
379- subscriptions_url: string;
380- organizations_url: string;
381- repos_url: string;
382- events_url: string;
383- received_events_url: string;
384- type: string;
385- user_view_type: string;
386- site_admin: boolean;
387- }
388-
389- interface GithubAsset {
390- [key: string]: any;
391- }
392-
393- interface GithubUpdate {
394- url: string;
395- assets_url: string;
396- upload_url: string;
397- html_url: string;
398- id: number;
399- author: GithubAuthor;
400- node_id: string;
401- tag_name: string;
402- target_commitish: string;
403- name: string;
404- draft: boolean;
405- prerelease: boolean;
406- created_at: string;
407- published_at: string;
408- assets: GithubAsset[];
409- tarball_url: string;
410- zipball_url: string;
411- body: string;
412- }
413-
414- const storage = new LRUCache({
415- ttl: 1000 * 60 * 60,
416- ttlAutopurge: true,
417- });
418365
419366@Public()
420367@Controller()
@@ -438,43 +385,35 @@ <h3 id="methods">
438385 @Get('/get-update/:project(sesame-orchestrator|sesame-daemon|sesame-app-manager)')
439386 public async update(
440387 @Res() res: Response,
441- @Param('project') project?: string ,
388+ @Param('project') project?: ProjectsList ,
442389 @Query('current') current?: string,
443390 ): Promise<Response> {
444- const validProjects = ['sesame-orchestrator', 'sesame-daemon', 'sesame-app-manager'];
445- if (!validProjects.includes(project)) {
446- throw new BadRequestException(`Invalid project: ${project}`);
447- }
448-
449- let data = <GithubUpdate>{};
450- if (storage.has(project)) {
451- this.logger.log(`Fetching ${project} tags from cache`);
452- data = storage.get(project) as GithubUpdate;
453- } else {
454- this.logger.log(`Fetching ${project} tags`);
455- const update = await fetch(`https://api.github.com/repos/Libertech-FR/${project}/releases/latest`, {
456- signal: AbortSignal.timeout(1000),
457- });
458- data = await update.json();
459- console.log('update', data)
460- storage.set(project, data);
461- }
462- // if (!Array.isArray(data)) {
463- // throw new BadRequestException(`Invalid data from Github <${JSON.stringify(data)}>`);
464- // }
465- const lastVersion = data.tag_name.replace(/^v/, '');
466391 const pkgInfo = this.appService.getInfo();
467392 const currentVersion = current || pkgInfo.version;
393+ const [lastMajor, lastMinor, lastPatch] = currentVersion.split('.').map(Number);
468394
395+ /**
396+ * If the project is not the same as the package name or if a current version is provided,
397+ * we validate the current version format.
398+ * If the current version is not in the format X.Y.Z, we throw a BadRequestException.
399+ *
400+ * This ensures that the current version is always in a valid format before proceeding with the comparison.
401+ */
469402 if (project !== pkgInfo.name || current) {
470403 if (!/[0-9]+\.[0-9]+\.[0-9]+/.test(current)) {
471404 throw new BadRequestException('Invalid version for current parameter');
472405 }
473406 }
474407
475- const [currentMajor, currentMinor, currentPatch] = lastVersion.split('.').map(Number);
476- const [lastMajor, lastMinor, lastPatch] = currentVersion.split('.').map(Number);
477- const updateAvailable = currentMajor > lastMajor || currentMinor > lastMinor || currentPatch > lastPatch;
408+ let lastVersion = '0.0.0';
409+ let updateAvailable = false;
410+ let data = await this.appService.getProjectUpdate(project);
411+
412+ if (data) {
413+ lastVersion = data.tag_name.replace(/^v/, '');
414+ const [currentMajor, currentMinor, currentPatch] = lastVersion.split('.').map(Number);
415+ updateAvailable = currentMajor > lastMajor || currentMinor > lastMinor || currentPatch > lastPatch;
416+ }
478417
479418 return res.json({
480419 data: {
0 commit comments