forked from DebaucheryLibrarian/traxxx
Not using media hash subdirs for S3 uploads. Updated video player for S3.
This commit is contained in:
15
src/media.js
15
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 {
|
||||
|
||||
Reference in New Issue
Block a user