Added dark and SFW modes.

This commit is contained in:
2020-03-23 01:43:49 +01:00
parent fdb2b132f6
commit 58ead7b426
288 changed files with 1316 additions and 156 deletions

View File

@@ -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,
};

View File

@@ -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
View 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;