Skip to content
Snippets Groups Projects
Commit 14910553 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!47
parents a427359c be3c5361
No related branches found
No related tags found
2 merge requests!96release V1.10.0,!47Dev
......@@ -23,6 +23,10 @@ export class ConfigurationService {
dotenv.config();
}
public isLocalConf(): boolean {
return process.env.NODE_ENV === 'local';
}
get config() {
return this._config;
}
......
......@@ -6,10 +6,15 @@ import { Post } from './schemas/post.schema';
import { PostsService } from './posts.service';
import { Tag } from './schemas/tag.schema';
import { PostWithMeta } from './schemas/postWithMeta.schema';
import { ConfigurationService } from '../configuration/configuration.service';
@Controller('posts')
export class PostsController {
constructor(private readonly httpService: HttpService, private readonly postsService: PostsService) {}
constructor(
private readonly httpService: HttpService,
private readonly postsService: PostsService,
private readonly configService: ConfigurationService
) {}
@Get()
@ApiQuery({ name: 'include', type: String, required: false })
......@@ -20,7 +25,7 @@ export class PostsController {
@ApiQuery({ name: 'page', type: String, required: false })
@ApiQuery({ name: 'order', type: String, required: false })
public async findAll(@Query() query): Promise<PostWithMeta> {
const result = await this.httpService
const result = this.httpService
.get(`${process.env.GHOST_HOST_AND_PORT}/ghost/api/v3/content/posts`, {
params: {
key: process.env.GHOST_CONTENT_API_KEY,
......@@ -40,9 +45,21 @@ export class PostsController {
})
);
return new Promise((resolve) => {
result.subscribe((result: PostWithMeta) => {
result.posts.map((post: Post) => (!post.custom_excerpt ? (post.excerpt = 'Inconnu') : ''));
resolve(result);
result.subscribe((postData: PostWithMeta) => {
postData.posts.forEach((post: Post) => {
// Handle excerpt field in case of no author
if (!post.custom_excerpt) {
post.excerpt = 'Inconnu';
}
// Handle image display. Rewrite image URL to fit ghost infra issue.
if (post.feature_image && !this.configService.isLocalConf()) {
post.feature_image = `https://${this.configService.config.host}/blog/content${
post.feature_image.split('/content')[1]
}`;
}
return post;
});
resolve(postData);
});
});
}
......
......@@ -5,7 +5,7 @@ export class Post {
slug: string;
html: string;
comment_id: string;
feature_image: null;
feature_image: string;
featured: false;
visibility: string;
email_recipient_filter: string;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment