Merge pull request #88 from FluxIndustries/master

pull/90/head
Josh Moore 3 years ago committed by GitHub
commit 0fd12f5504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.github/README.md vendored

@ -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

@ -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));

@ -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;

@ -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(/&timestamp/g, formatTimestamp(timestamp));
.replace(/&timestamp/g, formatTimestamp(timestamp, timeoffset));
}
function getDatedDirname() {

Loading…
Cancel
Save