Skip to content

Commit 921db47

Browse files
authored
feat: translation field for content updated (#3388)
1 parent 13533bb commit 921db47

4 files changed

Lines changed: 57 additions & 8 deletions

File tree

__tests__/workers/cdc/primary.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3347,6 +3347,7 @@ describe('post content updated', () => {
33473347
visible: true,
33483348
yggdrasilId: 'f30cdfd4-80cd-4955-bed1-0442dc5511bf',
33493349
deleted: false,
3350+
translation: {},
33503351
},
33513352
]);
33523353
});
@@ -3434,6 +3435,7 @@ describe('post content updated', () => {
34343435
visible: true,
34353436
yggdrasilId: 'f30cdfd4-80cd-4955-bed1-0442dc5511bf',
34363437
deleted: false,
3438+
translation: {},
34373439
},
34383440
]);
34393441
});
@@ -3563,6 +3565,7 @@ describe('post content updated', () => {
35633565
visible: true,
35643566
yggdrasilId: 'f30cdfd4-80cd-4955-bed1-0442dc5511bf',
35653567
deleted: false,
3568+
translation: {},
35663569
},
35673570
]);
35683571
});
@@ -3649,6 +3652,7 @@ describe('post content updated', () => {
36493652
visible: true,
36503653
yggdrasilId: 'f30cdfd4-80cd-4955-bed1-0442dc5511bf',
36513654
deleted: false,
3655+
translation: {},
36523656
},
36533657
]);
36543658
});
@@ -3664,8 +3668,21 @@ describe('post content updated', () => {
36643668
canonicalUrl: 'http://p4c.com',
36653669
contentMeta:
36663670
'{"cleaned":[{"provider":"test","resource_location":"gs://path.xml"}]}',
3667-
contentQuality:
3668-
'{"is_ai_probability":0.9}' as ArticlePost['contentQuality'],
3671+
contentQuality: '{"is_ai_probability":0.9}',
3672+
translation: JSON.stringify({
3673+
hr: {
3674+
title: 'translated title hr',
3675+
smartTitle: 'translated smart title hr',
3676+
titleHtml: '<p>translated title hr</p>',
3677+
summary: 'translated summary hr',
3678+
},
3679+
en: {
3680+
title: 'translated title',
3681+
smartTitle: 'translated smart title',
3682+
titleHtml: '<p>translated title</p>',
3683+
summary: 'translated summary',
3684+
},
3685+
}),
36693686
};
36703687
await expectSuccessfulBackground(
36713688
worker,
@@ -3687,6 +3704,20 @@ describe('post content updated', () => {
36873704
contentQuality: {
36883705
isAiProbability: 0.9,
36893706
},
3707+
translation: {
3708+
hr: {
3709+
title: 'translated title hr',
3710+
smartTitle: 'translated smart title hr',
3711+
titleHtml: '<p>translated title hr</p>',
3712+
summary: 'translated summary hr',
3713+
},
3714+
en: {
3715+
title: 'translated title',
3716+
smartTitle: 'translated smart title',
3717+
titleHtml: '<p>translated title</p>',
3718+
summary: 'translated summary',
3719+
},
3720+
},
36903721
},
36913722
],
36923723
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@connectrpc/connect-fastify": "^1.6.1",
3737
"@connectrpc/connect-node": "^1.6.1",
3838
"@dailydotdev/graphql-redis-subscriptions": "^2.4.3",
39-
"@dailydotdev/schema": "0.2.61",
39+
"@dailydotdev/schema": "0.2.62",
4040
"@dailydotdev/ts-ioredis-pool": "^1.0.2",
4141
"@fastify/cookie": "^11.0.2",
4242
"@fastify/cors": "^11.1.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/workers/cdc/common.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ContentMeta,
33
ContentQuality,
44
ContentUpdatedMessage,
5+
Translation,
56
} from '@dailydotdev/schema';
67
import { DataSource, ObjectLiteral } from 'typeorm';
78
import { EntityTarget } from 'typeorm/common/EntityTarget';
@@ -138,6 +139,23 @@ export const notifyPostContentUpdated = async ({
138139
}),
139140
deleted: articlePost.deleted,
140141
sharedPostId: sharePost.sharedPostId || undefined,
142+
translation: post.translation
143+
? Object.entries(
144+
typeof post.translation === 'string'
145+
? JSON.parse(post.translation)
146+
: post.translation,
147+
).reduce(
148+
(acc, [key, value]) => {
149+
acc[key] = decodeJsonField({
150+
value: value as JsonValue,
151+
decoder: new Translation(),
152+
});
153+
154+
return acc;
155+
},
156+
{} as { [key: string]: Translation },
157+
)
158+
: undefined,
141159
});
142160

143161
await triggerTypedEvent(

0 commit comments

Comments
 (0)