forked from DebaucheryLibrarian/traxxx
Fixed S3 display support for movies.
This commit is contained in:
33
src/media.js
33
src/media.js
@@ -26,7 +26,7 @@ const { get } = require('./utils/qu');
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
const streamQueue = taskQueue();
|
||||
|
||||
const endpoint = new AWS.Endpoint('s3.wasabisys.com');
|
||||
const endpoint = new AWS.Endpoint('s3.eu-central-1.wasabisys.com');
|
||||
|
||||
const s3 = new AWS.S3({
|
||||
// region: 'eu-central-1',
|
||||
@@ -869,6 +869,29 @@ async function associateAvatars(profiles) {
|
||||
return profilesWithAvatarIds;
|
||||
}
|
||||
|
||||
async function deleteS3Objects(media) {
|
||||
const objects = media
|
||||
.map(item => [
|
||||
{ Key: item.path },
|
||||
{ Key: item.thumbnail },
|
||||
{ Key: item.lazy },
|
||||
])
|
||||
.flat()
|
||||
.filter(item => item.Key);
|
||||
|
||||
const status = await s3.deleteObjects({
|
||||
Bucket: config.s3.bucket,
|
||||
Delete: {
|
||||
Objects: objects,
|
||||
Quiet: false,
|
||||
},
|
||||
}).promise();
|
||||
|
||||
logger.info(`Removed ${status.Deleted.length} media files from S3 bucket '${config.s3.bucket}', ${status.Errors.length} errors`);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
async function flushOrphanedMedia() {
|
||||
const orphanedMedia = await knex('media')
|
||||
.where('is_sfw', false)
|
||||
@@ -896,10 +919,10 @@ async function flushOrphanedMedia() {
|
||||
)
|
||||
.whereRaw('associations.media_id = media.id'),
|
||||
)
|
||||
.returning(['media.path', 'media.thumbnail', 'media.lazy'])
|
||||
.returning(['media.id', 'media.is_s3', 'media.path', 'media.thumbnail', 'media.lazy'])
|
||||
.delete();
|
||||
|
||||
await Promise.all(orphanedMedia.map(media => Promise.all([
|
||||
await Promise.all(orphanedMedia.filter(media => !media.is_s3).map(media => Promise.all([
|
||||
media.path && fsPromises.unlink(path.join(config.media.path, media.path)).catch(() => { /* probably file not found */ }),
|
||||
media.thumbnail && fsPromises.unlink(path.join(config.media.path, media.thumbnail)).catch(() => { /* probably file not found */ }),
|
||||
media.lazy && fsPromises.unlink(path.join(config.media.path, media.lazy)).catch(() => { /* probably file not found */ }),
|
||||
@@ -907,6 +930,10 @@ async function flushOrphanedMedia() {
|
||||
|
||||
logger.info(`Removed ${orphanedMedia.length} media files from database and storage`);
|
||||
|
||||
if (config.s3.enabled) {
|
||||
await deleteS3Objects(orphanedMedia.filter(media => media.is_s3));
|
||||
}
|
||||
|
||||
await fsPromises.rmdir(path.join(config.media.path, 'temp'), { recursive: true });
|
||||
|
||||
logger.info('Cleared temporary media directory');
|
||||
|
||||
@@ -200,8 +200,6 @@ function scrapeAll(html, site, networkUrl, hasTeaser = true) {
|
||||
];
|
||||
}
|
||||
|
||||
console.log(release);
|
||||
|
||||
return release;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user