feat: added server side embed configs

Merge branch '0.14.0/server-side-embed-config' into 0.14.0/stage
pull/188/head
tycrek 2 years ago
commit d7b57e5e95
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

16
.github/README.md vendored

@ -247,7 +247,7 @@ If you primarily share media on Discord, you can add these additional (optional)
| Header | Purpose |
| ------ | ------- |
| **`X-Ass-OG-Title`** | Large text shown above your media |
| **`X-Ass-OG-Title`** | Large text shown above your media. Required for embeds to appear on desktop. |
| **`X-Ass-OG-Description`** | Small text shown below the title but above the media (does not show up on videos) |
| **`X-Ass-OG-Author`** | Small text shown above the title |
| **`X-Ass-OG-Author-Url`** | URL to open when the Author is clicked |
@ -265,6 +265,20 @@ You can insert certain metadata into your embeds with these placeholders:
| **`&filename`** | The original filename of the uploaded file |
| **`&timestamp`** | The timestamp of when the file was uploaded (example: `Oct 14, 1983, 1:30 PM`) |
#### Server-side embed configuration
You may also specify a default embed config on the server. Keep in mind that if users specify the `X-Ass-OG-Title` header, the server-side config will be ignored. To configure the server-side embed, create a new file in the `share/` directory named `embed.json`. Available options are:
- **`title`**
- `description`
- `author`
- `authorUrl`
- `provider`
- `providerUrl`
- `color`
Their values are equivalent to the headers listed above.
### Webhooks
You may use Discord webhooks as an easy way to keep track of your uploads. The first step is to [create a new Webhook]. You only need to follow the first section, **Making a Webhook**. Once you are done that, click **Copy Webhook URL**. Finally, add these headers to your custom uploader:

@ -1,5 +1,5 @@
import { ErrWrap } from '../types/definitions';
import { Config, MagicNumbers, Package } from 'ass-json';
import { Config, MagicNumbers, Package, ServerSideEmbed } from 'ass-json';
import fs from 'fs-extra';
import bb from 'express-busboy';
@ -65,15 +65,20 @@ router.post('/', (req: Request, res: Response, next: Function) => {
// Keep track of the token that uploaded the resource
req.file.uploader = findFromToken(req.token)?.unid ?? '';
// Load server-side embed config, if it exists
const ssePath = path('share/embed.json');
const sse: ServerSideEmbed | undefined = fs.existsSync(ssePath) ? fs.readJsonSync(path('share/embed.json')) : undefined;
const useSse = sse && sse.title != undefined && sse.title != '';
// Attach any embed overrides, if necessary
req.file.opengraph = {
title: req.headers['x-ass-og-title'],
description: req.headers['x-ass-og-description'],
author: req.headers['x-ass-og-author'],
authorUrl: req.headers['x-ass-og-author-url'],
provider: req.headers['x-ass-og-provider'],
providerUrl: req.headers['x-ass-og-provider-url'],
color: req.headers['x-ass-og-color']
title: useSse ? sse.title : req.headers['x-ass-og-title'],
description: useSse ? sse.description : req.headers['x-ass-og-description'],
author: useSse ? sse.author : req.headers['x-ass-og-author'],
authorUrl: useSse ? sse.authorUrl : req.headers['x-ass-og-author-url'],
provider: useSse ? sse.provider : req.headers['x-ass-og-provider'],
providerUrl: useSse ? sse.providerUrl : req.headers['x-ass-og-provider-url'],
color: useSse ? sse.color : req.headers['x-ass-og-color']
};
// Fix spaces in originalname

@ -52,4 +52,14 @@ declare module 'ass-json' {
version: string
homepage: string
}
interface ServerSideEmbed {
title: string
description?: string
author?: string
authorUrl?: string
provider?: string
providerUrl?: string
color?: string
}
}

Loading…
Cancel
Save