From 2d050be1a5a98895faf335091bb6b635bb0d79e2 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:54 +0200 Subject: [PATCH] Added support for redd.it PNG. --- src/extensions.json | 7 +++++++ src/interpolate.js | 7 +------ src/methods/redditImage.js | 9 ++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 src/extensions.json diff --git a/src/extensions.json b/src/extensions.json new file mode 100644 index 0000000..995904f --- /dev/null +++ b/src/extensions.json @@ -0,0 +1,7 @@ +{ + "image/jpeg": ".jpg", + "image/png": ".png", + "image/gif": ".gif", + "video/mp4": ".mp4", + "video/webm": ".webm" +} diff --git a/src/interpolate.js b/src/interpolate.js index 70e3755..9baa6a7 100644 --- a/src/interpolate.js +++ b/src/interpolate.js @@ -5,12 +5,7 @@ const path = require('path'); const url = require('url'); const dateFns = require('date-fns'); -const extensions = { - 'image/jpeg': '.jpg', - 'image/gif': '.gif', - 'video/mp4': '.mp4', - 'video/webm': '.webm' -}; +const extensions = require('./extensions.json'); function interpolate(pattern, user, post, item) { const dateFormat = config.library.dateFormat || 'YYYYMMDD'; diff --git a/src/methods/redditImage.js b/src/methods/redditImage.js index 791e81e..83690f4 100644 --- a/src/methods/redditImage.js +++ b/src/methods/redditImage.js @@ -2,8 +2,15 @@ const util = require('util'); const config = require('config'); +const path = require('path'); const fetch = require('node-fetch'); +const extensions = require('../extensions.json'); + +function reverseLookup(extension) { + return Object.keys(extensions).find(mime => extensions[mime] === extension); +}; + function redditImage(post) { return Promise.resolve({ album: null, @@ -12,7 +19,7 @@ function redditImage(post) { url: post.url, title: post.title, datetime: post.datetime, - type: 'image/jpeg', + type: reverseLookup(path.extname(post.url)), original: post }] });