mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-02-06 09:56:03 +00:00
* lint @typescript-eslint/recommended * lint @typescript-eslint/recommended-requiring-type-checking fix type not detected locally due to wierd uuid typings missing save error not reported locally --------- Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
/* eslint-disable @typescript-eslint/await-thenable */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
import LanguageDetect from 'languagedetect'
|
|
|
|
import { removeHtmlTags } from '@middleware/helpers/cleanHtml'
|
|
|
|
const setPostLanguage = (text, defaultLanguage) => {
|
|
const lngDetector = new LanguageDetect()
|
|
lngDetector.setLanguageType('iso2')
|
|
let languages = lngDetector.detect(removeHtmlTags(text), 1)
|
|
if (!(Array.isArray(languages) && languages.length > 0)) {
|
|
languages = [[defaultLanguage, 1.0]]
|
|
}
|
|
return languages[0][0]
|
|
}
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreatePost: async (resolve, root, args, context, info) => {
|
|
args.language = await setPostLanguage(args.content, context.user.locale)
|
|
return resolve(root, args, context, info)
|
|
},
|
|
UpdatePost: async (resolve, root, args, context, info) => {
|
|
args.language = await setPostLanguage(args.content, context.user.locale)
|
|
return resolve(root, args, context, info)
|
|
},
|
|
},
|
|
}
|