From 1f3e0714fbd951ddd4fa15cb927c5eb16df35284 Mon Sep 17 00:00:00 2001 From: FluxIndustries <88303769+FluxIndustries@users.noreply.github.com> Date: Mon, 4 Oct 2021 22:47:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=9B=20added=20a=20header=20for=20setti?= =?UTF-8?q?ng=20the=20time=20offset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/README.md | 1 + routers/resource.js | 10 +++++----- routers/upload.js | 3 +++ utils.js | 8 ++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/README.md b/.github/README.md index 0c04dd7..4003260 100644 --- a/.github/README.md +++ b/.github/README.md @@ -234,6 +234,7 @@ If you need to override a specific part of the config to be different from the g | **`X-Ass-Domain`** | Override the domain returned for the clipboard (useful for multi-domain hosts) | | **`X-Ass-Access`** | Override the generator used for the resource URL. Must be one of: `original`, `zws`, `gfycat`, or `random` ([see above](#access-types)) | | **`X-Ass-Gfycat`** | Override the length of Gfycat ID's. Defaults to `2` | +| **`X-Ass-Timeoffset`** | Override the timestamp offset. Defaults to `UTC+0` | ### Fancy embeds diff --git a/routers/resource.js b/routers/resource.js index 5542f8c..68b6e0b 100644 --- a/routers/resource.js +++ b/routers/resource.js @@ -39,7 +39,7 @@ router.get('/', (req, res, next) => data.get(req.ass.resourceId).then((fileData) title: escape(fileData.originalname), mimetype: fileData.mimetype, uploader: users[fileData.token].username, - timestamp: formatTimestamp(fileData.timestamp), + timestamp: formatTimestamp(fileData.timestamp, fileData.timeoffset), size: formatBytes(fileData.size), color: getResourceColor(fileData.opengraph.color || null, fileData.vibrant), resourceAttr: { src: getDirectUrl(resourceId) }, @@ -47,7 +47,7 @@ router.get('/', (req, res, next) => data.get(req.ass.resourceId).then((fileData) oembedUrl: `${getTrueHttp()}${getTrueDomain()}/${resourceId}/oembed`, ogtype: fileData.is.video ? 'video.other' : fileData.is.image ? 'image' : 'website', urlType: `og:${fileData.is.video ? 'video' : fileData.is.audio ? 'audio' : 'image'}`, - opengraph: replaceholder(ogs.join('\n'), fileData.size, fileData.timestamp, fileData.originalname), + opengraph: replaceholder(ogs.join('\n'), fileData.size, fileData.timestamp, fileData.timeoffset, fileData.originalname), viewDirect }); }).catch(next)); @@ -85,14 +85,14 @@ router.get('/thumbnail', (req, res, next) => // https://old.reddit.com/r/discordapp/comments/82p8i6/a_basic_tutorial_on_how_to_get_the_most_out_of/ router.get('/oembed', (req, res, next) => data.get(req.ass.resourceId) - .then(({ opengraph, is, size, timestamp, originalname }) => + .then(({ opengraph, is, size, timestamp, timeoffset, originalname }) => res.type('json').send({ version: '1.0', type: is.video ? 'video' : is.image ? 'photo' : 'link', author_url: opengraph.authorUrl, provider_url: opengraph.providerUrl, - author_name: replaceholder(opengraph.author || '', size, timestamp, originalname), - provider_name: replaceholder(opengraph.provider || '', size, timestamp, originalname) + author_name: replaceholder(opengraph.author || '', size, timestamp, timeoffset, originalname), + provider_name: replaceholder(opengraph.provider || '', size, timestamp, timeoffset, originalname) })) .catch(next)); diff --git a/routers/upload.js b/routers/upload.js index a09cc55..d334f3a 100644 --- a/routers/upload.js +++ b/routers/upload.js @@ -47,6 +47,9 @@ router.post('/', (req, res, next) => { // Get the uploaded time in milliseconds req.file.timestamp = DateTime.now().toMillis(); + // Save the timezone offset + req.file.timeoffset = req.headers['x-ass-timeoffset'] || "UTC+0"; + // Keep track of the token that uploaded the resource req.file.token = req.token; diff --git a/utils.js b/utils.js index 00e5502..1e27afc 100755 --- a/utils.js +++ b/utils.js @@ -45,8 +45,8 @@ function getResourceColor(colorValue, vibrantValue) { return colorValue === '&random' ? randomHexColour() : colorValue === '&vibrant' ? vibrantValue : colorValue; } -function formatTimestamp(timestamp) { - return DateTime.fromMillis(timestamp).toLocaleString(DateTime.DATETIME_MED); +function formatTimestamp(timestamp, timeoffset) { + return DateTime.fromMillis(timestamp).setZone(timeoffset).toLocaleString(DateTime.DATETIME_MED); } function formatBytes(bytes, decimals = 2) { // skipcq: JS-0074 @@ -56,11 +56,11 @@ function formatBytes(bytes, decimals = 2) { // skipcq: JS-0074 return parseFloat((bytes / Math.pow(KILOBYTES, i)).toFixed(decimals < 0 ? 0 : decimals)).toString().concat(` ${sizes[i]}`); } -function replaceholder(data, size, timestamp, originalname) { +function replaceholder(data, size, timestamp, timeoffset, originalname) { return data .replace(/&size/g, formatBytes(size)) .replace(/&filename/g, originalname) - .replace(/×tamp/g, formatTimestamp(timestamp)); + .replace(/×tamp/g, formatTimestamp(timestamp, timeoffset)); } function getDatedDirname() {