Merge branch 'master' into ts-attempt-over-9000

pull/62/head
tycrek 3 years ago
commit b2ffc44972
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

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

@ -43,7 +43,7 @@ router.get('/', (req: AssRequest, res: AssResponse, next) => data.get(req.ass?.r
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),
// todo: figure out how to not ignore this
// @ts-ignore
@ -53,7 +53,7 @@ router.get('/', (req: AssRequest, res: AssResponse, next) => data.get(req.ass?.r
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));
@ -99,10 +99,10 @@ router.get('/oembed', (req: AssRequest, res: AssResponse, next) =>
provider_url: fileData.opengraph.providerUrl,
// todo: figure out how to not ignore this
// @ts-ignore
author_name: replaceholder(fileData.opengraph.author || '', fileData.size, fileData.timestamp, fileData.originalname),
author_name: replaceholder(fileData.opengraph.author || '', fileData.size, fileData.timestamp, fileData.timeoffset, fileData.originalname),
// todo: figure out how to not ignore this
// @ts-ignore
provider_name: replaceholder(fileData.opengraph.provider || '', fileData.size, fileData.timestamp, fileData.originalname)
provider_name: replaceholder(fileData.opengraph.provider || '', fileData.size, fileData.timestamp, fileData.timeoffset, fileData.originalname)
}))
.catch(next));

@ -49,6 +49,9 @@ router.post('/', (req: AssRequest, res: AssResponse, next: Function) => {
// 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 ?? '';

@ -47,8 +47,8 @@ export function getResourceColor(colorValue: string, vibrantValue: string) {
return colorValue === '&random' ? randomHexColour() : colorValue === '&vibrant' ? vibrantValue : colorValue;
}
export function formatTimestamp(timestamp: number) {
return DateTime.fromMillis(timestamp).toLocaleString(DateTime.DATETIME_MED);
export function formatTimestamp(timestamp: number, timeoffset) {
return DateTime.fromMillis(timestamp).setZone(timeoffset).toLocaleString(DateTime.DATETIME_MED);
}
export function formatBytes(bytes: number, decimals = 2) { // skipcq: JS-0074
@ -58,11 +58,11 @@ export function formatBytes(bytes: number, decimals = 2) { // skipcq: JS-0074
return parseFloat((bytes / Math.pow(KILOBYTES, i)).toFixed(decimals < 0 ? 0 : decimals)).toString().concat(` ${sizes[i]}`);
}
export function replaceholder(data: string, size: number, timestamp: number, originalname: string) {
export function replaceholder(data: string, size: number, timestamp: number, timeoffset, originalname: string) {
return data
.replace(/&size/g, formatBytes(size))
.replace(/&filename/g, originalname)
.replace(/&timestamp/g, formatTimestamp(timestamp));
.replace(/&timestamp/g, formatTimestamp(timestamp, timeoffset));
}
export function getDatedDirname() {

Loading…
Cancel
Save