mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
language detect: remove unwanted db fields
This commit is contained in:
parent
250d231a74
commit
ca74c91fc9
@ -11,31 +11,17 @@ const removeHtmlTags = (input) => {
|
||||
const setPostLanguage = (text) => {
|
||||
const lngDetector = new LanguageDetect()
|
||||
lngDetector.setLanguageType('iso2')
|
||||
const result = lngDetector.detect(removeHtmlTags(text), 2)
|
||||
return {
|
||||
language: result[0][0],
|
||||
languageScore: result[0][1],
|
||||
secondaryLanguage: result[1][0],
|
||||
secondaryLanguageScore: result[1][1],
|
||||
}
|
||||
return lngDetector.detect(removeHtmlTags(text), 1)[0][0]
|
||||
}
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
CreatePost: async (resolve, root, args, context, info) => {
|
||||
const languages = await setPostLanguage(args.content)
|
||||
args = {
|
||||
...args,
|
||||
...languages,
|
||||
}
|
||||
args.language = await setPostLanguage(args.content)
|
||||
return resolve(root, args, context, info)
|
||||
},
|
||||
UpdatePost: async (resolve, root, args, context, info) => {
|
||||
const languages = await setPostLanguage(args.content)
|
||||
args = {
|
||||
...args,
|
||||
...languages,
|
||||
}
|
||||
args.language = await setPostLanguage(args.content)
|
||||
return resolve(root, args, context, info)
|
||||
},
|
||||
},
|
||||
|
||||
@ -32,9 +32,6 @@ const createPostMutation = gql`
|
||||
mutation($title: String!, $content: String!, $categoryIds: [ID]) {
|
||||
CreatePost(title: $title, content: $content, categoryIds: $categoryIds) {
|
||||
language
|
||||
languageScore
|
||||
secondaryLanguage
|
||||
secondaryLanguageScore
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -61,17 +58,15 @@ describe('languagesMiddleware', () => {
|
||||
...variables,
|
||||
content: 'Jeder sollte vor seiner eigenen Tür kehren.',
|
||||
}
|
||||
const response = await mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})
|
||||
expect(response).toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'de',
|
||||
languageScore: 0.5134188034188034,
|
||||
secondaryLanguage: 'no',
|
||||
secondaryLanguageScore: 0.3655555555555555,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -82,17 +77,15 @@ describe('languagesMiddleware', () => {
|
||||
...variables,
|
||||
content: 'A journey of a thousand miles begins with a single step.',
|
||||
}
|
||||
const response = await mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})
|
||||
expect(response).toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'en',
|
||||
languageScore: 0.3430188679245283,
|
||||
secondaryLanguage: 'da',
|
||||
secondaryLanguageScore: 0.19968553459119498,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -103,17 +96,15 @@ describe('languagesMiddleware', () => {
|
||||
...variables,
|
||||
content: 'A caballo regalado, no le mires el diente.',
|
||||
}
|
||||
const response = await mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})
|
||||
expect(response).toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'es',
|
||||
languageScore: 0.46589743589743593,
|
||||
secondaryLanguage: 'pt',
|
||||
secondaryLanguageScore: 0.3834188034188034,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -125,17 +116,15 @@ describe('languagesMiddleware', () => {
|
||||
content:
|
||||
'<strong>Jeder</strong> <strike>sollte</strike> <strong>vor</strong> <span>seiner</span> eigenen <blockquote>Tür</blockquote> kehren.',
|
||||
}
|
||||
const response = await mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})
|
||||
expect(response).toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'de',
|
||||
languageScore: 0.5134188034188034,
|
||||
secondaryLanguage: 'no',
|
||||
secondaryLanguageScore: 0.3655555555555555,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@ -122,9 +122,6 @@ type Post {
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
language: String
|
||||
languageScore: Float
|
||||
secondaryLanguage: String
|
||||
secondaryLanguageScore: Float
|
||||
pinnedAt: String @cypher(
|
||||
statement: "MATCH (this)<-[pinned:PINNED]-(:User) WHERE NOT this.deleted = true AND NOT this.disabled = true RETURN pinned.createdAt"
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user