Fixed failed hash duplicate source breaking media association.

This commit is contained in:
DebaucheryLibrarian 2023-07-02 23:59:49 +02:00
parent a2ff12a636
commit 13d02a44e5
3 changed files with 66 additions and 14 deletions

View File

@ -353,8 +353,6 @@ async function extractSource(baseSource, { existingExtractMediaByUrl }) {
if (typeof baseSource.defer === 'function') {
const src = await baseSource.defer();
console.log('DEFERED', src);
return {
...baseSource,
...toBaseSource(src),
@ -909,7 +907,7 @@ async function associateReleaseMedia(releases, type = 'release') {
.reduce((acc, [releaseId, releaseBaseMedias]) => {
releaseBaseMedias.forEach((baseMedia) => {
const media = storedMediasById[baseMedia.id];
const mediaId = media?.use || media?.entry?.id;
const mediaId = (storedMediasById[media?.use] && media?.use) || media?.entry?.id;
if (mediaId) {
acc.push({

View File

@ -217,7 +217,7 @@ function gender() {
]);
}
function actors(release) {
function generateActors(release) {
const length = release.tags.some((tag) => ['dp', 'dap', 'gangbang'].includes(tag))
? Math.floor(Math.random() * 6) + 3
: Math.floor(Math.random() * 3) + 2;
@ -233,13 +233,20 @@ function actors(release) {
}
async function beforeFetchLatest() {
const tags = await knex('tags')
const [actors, tags] = await Promise.all([
knex('actors')
.select('name')
.orderByRaw('random()')
.limit(1000)
.pluck('name'),
knex('tags')
.select('name')
.where('priority', '>', 7)
.orderByRaw('random()')
.pluck('name');
.pluck('name'),
]);
return { tags };
return { actors, tags };
}
async function fetchLatest(entity, page, options) {
@ -269,13 +276,13 @@ async function fetchLatest(entity, page, options) {
release.photos = photos.map((photo) => `http://${config.web.host}:${config.web.port}/img/${photo}?id=${nanoid()}`);
}
release.tags = shuffle(options.beforeFetchLatest.tags).slice(faker.datatype.number({ min: 3, max: 20 }));
release.tags = shuffle(options.beforeFetchLatest.tags).slice(0, faker.datatype.number({ min: 3, max: 20 }));
// release.actors = [...generateActors(release), null]; // include empty actor to ensure proper handling
release.actors = shuffle(options.beforeFetchLatest.actors).slice(0, faker.datatype.number(release.tags.some((tag) => ['dp', 'dap', 'gangbang'].includes(tag)) ? { min: 3, max: 6 } : { min: 2, max: 3 }));
release.actors = [...actors(release), null]; // include empty actor to ensure proper handling
release.title = title(release);
console.log(release.entryId);
return release;
}));
}

47
src/tools/names.js Normal file
View File

@ -0,0 +1,47 @@
'use strict';
const pickRandom = require('../utils/pick-random');
const firstMale = [
'John',
'James',
'Biggus',
'Mick',
];
const lastMale = [
'Dickus',
'Strong',
'Slayer',
'Gun',
'Pistol',
];
const firstFemale = [
'Kimmy',
'Summer',
'Jessica',
'Rose',
'Sky',
'Skye',
];
const lastFemale = [
'Olsen',
'Flower',
'Star',
'Dior',
];
const lastGeneric = [
'Steele',
'White',
];
function init() {
const names = Array.from({ length: 1000 }, () => `${pickRandom([...firstMale, ...firstFemale])} ${pickRandom([...lastMale, ...lastFemale, ...lastGeneric])}`);
console.log(names);
}
init();