From c1829c64c2465bf98cb8b89c78376e5976cf680c Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Tue, 23 Feb 2021 00:54:19 +0100 Subject: [PATCH] Not using media hash subdirs for S3 uploads. Updated video player for S3. --- assets/components/video/player.vue | 2 +- assets/css/_theme.scss | 2 +- src/media.js | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/components/video/player.vue b/assets/components/video/player.vue index cf055b5a..429ff9c7 100644 --- a/assets/components/video/player.vue +++ b/assets/components/video/player.vue @@ -7,7 +7,7 @@ @pause="$emit('pause')" > diff --git a/assets/css/_theme.scss b/assets/css/_theme.scss index c269d9a8..e296dfdf 100644 --- a/assets/css/_theme.scss +++ b/assets/css/_theme.scss @@ -44,7 +44,7 @@ $breakpoint4: 1500px; --text-contrast: #fff; --background: var(--background-light); - --background-dim: #fafafa; + --background-dim: #f5f5f5; --background-soft: #fdfdfd; --profile: #222; diff --git a/src/media.js b/src/media.js index de92bc85..4c3c4289 100644 --- a/src/media.js +++ b/src/media.js @@ -328,6 +328,8 @@ async function storeS3Object(filepath, media) { await fsPromises.unlink(fullFilepath); + logger.silly(`Uploaded '${media.id}' from ${media.src} to S3 bucket '${status.Bucket}' at ${status.Location}`); + return status; } @@ -371,10 +373,10 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil logger.silly(`Storing permanent media files for ${media.id} from ${media.src} at ${filepath}`); try { - const thumbdir = path.join(media.role, 'thumbs', hashDir, hashSubDir); + const thumbdir = config.s3.enabled ? path.join(media.role, 'thumbs') : path.join(media.role, 'thumbs', hashDir, hashSubDir); const thumbpath = path.join(thumbdir, filename); - const lazydir = path.join(media.role, 'lazy', hashDir, hashSubDir); + const lazydir = config.s3.enabled ? path.join(media.role, 'lazy') : path.join(media.role, 'lazy', hashDir, hashSubDir); const lazypath = path.join(lazydir, filename); await Promise.all([ @@ -459,13 +461,13 @@ async function storeFile(media, options) { try { const hashDir = media.meta.hash.slice(0, 2); const hashSubDir = media.meta.hash.slice(2, 4); - const hashFilename = media.meta.hash.slice(4); + const hashFilename = config.s3.enabled ? media.meta.hash : media.meta.hash.slice(4); const filename = media.quality ? `${hashFilename}_${media.quality}.${media.meta.extension}` : `${hashFilename}.${media.meta.extension}`; - const filedir = path.join(media.role, hashDir, hashSubDir); + const filedir = config.s3.enabled ? media.role : path.join(media.role, hashDir, hashSubDir); const filepath = path.join(filedir, filename); if (argv.force) { @@ -493,6 +495,11 @@ async function storeFile(media, options) { // move temp file to permanent location await fsPromises.rename(media.file.path, path.join(config.media.path, filepath)); + if (config.s3.enabled) { + // upload the file to S3 storage, will remove original + await storeS3Object(filepath, media); + } + logger.silly(`Stored permanent media file for ${media.id} from ${media.src} at ${filepath}`); return {