mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-03 02:56:45 -04:00
(api)(nouns) add backwards compatibility on /api/nouns
This commit is contained in:
parent
01995be86e
commit
ce6849a17f
@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type NounsSubmitForm from '~/components/nouns/NounsSubmitForm.vue';
|
||||
import { filterWordsForConvention, loadWords, Noun } from '~/src/classes.ts';
|
||||
import type { Filter } from '~/src/classes.ts';
|
||||
import type { NounRaw, Filter } from '~/src/classes.ts';
|
||||
import { loadNounsData } from '~/src/data.ts';
|
||||
import { collapseNounWordsInjectionKey } from '~/src/injectionKeys.ts';
|
||||
import { addWordsFromClassInstance, availableGenders, buildNounDeclensionsByFirstCase } from '~/src/nouns.ts';
|
||||
@ -34,8 +34,8 @@ const nounsAsyncData = useAsyncData(
|
||||
async () => {
|
||||
const declensionsByFirstCase = buildNounDeclensionsByFirstCase(config, nounsData.cases, nounsData.declensions);
|
||||
const collator = Intl.Collator(config.locale);
|
||||
return Object.fromEntries((await $fetch('/api/nouns'))
|
||||
.map((nounRaw) => loadWords(nounRaw, config, declensionsByFirstCase))
|
||||
return Object.fromEntries((await $fetch('/api/nouns', { query: { version: 2 } }))
|
||||
.map((nounRaw) => loadWords(nounRaw as NounRaw, config, declensionsByFirstCase))
|
||||
.map((nounRaw) => {
|
||||
if (!nounRaw.classInstance) {
|
||||
return nounRaw;
|
||||
|
@ -568,7 +568,7 @@ api:
|
||||
sources_all: ['/api/sources']
|
||||
sources_one: ['/api/sources/01ERQRCV0V4QVMNKCENF724A08']
|
||||
|
||||
nouns_all: ['/api/nouns']
|
||||
nouns_all: ['/api/nouns?version=2']
|
||||
nouns_search: ['/api/nouns/search/person']
|
||||
|
||||
inclusive_all: ['/api/inclusive']
|
||||
|
@ -4371,7 +4371,7 @@ api:
|
||||
sources_all: ['/api/sources']
|
||||
sources_one: ['/api/sources/01F1JDD446TNY56PQG7E6MFRRH']
|
||||
|
||||
nouns_all: ['/api/nouns']
|
||||
nouns_all: ['/api/nouns?version=2']
|
||||
nouns_search: ['/api/nouns/search/ateis']
|
||||
|
||||
inclusive_all: ['/api/inclusive']
|
||||
|
@ -202,7 +202,7 @@ api:
|
||||
inclusive_all: ['/api/inclusive']
|
||||
inclusive_search: ['/api/inclusive/search/gerizekalı']
|
||||
|
||||
terms_all: ['/api/terms']
|
||||
terms_all: ['/api/terms?version=2']
|
||||
terms_search: ['/api/terms/search/cinsiyetsiz']
|
||||
|
||||
profile_get: ['/api/profile/get/andrea?version=2']
|
||||
|
@ -57,7 +57,7 @@ const groups = computed((): Group[] => {
|
||||
header: 'nouns.header',
|
||||
icon: 'atom-alt',
|
||||
endpoints: {
|
||||
nouns_all: ['GET', '/api/nouns'],
|
||||
nouns_all: ['GET', '/api/nouns?version=2'],
|
||||
nouns_search: ['GET', '/api/nouns/search/{term}'],
|
||||
},
|
||||
}, {
|
||||
|
@ -1,11 +1,42 @@
|
||||
import { getLocale, loadConfig } from '~/server/data.ts';
|
||||
import { getNounEntries } from '~/server/nouns.ts';
|
||||
import { getLocale, loadConfig, loadNounsData } from '~/server/data.ts';
|
||||
import { buildNoun, getNounEntries } from '~/server/nouns.ts';
|
||||
import type { Noun } from '~/src/classes.ts';
|
||||
import { genders, numeri, resolveFirstDeclension } from '~/src/nouns.ts';
|
||||
import type { NounsData } from '~/src/nouns.ts';
|
||||
|
||||
const downgradeToV1 = (noun: Noun, nounsData: NounsData) => {
|
||||
const downgradedNoun: Record<string, unknown> = {
|
||||
id: noun.id,
|
||||
sourcesData: noun.sourcesData,
|
||||
categories: noun.categories.join('|'),
|
||||
sources: noun.sources.join(','),
|
||||
};
|
||||
for (const gender of genders) {
|
||||
for (const numerus of numeri) {
|
||||
const wordSpellings = noun.words[gender]?.[numerus]
|
||||
?.map((word) => resolveFirstDeclension(word, numerus, nounsData)) ?? [];
|
||||
downgradedNoun[gender + (numerus === 'singular' ? '' : 'Pl')] = wordSpellings.join('|');
|
||||
}
|
||||
}
|
||||
return downgradedNoun;
|
||||
};
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const locale = getLocale(event);
|
||||
checkIsConfigEnabledOr404(await loadConfig(locale), 'nouns');
|
||||
|
||||
const query = getQuery(event);
|
||||
|
||||
const { isGranted } = await useAuthentication(event);
|
||||
const db = useDatabase();
|
||||
return await getNounEntries(db, isGranted, locale);
|
||||
const nouns = await getNounEntries(db, isGranted, locale);
|
||||
if (query.version !== '2') {
|
||||
const config = await loadConfig(locale);
|
||||
const nounsData = await loadNounsData(locale);
|
||||
return nouns
|
||||
.map((nounRaw) => buildNoun(nounRaw, config, nounsData))
|
||||
.map((noun) => downgradeToV1(noun, nounsData));
|
||||
} else {
|
||||
return nouns;
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user