Skip to content

Commit

Permalink
Merge pull request #43 from Sanofi-IADC/bugfix/sonarcloud-fixes
Browse files Browse the repository at this point in the history
fix: minor fixes to improve code
  • Loading branch information
PiiXiieeS authored Mar 30, 2021
2 parents 6d74bc7 + 77314ff commit 287ac64
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
isGlobal: true,
}),
CacheModule.register({
// TODO: Make the cache parameters customizable via env variables
ttl: 604800, // 1 week
max: 10,
}),
Expand All @@ -48,6 +49,6 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
// TODO: Improve the logger customization in development mode (* for all routes)
consumer.apply(LoggerMiddleware).forRoutes('/slides*');
consumer.apply(LoggerMiddleware).forRoutes('*');
}
}
2 changes: 0 additions & 2 deletions src/config/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import LogLevel from "./LogLevel";

interface Config {
env: string;

Expand Down
5 changes: 2 additions & 3 deletions src/confluence/confluence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ConfluenceService {
})
.toPromise();
this.logger.log(`Retrieving page ${pageId}`);
// TODO: Check first metadata.labels!=='iadc-private' or return error 403 Forbidden
return results.data;
} catch (err) {
this.logger.log(err, 'error:getPage');
Expand All @@ -53,7 +54,7 @@ export class ConfluenceService {
},
})
.toPromise();
// this.logger.log(`Retrieving media from ${uri}`);
this.logger.log(`Retrieving media from ${uri}`);
return results.headers.location;
} catch (err) {
this.logger.log(err, 'error:getRedirectUrlForMedia');
Expand Down Expand Up @@ -122,13 +123,11 @@ export class ConfluenceService {
params: {
limit: 999,
cql: cpl,
// excerpt: "highlight", // use "highlight" to enclosed word found in @@@hl@@@ and @@@endhl@@@
expand: [
// fields to retrieve
'content.history',
'content.metadata.labels',
'content.body.styled_view',
// 'content.body.view',
].join(','),
},
})
Expand Down
3 changes: 1 addition & 2 deletions src/http/http.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
OnModuleInit,
HttpModule as BaseHttpModule,
} from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigService } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import Config from '../config/config';

@Module({
Expand Down
6 changes: 2 additions & 4 deletions src/proxy-api/proxy-api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export class ProxyApiController {
*/
@Get('getAllPosts/:spaceKey')
async getAllPosts(@Param() params: PostsParamsDTO): Promise<any> {
const data = await this.proxyApi.getAllPosts(params.spaceKey);
return data;
return await this.proxyApi.getAllPosts(params.spaceKey);
}

/**
Expand All @@ -24,10 +23,9 @@ export class ProxyApiController {
*/
@Get('search')
async getSearchResults(@Query() queries: SearchQueryDTO): Promise<any> {
const data = await this.proxyApi.getSearchResults(
return await this.proxyApi.getSearchResults(
queries.spaceKey,
queries.query,
);
return data;
}
}
3 changes: 0 additions & 3 deletions src/proxy-api/proxy-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class ProxyApiService {
* @param spaceKey {string} 'iadc' - space key where the page belongs
*/
async getAllPosts(spaceKey: string): Promise<any> {
// const results = await this.confluence.getPage(spaceKey, pageId);
const data = await this.confluence.getAllPosts(spaceKey);
const baseURL = this.config.get<Config>('confluence.baseURL');
const baseHost = this.config.get<Config>('web.baseHost');
Expand Down Expand Up @@ -69,7 +68,6 @@ export class ProxyApiService {
* @param query {string} 'vision factory' - words to be searched
*/
async getSearchResults(spaceKey: string, query: string): Promise<string> {
// const context = new Context(spaceKey, '', '', scope, query);
const data = await this.confluence.getResults(spaceKey, query);
const baseURL = this.config.get<Config>('confluence.baseURL');
const baseHost = this.config.get<Config>('web.baseHost');
Expand Down Expand Up @@ -122,7 +120,6 @@ export class ProxyApiService {
results: parseResults,
};

// console.log("objects is ", combined);
return JSON.parse(JSON.stringify(combined));
// return combined; // why this is not working?
}
Expand Down
29 changes: 6 additions & 23 deletions src/proxy-page/proxy-page.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ export class ProxyPageController {
@Query() queries: PageQueryDTO,
) {
this.logger.verbose(`Rendering... /${params.spaceKey}/${params.pageId}`);
const page = await this.proxyPage.renderPage(
return await this.proxyPage.renderPage(
params.spaceKey,
params.pageId,
queries.theme,
queries.type,
);
return page;
}

/**
Expand All @@ -53,32 +52,16 @@ export class ProxyPageController {
this.logger.verbose(
`Rendering Slides for ... /${params.spaceKey}/${params.pageId}`,
);
const page = await this.proxyPage.renderSlides(
params.spaceKey,
params.pageId,
);
return page;
}

/**
* @GET (controller) /download/*
* @description Route to retrieve the standard media files like images and videos (usually attachments)
* @return {string} 'url' - URL of the media to display
*/
@Get('/download/*')
async download(@Req() req: Request, @Res() res: Response) {
const reqUrl = req.url.replace(/\/cpv\/wiki/, '');
const mediaCdnUrl = await this.proxyPage.getMediaCdnUrl(reqUrl);
res.redirect(mediaCdnUrl);
return await this.proxyPage.renderSlides(params.spaceKey, params.pageId);
}

/**
* @GET (controller) /aa-avatar/*
* @description Route to retrieve the avatar image asociated with a Confluence user profile
* @GET (controller) /download/* or /aa-avatar/*
* @description Route to retrieve the standard media files like images, videos or user profile avatar
* @return {string} 'url' - URL of the media to display
*/
@Get('/aa-avatar/*')
async avatar(@Req() req: Request, @Res() res: Response) {
@Get(['/download/*', '/aa-avatar/*'])
async getMedia(@Req() req: Request, @Res() res: Response) {
const reqUrl = req.url.replace(/\/cpv\/wiki/, '');
const mediaCdnUrl = await this.proxyPage.getMediaCdnUrl(reqUrl);
res.redirect(mediaCdnUrl);
Expand Down

0 comments on commit 287ac64

Please sign in to comment.