forked from DebaucheryLibrarian/traxxx
Added dark and SFW modes.
This commit is contained in:
48
src/media.js
48
src/media.js
@@ -22,11 +22,32 @@ function getHash(buffer) {
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
async function createThumbnail(buffer) {
|
||||
async function getMeta(buffer, withHash = false) {
|
||||
try {
|
||||
const { entropy } = await sharp(buffer).stats();
|
||||
const { width, height, size } = await sharp(buffer).metadata();
|
||||
|
||||
const hash = withHash && getHash(buffer);
|
||||
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
size,
|
||||
entropy,
|
||||
hash,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to retrieve image entropy, using 7.5: ${error.message}`);
|
||||
|
||||
return 7.5;
|
||||
}
|
||||
}
|
||||
|
||||
async function createThumbnail(buffer, height = config.media.thumbnailSize) {
|
||||
try {
|
||||
const thumbnail = sharp(buffer)
|
||||
.resize({
|
||||
height: config.media.thumbnailSize,
|
||||
height,
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.jpeg({
|
||||
@@ -101,24 +122,6 @@ function pickQuality(items) {
|
||||
return item || items[0];
|
||||
}
|
||||
|
||||
async function getMeta(buffer) {
|
||||
try {
|
||||
const { entropy } = await sharp(buffer).stats();
|
||||
const { width, height, size } = await sharp(buffer).metadata();
|
||||
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
size,
|
||||
entropy,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to retrieve image entropy, using 7.5: ${error.message}`);
|
||||
|
||||
return 7.5;
|
||||
}
|
||||
}
|
||||
|
||||
async function extractItem(source) {
|
||||
// const res = await bhttp.get(source.src);
|
||||
const res = await get(source.src);
|
||||
@@ -434,7 +437,10 @@ async function associateMedia(sourcesByTargetId, mediaBySource, domain, role, pr
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
associateMedia,
|
||||
createThumbnail,
|
||||
getHash,
|
||||
getMeta,
|
||||
pluckItems,
|
||||
storeMedia,
|
||||
associateMedia,
|
||||
};
|
||||
|
||||
17
src/tags.js
17
src/tags.js
@@ -8,11 +8,11 @@ async function matchReleaseTags(releases) {
|
||||
.map(release => release.tags).flat()
|
||||
.filter(Boolean);
|
||||
|
||||
const casedTags = Array.from(new Set(
|
||||
const casedTags = [...new Set(
|
||||
rawTags
|
||||
.concat(rawTags.map(tag => tag.toLowerCase()))
|
||||
.concat(rawTags.map(tag => tag.toUpperCase())),
|
||||
));
|
||||
)];
|
||||
|
||||
const tagEntries = await knex('tags')
|
||||
.select('tags.id', 'tags.name', 'tags.alias_for')
|
||||
@@ -48,17 +48,18 @@ function buildReleaseTagAssociations(releases, tagIdsBySlug, siteTagIdsBySiteId)
|
||||
const tagAssociations = releases
|
||||
.map((release) => {
|
||||
const siteTagIds = siteTagIdsBySiteId[release.site.id];
|
||||
const releaseTags = release.tags || [];
|
||||
|
||||
const releaseTagIds = release.tags.every(tag => typeof tag === 'number')
|
||||
? release.tags // obsolete scraper returned pre-matched tags
|
||||
: release.tags.map(tag => tagIdsBySlug[slugify(tag)]);
|
||||
const releaseTagIds = releaseTags.every(tag => typeof tag === 'number')
|
||||
? releaseTags // obsolete scraper returned pre-matched tags
|
||||
: releaseTags.map(tag => tagIdsBySlug[slugify(tag)]);
|
||||
|
||||
return Array.from(new Set(
|
||||
return [...new Set(
|
||||
// filter duplicates and empties
|
||||
releaseTagIds
|
||||
.concat(siteTagIds)
|
||||
.filter(Boolean),
|
||||
))
|
||||
)]
|
||||
.map(tagId => ({
|
||||
release_id: release.id,
|
||||
tag_id: tagId,
|
||||
@@ -93,7 +94,7 @@ async function associateTags(releases) {
|
||||
const siteTagIdsBySiteId = await getSiteTags(releases);
|
||||
|
||||
const tagAssociations = buildReleaseTagAssociations(releases, tagIdsBySlug, siteTagIdsBySiteId);
|
||||
const uniqueAssociations = extractUniqueAssociations(tagAssociations);
|
||||
const uniqueAssociations = await extractUniqueAssociations(tagAssociations);
|
||||
|
||||
await knex('releases_tags').insert(uniqueAssociations);
|
||||
}
|
||||
|
||||
14
src/utils/shuffle.js
Normal file
14
src/utils/shuffle.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
function shuffle(array) {
|
||||
const shuffledArray = [...array];
|
||||
|
||||
for (let i = array.length - 1; i > 0; i -= 1) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
||||
}
|
||||
|
||||
return shuffledArray;
|
||||
}
|
||||
|
||||
module.exports = shuffle;
|
||||
Reference in New Issue
Block a user