feat(search): add basic search functionality
this commit adds basic search feature. fix: https://codeberg.org/zyachel/libremdb/issues/9, https://github.com/zyachel/libremdb/issues/10
This commit is contained in:
71
src/utils/cleaners/find.ts
Normal file
71
src/utils/cleaners/find.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import RawFind from '../../interfaces/misc/rawFind';
|
||||
|
||||
const formatSAndE = (
|
||||
season: string | undefined,
|
||||
episode: string | undefined
|
||||
) => {
|
||||
if (season && season !== 'Unknown' && episode && episode !== 'Unknown')
|
||||
return `S${season} E${episode}`;
|
||||
return null;
|
||||
};
|
||||
|
||||
const cleanFind = (rawFind: RawFind) => {
|
||||
const {
|
||||
props: { pageProps: d },
|
||||
} = rawFind;
|
||||
|
||||
const cleanData = {
|
||||
meta: {
|
||||
exact: d.findPageMeta.isExactMatch,
|
||||
type: d.findPageMeta.searchType || null,
|
||||
titleType: d.findPageMeta.titleSearchType?.[0] || null,
|
||||
},
|
||||
people: d.nameResults.results.map(person => ({
|
||||
id: person.id,
|
||||
name: person.displayNameText,
|
||||
aka: person.akaName || null,
|
||||
jobCateogry: person.knownForJobCategory || null,
|
||||
knownForTitle: person.knownForTitleText || null,
|
||||
knownInYear: person.knownForTitleYear || null,
|
||||
...(person.avatarImageModel && {
|
||||
image: {
|
||||
url: person.avatarImageModel.url,
|
||||
caption: person.avatarImageModel.caption,
|
||||
},
|
||||
}),
|
||||
})),
|
||||
titles: d.titleResults.results.map(title => ({
|
||||
id: title.id,
|
||||
name: title.titleNameText,
|
||||
type: title.titleTypeText,
|
||||
releaseYear: title.titleReleaseText || null,
|
||||
credits: title.topCredits,
|
||||
...(title.titlePosterImageModel && {
|
||||
image: {
|
||||
url: title.titlePosterImageModel.url,
|
||||
caption: title.titlePosterImageModel.caption,
|
||||
},
|
||||
}),
|
||||
seriesId: title.seriesId || null,
|
||||
seriesName: title.seriesNameText || null,
|
||||
seriesType: title.seriesTypeText || null,
|
||||
seriesReleaseYear: title.seriesReleaseText || null,
|
||||
sAndE: formatSAndE(title.seriesSeasonText, title.seriesEpisodeText),
|
||||
})),
|
||||
companies: d.companyResults.results.map(company => ({
|
||||
id: company.id,
|
||||
name: company.companyName,
|
||||
type: company.typeText,
|
||||
country: company.countryText,
|
||||
})),
|
||||
keywords: d.keywordResults.results.map(keyword => ({
|
||||
id: keyword.id,
|
||||
text: keyword.keywordText,
|
||||
numTitles: keyword.numTitles,
|
||||
})),
|
||||
};
|
||||
|
||||
return cleanData;
|
||||
};
|
||||
|
||||
export default cleanFind;
|
Reference in New Issue
Block a user