forked from DebaucheryLibrarian/traxxx
				
			
		
			
				
	
	
		
			244 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			244 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
| import dayjs from 'dayjs';
 | |
| 
 | |
| function curateActor(actor, release) {
 | |
| 	if (!actor) {
 | |
| 		return null;
 | |
| 	}
 | |
| 
 | |
| 	const curatedActor = {
 | |
| 		...actor,
 | |
| 		height: actor.heightMetric && {
 | |
| 			metric: actor.heightMetric,
 | |
| 			imperial: actor.heightImperial,
 | |
| 		},
 | |
| 		weight: actor.weightMetric && {
 | |
| 			metric: actor.weightMetric,
 | |
| 			imperial: actor.weightImperial,
 | |
| 		},
 | |
| 		origin: actor.birthCountry && {
 | |
| 			city: actor.birthCity,
 | |
| 			state: actor.birthState,
 | |
| 			country: actor.birthCountry,
 | |
| 		},
 | |
| 		residence: actor.residenceCountry && {
 | |
| 			city: actor.residenceCity,
 | |
| 			state: actor.residenceState,
 | |
| 			country: actor.residenceCountry,
 | |
| 		},
 | |
| 		scrapedAt: new Date(actor.createdAt),
 | |
| 		updatedAt: new Date(actor.updatedAt),
 | |
| 	};
 | |
| 
 | |
| 	if (actor.profiles) {
 | |
| 		const photos = actor.profiles
 | |
| 			.map((profile) => ({ entity: profile.entity, ...profile.avatar }))
 | |
| 			.filter((avatar) => avatar.id && (!curatedActor.avatar || avatar.hash !== curatedActor.avatar.hash));
 | |
| 
 | |
| 		const descriptions = actor.profiles.reduce((acc, profile) => ({
 | |
| 			...acc,
 | |
| 			...(profile.description && {
 | |
| 				[profile.descriptionHash]: {
 | |
| 					text: profile.description,
 | |
| 					entity: profile.entity,
 | |
| 				},
 | |
| 			}),
 | |
| 		}), {});
 | |
| 
 | |
| 		curatedActor.photos = Object.values(photos.reduce((acc, photo) => ({ ...acc, [photo.hash]: photo }), {}));
 | |
| 		curatedActor.descriptions = Object.values(descriptions);
 | |
| 	}
 | |
| 
 | |
| 	if (release && release.date && curatedActor.birthdate) {
 | |
| 		curatedActor.ageThen = dayjs(release.date).diff(actor.birthdate, 'year');
 | |
| 	}
 | |
| 
 | |
| 	if (actor.aliasFor) {
 | |
| 		curatedActor.aliasFor = curateActor(curatedActor.aliasFor);
 | |
| 	}
 | |
| 
 | |
| 	if (actor.stashes) {
 | |
| 		curatedActor.stashes = actor.stashes.filter(Boolean).map((stash) => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
 | |
| 	}
 | |
| 
 | |
| 	curatedActor.stashes = actor.stashes?.map((stash) => stash.stash || stash) || [];
 | |
| 
 | |
| 	return curatedActor;
 | |
| }
 | |
| 
 | |
| function curateRelease(release, type = 'scene', context = {}) {
 | |
| 	const curatedRelease = {
 | |
| 		...release,
 | |
| 		type: release.type || type,
 | |
| 		actors: [],
 | |
| 		poster: release.poster && release.poster.media,
 | |
| 		tags: release.tags ? release.tags.map((tag) => tag.tag || tag) : [],
 | |
| 		isNew: release.createdBatchId === context.lastBatch,
 | |
| 	};
 | |
| 
 | |
| 	curatedRelease.scenes = release.scenes?.filter(Boolean).map(({ scene }) => curateRelease(scene, 'scene', context)) || [];
 | |
| 	curatedRelease.movies = release.movies?.filter(Boolean).map(({ movie }) => curateRelease(movie, 'movie', context)) || [];
 | |
| 	curatedRelease.series = release.series?.filter(Boolean).map(({ serie }) => curateRelease(serie, 'serie', context)) || [];
 | |
| 	curatedRelease.chapters = release.chapters?.filter(Boolean).map((chapter) => curateRelease(chapter, 'chapter', context)) || [];
 | |
| 	curatedRelease.photos = release.photos?.filter(Boolean).map((photo) => photo.media || photo) || [];
 | |
| 	curatedRelease.caps = release.caps?.filter(Boolean).map((cap) => cap.media || cap) || [];
 | |
| 	curatedRelease.scenesPhotos = release.scenesPhotos?.filter(Boolean).map((photo) => photo.media || photo) || [];
 | |
| 	curatedRelease.covers = release.covers?.filter(Boolean).map(({ media }) => media) || [];
 | |
| 
 | |
| 	if (release.trailer) curatedRelease.trailer = release.trailer.media;
 | |
| 	if (release.teaser) curatedRelease.teaser = release.teaser.media;
 | |
| 	if (release.actors) curatedRelease.actors = release.actors.filter(Boolean).map((actor) => curateActor(actor.actor || actor, curatedRelease));
 | |
| 	if (release.directors) curatedRelease.directors = release.directors.filter(Boolean).map((director) => curateActor(director.director || director, curatedRelease));
 | |
| 	if (release.movieTags && release.movieTags.length > 0) curatedRelease.tags = release.movieTags.filter(Boolean).map(({ tag }) => tag);
 | |
| 	if (release.movieActors && release.movieActors.length > 0) curatedRelease.actors = release.movieActors.filter(Boolean).map(({ actor }) => curateActor(actor, curatedRelease));
 | |
| 	if (release.stashes) curatedRelease.stashes = release.stashes.filter(Boolean).map((stash) => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
 | |
| 
 | |
| 	if (release.productionLocation) {
 | |
| 		curatedRelease.productionLocation = {
 | |
| 			raw: release.productionLocation,
 | |
| 			city: release.productionCity,
 | |
| 			state: release.productionState,
 | |
| 			country: release.productionCountry,
 | |
| 		};
 | |
| 	}
 | |
| 
 | |
| 	return curatedRelease;
 | |
| }
 | |
| 
 | |
| function curateEntity(entity, parent, releases, context) {
 | |
| 	const curatedEntity = {
 | |
| 		...entity,
 | |
| 		children: [],
 | |
| 	};
 | |
| 
 | |
| 	if (entity.tags) curatedEntity.tags = entity.tags.map(({ tag }) => tag);
 | |
| 	if (entity.sceneTags) curatedEntity.sceneTags = entity.sceneTags;
 | |
| 
 | |
| 	if (entity.children) {
 | |
| 		if (entity.children.nodes) {
 | |
| 			curatedEntity.children = entity.children.nodes.map((childEntity) => curateEntity(childEntity, curatedEntity));
 | |
| 		}
 | |
| 
 | |
| 		curatedEntity.childrenTotal = entity.children.totalCount;
 | |
| 	}
 | |
| 
 | |
| 	if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent);
 | |
| 	if (releases) curatedEntity.releases = releases.map((release) => curateRelease(release, 'scene', context));
 | |
| 
 | |
| 	curatedEntity.sceneTotal = entity.sceneTotal;
 | |
| 
 | |
| 	return curatedEntity;
 | |
| }
 | |
| 
 | |
| function curateTag(tag, context) {
 | |
| 	const curatedTag = {
 | |
| 		...tag,
 | |
| 	};
 | |
| 
 | |
| 	if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release, 'scene', context));
 | |
| 	if (tag.banners) curatedTag.banners = tag.banners.map(({ banner }) => banner);
 | |
| 	if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media);
 | |
| 	if (tag.poster) curatedTag.poster = tag.poster.media;
 | |
| 
 | |
| 	return curatedTag;
 | |
| }
 | |
| 
 | |
| function curateStash(stash, context) {
 | |
| 	const curatedStash = stash;
 | |
| 
 | |
| 	if (stash.scenes || stash.scenesConnection?.scenes) {
 | |
| 		curatedStash.sceneTotal = stash.scenesConnection?.totalCount || null;
 | |
| 		curatedStash.scenes = (stash.scenesConnection?.scenes || stash.scenes).map((item) => ({
 | |
| 			...item,
 | |
| 			scene: curateRelease(item.scene, 'scene', context),
 | |
| 		}));
 | |
| 	}
 | |
| 
 | |
| 	if (stash.actors || stash.actorsConnection?.actors) {
 | |
| 		curatedStash.actorTotal = stash.actorsConnection?.totalCount || null;
 | |
| 		curatedStash.actors = (stash.actorsConnection?.actors || stash.actors).map((item) => ({
 | |
| 			...item,
 | |
| 			actor: curateActor(item.actor),
 | |
| 		}));
 | |
| 	}
 | |
| 
 | |
| 	if (stash.movies || stash.moviesConnection?.movies) {
 | |
| 		curatedStash.movieTotal = stash.moviesConnection?.totalCount || null;
 | |
| 		curatedStash.movies = (stash.moviesConnection?.movies || stash.movies).map((item) => ({
 | |
| 			...item,
 | |
| 			movie: curateRelease(item.movie, 'movie', context),
 | |
| 		}));
 | |
| 	}
 | |
| 
 | |
| 	return curatedStash;
 | |
| }
 | |
| 
 | |
| function curateAlert(alert) {
 | |
| 	if (!alert) {
 | |
| 		return null;
 | |
| 	}
 | |
| 
 | |
| 	const curatedAlert = alert;
 | |
| 
 | |
| 	if (alert.actors) {
 | |
| 		curatedAlert.actors = alert.actors.map((actor) => curateActor(actor.actor || actor));
 | |
| 	}
 | |
| 
 | |
| 	if (alert.tags) {
 | |
| 		curatedAlert.tags = alert.tags.map((tag) => curateTag(tag.tag || tag));
 | |
| 	}
 | |
| 
 | |
| 	if (alert.entity) {
 | |
| 		curatedAlert.entity = curateEntity(alert.entity.entity || alert.entity);
 | |
| 	}
 | |
| 
 | |
| 	if (alert.entities) {
 | |
| 		curatedAlert.entities = alert.entities.map((entity) => curateEntity(entity.entity || entity));
 | |
| 	}
 | |
| 
 | |
| 	if (alert.stashes) {
 | |
| 		curatedAlert.stashes = alert.stashes.map((stash) => curateStash(stash.stash || stash));
 | |
| 	}
 | |
| 
 | |
| 	return curatedAlert;
 | |
| }
 | |
| 
 | |
| function curateUser(user) {
 | |
| 	if (!user) {
 | |
| 		return null;
 | |
| 	}
 | |
| 
 | |
| 	const curatedUser = user;
 | |
| 
 | |
| 	if (user.stashes) {
 | |
| 		curatedUser.stashes = user.stashes.map((stash) => curateStash(stash.stash || stash));
 | |
| 	}
 | |
| 
 | |
| 	if (user.alerts) {
 | |
| 		curatedUser.alerts = user.alerts.map((alert) => curateAlert(alert.alert || alert));
 | |
| 	}
 | |
| 
 | |
| 	return curatedUser;
 | |
| }
 | |
| 
 | |
| function curateNotification(notification) {
 | |
| 	const curatedNotification = notification;
 | |
| 
 | |
| 	curatedNotification.scene = curateRelease(notification.scene);
 | |
| 
 | |
| 	if (notification.alert) {
 | |
| 		curatedNotification.alert = curateAlert(notification.alert.alert || notification.alert);
 | |
| 	}
 | |
| 
 | |
| 	return curatedNotification;
 | |
| }
 | |
| 
 | |
| export {
 | |
| 	curateActor,
 | |
| 	curateEntity,
 | |
| 	curateRelease,
 | |
| 	curateNotification,
 | |
| 	curateTag,
 | |
| 	curateStash,
 | |
| 	curateUser,
 | |
| };
 |