Fixed S3 display support for movies.

This commit is contained in:
DebaucheryLibrarian 2021-02-23 01:30:38 +01:00
parent c1829c64c2
commit 2b5aac7633
7 changed files with 48 additions and 8 deletions

View File

@ -59,7 +59,7 @@
<a <a
v-for="cover in release.covers" v-for="cover in release.covers"
:key="`cover-${cover.id}`" :key="`cover-${cover.id}`"
:href="`${config.media.mediaPath}/${cover.path}`" :href="getPath(cover)"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
> >

View File

@ -84,7 +84,7 @@
<span class="movie-title">{{ movie.title }}</span> <span class="movie-title">{{ movie.title }}</span>
<img <img
v-if="movie.covers.length > 0" v-if="movie.covers.length > 0"
:src="`/media/${movie.covers[0].thumbnail}`" :src="getPath(movie.covers[0], 'thumbnail')"
class="movie-cover" class="movie-cover"
> >
</router-link> </router-link>

View File

@ -315,6 +315,7 @@ const releaseFragment = `
path path
thumbnail thumbnail
lazy lazy
isS3
comment comment
sfw: sfwMedia { sfw: sfwMedia {
id id

View File

@ -103,6 +103,7 @@ function initReleasesActions(store, router) {
path path
thumbnail thumbnail
lazy lazy
isS3
sfw: sfwMedia { sfw: sfwMedia {
id id
path path
@ -157,6 +158,16 @@ function initReleasesActions(store, router) {
path path
thumbnail thumbnail
lazy lazy
isS3
}
}
posters: moviesPosterByMovieId {
media {
id
path
thumbnail
lazy
isS3
} }
} }
covers: moviesCovers { covers: moviesCovers {
@ -165,12 +176,14 @@ function initReleasesActions(store, router) {
path path
thumbnail thumbnail
lazy lazy
isS3
} }
} }
trailer: moviesTrailerByMovieId { trailer: moviesTrailerByMovieId {
media { media {
id id
path path
isS3
} }
} }
scenes: moviesScenes { scenes: moviesScenes {
@ -189,6 +202,7 @@ function initReleasesActions(store, router) {
path path
thumbnail thumbnail
lazy lazy
isS3
comment comment
sfw: sfwMedia { sfw: sfwMedia {
id id

View File

@ -901,7 +901,7 @@ exports.up = knex => Promise.resolve()
.references('id') .references('id')
.inTable('media'); .inTable('media');
table.unique(['movie_id', 'media_id']); table.unique('movie_id');
})) }))
.then(() => knex.schema.createTable('clips', (table) => { .then(() => knex.schema.createTable('clips', (table) => {
table.increments('id', 16); table.increments('id', 16);

View File

@ -26,7 +26,7 @@ const { get } = require('./utils/qu');
const pipeline = util.promisify(stream.pipeline); const pipeline = util.promisify(stream.pipeline);
const streamQueue = taskQueue(); 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({ const s3 = new AWS.S3({
// region: 'eu-central-1', // region: 'eu-central-1',
@ -869,6 +869,29 @@ async function associateAvatars(profiles) {
return profilesWithAvatarIds; 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() { async function flushOrphanedMedia() {
const orphanedMedia = await knex('media') const orphanedMedia = await knex('media')
.where('is_sfw', false) .where('is_sfw', false)
@ -896,10 +919,10 @@ async function flushOrphanedMedia() {
) )
.whereRaw('associations.media_id = media.id'), .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(); .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.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.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 */ }), 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`); 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 }); await fsPromises.rmdir(path.join(config.media.path, 'temp'), { recursive: true });
logger.info('Cleared temporary media directory'); logger.info('Cleared temporary media directory');

View File

@ -200,8 +200,6 @@ function scrapeAll(html, site, networkUrl, hasTeaser = true) {
]; ];
} }
console.log(release);
return release; return release;
}); });
} }