UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.37 kB
{"version":3,"file":"prepare-media-translations.mjs","names":[],"sources":["../../../../src/services/media/helpers/prepare-media-translations.ts"],"sourcesContent":["import type { Insert, LucidMediaTranslations } from \"../../../types.js\";\n\nconst prepareMediaTranslations = (props: {\n\ttitle: {\n\t\tlocaleCode: string;\n\t\tvalue: string | null;\n\t}[];\n\talt: {\n\t\tlocaleCode: string;\n\t\tvalue: string | null;\n\t}[];\n\tdescription?: {\n\t\tlocaleCode: string;\n\t\tvalue: string | null;\n\t}[];\n\tsummary?: {\n\t\tlocaleCode: string;\n\t\tvalue: string | null;\n\t}[];\n\tmediaId: number;\n}): Array<Omit<Insert<LucidMediaTranslations>, \"id\">> => {\n\tconst translations: Array<Omit<Insert<LucidMediaTranslations>, \"id\">> = [];\n\n\tconst uniqueLocales = new Set<string>();\n\tfor (const title of props.title) {\n\t\tuniqueLocales.add(title.localeCode);\n\t}\n\tfor (const alt of props.alt) {\n\t\tuniqueLocales.add(alt.localeCode);\n\t}\n\tfor (const description of props.description || []) {\n\t\tuniqueLocales.add(description.localeCode);\n\t}\n\tfor (const summary of props.summary || []) {\n\t\tuniqueLocales.add(summary.localeCode);\n\t}\n\n\tfor (const locale of uniqueLocales) {\n\t\ttranslations.push({\n\t\t\tlocale_code: locale,\n\t\t\ttitle: props.title.find((t) => t.localeCode === locale)?.value ?? null,\n\t\t\talt: props.alt.find((a) => a.localeCode === locale)?.value ?? null,\n\t\t\tdescription:\n\t\t\t\tprops.description?.find((d) => d.localeCode === locale)?.value ?? null,\n\t\t\tsummary:\n\t\t\t\tprops.summary?.find((s) => s.localeCode === locale)?.value ?? null,\n\t\t\tmedia_id: props.mediaId,\n\t\t});\n\t}\n\n\treturn translations;\n};\n\nexport default prepareMediaTranslations;\n"],"mappings":"AAEA,MAAM,EAA4B,GAkBuB,CACxD,IAAM,EAAkE,CAAC,EAEnE,EAAgB,IAAI,IAC1B,IAAK,IAAM,KAAS,EAAM,MACzB,EAAc,IAAI,EAAM,UAAU,EAEnC,IAAK,IAAM,KAAO,EAAM,IACvB,EAAc,IAAI,EAAI,UAAU,EAEjC,IAAK,IAAM,KAAe,EAAM,aAAe,CAAC,EAC/C,EAAc,IAAI,EAAY,UAAU,EAEzC,IAAK,IAAM,KAAW,EAAM,SAAW,CAAC,EACvC,EAAc,IAAI,EAAQ,UAAU,EAGrC,IAAK,IAAM,KAAU,EACpB,EAAa,KAAK,CACjB,YAAa,EACb,MAAO,EAAM,MAAM,KAAM,GAAM,EAAE,aAAe,CAAM,CAAC,EAAE,OAAS,KAClE,IAAK,EAAM,IAAI,KAAM,GAAM,EAAE,aAAe,CAAM,CAAC,EAAE,OAAS,KAC9D,YACC,EAAM,aAAa,KAAM,GAAM,EAAE,aAAe,CAAM,CAAC,EAAE,OAAS,KACnE,QACC,EAAM,SAAS,KAAM,GAAM,EAAE,aAAe,CAAM,CAAC,EAAE,OAAS,KAC/D,SAAU,EAAM,OACjB,CAAC,EAGF,OAAO,CACR"}