Skip to content

Commit

Permalink
Merge pull request #24 from xeptagondev/iverfiy-rdc-be
Browse files Browse the repository at this point in the history
Iverfiy rdc be
  • Loading branch information
palindaa authored Oct 9, 2024
2 parents 1b49193 + 664dd2e commit c32f809
Show file tree
Hide file tree
Showing 52 changed files with 3,596 additions and 31,978 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deployment-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: iverify-publisher
IMAGE_TAG: latest
IMAGE_TAG: v2
run: |
npx nx build publisher
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f ./apps/publisher/Dockerfile .
Expand All @@ -152,7 +152,7 @@ jobs:
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: iverify-triage
IMAGE_TAG: latest
IMAGE_TAG: v2
run: |
npx nx build triage
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f ./apps/triage/Dockerfile .
Expand Down
71 changes: 71 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,77 @@
}
}
}
},
"unitedwave-client": {
"projectType": "library",
"root": "libs/unitedwave-client",
"sourceRoot": "libs/unitedwave-client/src",
"prefix": "iverify",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/unitedwave-client"],
"options": {
"jestConfig": "libs/unitedwave-client/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/unitedwave-client/src/**/*.ts",
"libs/unitedwave-client/src/**/*.html"
]
}
}
}
},
"libs-s3": {
"projectType": "library",
"root": "libs/libs/s3",
"sourceRoot": "libs/libs/s3/src",
"prefix": "iverify",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/libs/s3"],
"options": {
"jestConfig": "libs/libs/s3/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/libs/s3/src/**/*.ts",
"libs/libs/s3/src/**/*.html"
]
}
}
}
},
"s3": {
"root": "libs/s3",
"sourceRoot": "libs/s3/src",
"projectType": "library",
"architect": {
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["libs/s3/**/*.ts"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/s3"],
"options": {
"jestConfig": "libs/s3/jest.config.js",
"passWithNoTests": true
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion apps/publisher/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:lts-alpine
WORKDIR /app
COPY ./dist/apps/publisher .
COPY ./ssl .
ENV PORT=3334
EXPOSE 3334
RUN npm install --production
RUN npm install reflect-metadata tslib rxjs @nestjs/platform-express
CMD node ./main.js
CMD node ./main.js
1 change: 1 addition & 0 deletions apps/publisher/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
const globalPrefix = 'publisher';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3334;
Expand Down
20 changes: 11 additions & 9 deletions apps/publisher/src/wp-publisher/wp-publisher-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export class WpPublisherHelper{


buildPostFromReport(
report: any,
report: any,
meedanReport: any,
// categories: number[],
// categories: number[],
author: number,
media: number,
tags: number[],
categories: number[],
visualCard: string): CreatePostDto{

const status = PostStatus.publish;
const comment_status = CommentStatus.open;
const format = PostFormat.standard;
Expand All @@ -48,9 +48,10 @@ export class WpPublisherHelper{
const evidence = this.sharedHelper.extractTask(report, TasksLabels[this.lang].evidences_and_references);
const evidence_and_references = this.formatEvidence(evidence);
const _webdados_fb_open_graph_specific_image = visualCard;
const fields: PostFields = {check_id, factchecking_status, claim, rating_justification, evidence_and_references, subtitle, toxic};
const category = this.sharedHelper.extractTask(report, TasksLabels[this.lang].category_checked);
const fields: PostFields = {check_id, factchecking_status, claim, rating_justification, evidence_and_references, subtitle, toxic,category};
console.log('visual card url: ', _webdados_fb_open_graph_specific_image)

const email_address = this.sharedHelper.extractTask(report, TasksLabels[this.lang].email_address);
const post: CreatePostDto = {
format,
author,
Expand All @@ -61,13 +62,14 @@ export class WpPublisherHelper{
tags,
fields,
categories,
_webdados_fb_open_graph_specific_image
_webdados_fb_open_graph_specific_image,
email_address
}

if(!post.featured_media) delete post.featured_media;

return post;
}
}

extractFactcheckingStatus(report: any){
return this.sharedHelper.extractFactcheckingStatus(report);
Expand Down Expand Up @@ -101,14 +103,14 @@ export class WpPublisherHelper{
// if (word.startsWith('http://') || word.startsWith('https://') || word.startsWith('www.')) {
// word = `<a href=${word} target="_blank" rel="noopener noreferrer">${word}</a>`
// }

// updated_test += (word + ' ')
// }

try {
const converter = new showdown.Converter({simplifiedAutoLink: true, simpleLineBreaks: true, openLinksInNewWindow: true, emoji: true});
converter.setFlavor('github');
return converter.makeHtml(evidence);
return converter.makeHtml(evidence);
} catch (err) {
return evidence;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/publisher/src/wp-publisher/wp-publisher.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { HttpModule, Module } from '@nestjs/common';
import { SharedModule } from '../shared/shared.module';
import { WpPublisherHelper } from './wp-publisher-helper.service';
import { WpPublisherService } from './wp-publisher.service';
import { EmailModule } from '@iverify/email/src';

@Module({
imports: [HttpModule, SharedModule, WpClientModule],
imports: [HttpModule, SharedModule, WpClientModule, EmailModule],
providers: [WpPublisherService, WpPublisherHelper],
exports: [WpPublisherService]
})
Expand Down
62 changes: 37 additions & 25 deletions apps/publisher/src/wp-publisher/wp-publisher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { combineLatest, from, iif, Observable, of, zip } from "rxjs";
import { catchError, concatMap, filter, map, reduce, scan, shareReplay, switchMap, take, tap, withLatestFrom } from "rxjs/operators";
import { SharedService } from "../shared/shared.service";
import { WpPublisherHelper } from "./wp-publisher-helper.service";
import { EmailService } from "@iverify/email/src";

@Injectable({ scope: Scope.REQUEST })
export class WpPublisherService{
Expand All @@ -26,15 +27,15 @@ export class WpPublisherService{
throw new HttpException(err.message, 500);
})
)

tagsIds$: Observable<number[]> = this.report$.pipe(
map(report => this.helper.extractTags(report)),
switchMap(tags => iif(() => !!tags && !!tags.length, this.tagsIds(tags), of(null))),
catchError(err => {
throw new HttpException(err.message, 500);
})
)

private mediaId$: Observable<number> = this.meedanReport$.pipe(
map(report => report.image),
switchMap(url => this.http.get(url, {responseType: 'arraybuffer'})),
Expand All @@ -43,10 +44,10 @@ export class WpPublisherService{
map(res => res['id']),
catchError(err => {
return of(null)
// throw new HttpException(err.message, 500);
// throw new HttpException(err.message, 500);
})
)

private author$: Observable<number> = this.wpClient.getAppUser().pipe(
map(user => user.id),
catchError(err => {
Expand All @@ -58,29 +59,40 @@ export class WpPublisherService{
map(report => report.visual_card_url),
catchError(err => {
return of(null)
// throw new HttpException(err.message, 500);
// throw new HttpException(err.message, 500);
})
)

post$: Observable<any> = combineLatest([this.report$, this.meedanReport$, this.author$, this.mediaId$, this.tagsIds$, this.categoriesIds$, this.visualCard$]).pipe(
map(([report, meedanReport, author, media, tags, categories, visualCard]) => this.helper.buildPostFromReport(report, meedanReport, author, media, tags, categories, visualCard)),
filter(post => !!post.title.length),
take(1),
tap(postDto => console.log('sending to WP publication: ', JSON.stringify(postDto))),
withLatestFrom(this.wpPostId$),
map(([postDto, wpPostId]) => ({postDto, wpPostId})),
switchMap(data => this.wpClient.publishPost(data.postDto, data.wpPostId)),
tap(wpPost => this.shared.updateWpPost(wpPost)),
map(([report, meedanReport, author, media, tags, categories, visualCard]) =>
this.helper.buildPostFromReport(report, meedanReport, author, media, tags, categories, visualCard)
),
filter(post => !!post.title?.length), // Ensure post has a title
take(1),
tap(postDto => console.log('sending to WP publication: ', JSON.stringify(postDto))),
withLatestFrom(this.wpPostId$),
map(([postDto, wpPostId]) => ({ postDto, wpPostId })),
switchMap(data => this.wpClient.publishPost(data.postDto, data.wpPostId).pipe(
tap(wpPost => {
this.shared.updateWpPost(wpPost);
if (data.postDto.email_address) {
this.emailService.submittedFactCheckContent(data.postDto.email_address, wpPost.link).catch(err => {
console.error('Error sending post published email:', err);
});
}
}),
catchError(err => {
throw new HttpException(err.message, 500);
})
)
))
);

constructor(
private http: HttpService,
private shared: SharedService,
private wpClient: WpClientService,
private helper: WpPublisherHelper
private helper: WpPublisherHelper,
private emailService: EmailService
){}

private tagsIds(tags: string[]): Observable<number[]>{
Expand All @@ -106,7 +118,7 @@ export class WpPublisherService{
// map(wpTags => tags.filter(tag => wpTags.indexOf(tag.toLowerCase()) === -1)),
// tap(wpTags => console.log('new tags: ', wpTags)),

// )
// )
// const newTagsIds$: Observable<number[]> = newTags$.pipe(
// switchMap(tags => iif(()=> !!tags.length, this.createManyTags(tags).pipe(map(tag => [tag.id])), of([]))),
// reduce((acc, val) => [...acc, ...val], [])
Expand All @@ -117,7 +129,7 @@ export class WpPublisherService{
// throw new HttpException(err.message, 500);
// })
// )

return tagsIds$;
}

Expand All @@ -131,39 +143,39 @@ export class WpPublisherService{
// const newCategories$: Observable<string[]> = wpCategories$.pipe(
// map(wpCategories => wpCategories.map(category => category.name as string)),
// map(wpCategories => categories.filter(category => wpCategories.indexOf(category) === -1))
// )
// )
// const newCategoriesIds$: Observable<number[]> = newCategories$.pipe(
// switchMap(categories => iif(()=> !!categories.length, this.createManyCategories(categories).pipe(map(category => [category.id])), of([]))),
// scan((acc, val) => [...acc, ...val], [])
// )
// const categoriesIds$: Observable<number[]> = combineLatest([existingCategoriesIds$, newCategoriesIds$]).pipe(
// map(([existingIds, newIds]) => [...existingIds, ...newIds])
// )

return existingCategoriesIds$;
}

private createManyTags(tags: string[]): Observable<any>{
const tagsDtos: CreateTagDto[] = tags.map(tag => ({name: tag}))
const tagsDtos: CreateTagDto[] = tags.map(tag => ({name: tag}))
return from(tagsDtos).pipe(
tap(tag => console.log('sending tag to creation: ', tag)),
concatMap(tag => this.createSingleTag(tag)),
tap(tag => console.log('Returning tag from creation: ', tag)),
reduce((acc, item) => [...acc, item], [])
)
}

private createSingleTag(tag: CreateTagDto): Observable<any>{
return this.wpClient.createTag(tag)
}

private createManyCategories(categories: string[]): Observable<any>{
const categoriesDtos: CreateCategoryDto[] = categories.map(category => ({name: category}))
const categoriesDtos: CreateCategoryDto[] = categories.map(category => ({name: category}))
return from(categoriesDtos).pipe(
concatMap(category => this.createSingleCategory(category))
)
}

private createSingleCategory(category: CreateCategoryDto): Observable<any>{
return this.wpClient.createCategory(category)
}
Expand Down
3 changes: 2 additions & 1 deletion apps/triage/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:lts-alpine
WORKDIR /app
COPY ./dist/apps/triage .
COPY ./ssl .
ENV PORT=3335
EXPOSE 3335
RUN npm install --production
RUN npm install reflect-metadata tslib rxjs @nestjs/platform-express
CMD node ./main.js
CMD node ./main.js
Loading

0 comments on commit c32f809

Please sign in to comment.