Fixed boolean handling in actor profile curation.

This commit is contained in:
DebaucheryLibrarian 2020-12-29 23:44:38 +01:00
parent 92eed64fe8
commit a8f68f4993
1 changed files with 26 additions and 19 deletions

View File

@ -75,8 +75,30 @@ const ethnicities = {
white: 'white', white: 'white',
}; };
function getBoolean(value) {
if (typeof value === 'boolean') {
return value;
}
if (typeof value === 'string') {
if (/yes/i.test(value)) {
return true;
}
if (/no/i.test(value)) {
return true;
}
}
return null;
}
function getMostFrequent(items) { function getMostFrequent(items) {
const { mostFrequent } = items.reduce((acc, item) => { const { mostFrequent } = items.reduce((acc, item) => {
if (item === undefined || item === null) {
return acc;
}
const slug = slugify(item); const slug = slugify(item);
acc.counts[slug] = (acc.counts[slug] || 0) + 1; acc.counts[slug] = (acc.counts[slug] || 0) + 1;
@ -347,25 +369,10 @@ async function curateProfile(profile, actor) {
curatedProfile.penisLength = Number(profile.penisLength) || profile.penisLength?.match?.(/\d+/)?.[0] || null; curatedProfile.penisLength = Number(profile.penisLength) || profile.penisLength?.match?.(/\d+/)?.[0] || null;
curatedProfile.penisGirth = Number(profile.penisGirth) || profile.penisGirth?.match?.(/\d+/)?.[0] || null; curatedProfile.penisGirth = Number(profile.penisGirth) || profile.penisGirth?.match?.(/\d+/)?.[0] || null;
curatedProfile.circumcised = (typeof profile.circumcised === 'boolean' && profile.circumcised) curatedProfile.circumcised = getBoolean(profile.circumcised);
?? (/yes/i.test(profile.circumcised) && true) curatedProfile.naturalBoobs = getBoolean(profile.naturalBoobs);
?? (/no/i.test(profile.circumcised) && false) curatedProfile.hasTattoos = getBoolean(profile.hasTattoos);
?? null; curatedProfile.hasPiercings = getBoolean(profile.hasPiercings);
curatedProfile.naturalBoobs = (typeof profile.naturalBoobs === 'boolean' && profile.naturalBoobs)
?? (/yes/i.test(profile.naturalBoobs) && true)
?? (/no/i.test(profile.naturalBoobs) && false)
?? null;
curatedProfile.hasTattoos = (typeof profile.hasTattoos === 'boolean' && profile.hasTattoos)
?? (/yes/i.test(profile.hasTattoos) && true)
?? (/no/i.test(profile.hasTattoos) && true)
?? null;
curatedProfile.hasPiercings = (typeof profile.hasPiercings === 'boolean' && profile.hasPiercings)
?? (/yes/i.test(profile.hasPiercings) && true)
?? (/no/i.test(profile.hasPiercings) && true)
?? null;
if (argv.resolvePlace) { if (argv.resolvePlace) {
const [placeOfBirth, placeOfResidence] = await Promise.all([ const [placeOfBirth, placeOfResidence] = await Promise.all([