From 717b788e83c6f5c5fc69d45f167410137d8fe2b3 Mon Sep 17 00:00:00 2001 From: tycrek Date: Sat, 24 Dec 2022 20:40:33 -0700 Subject: [PATCH 1/2] feat: added server-side embed configuration (closes #173) --- src/routers/upload.ts | 21 +++++++++++++-------- src/types/json.d.ts | 10 ++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/routers/upload.ts b/src/routers/upload.ts index e1f2f4b..0a5cddb 100644 --- a/src/routers/upload.ts +++ b/src/routers/upload.ts @@ -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 diff --git a/src/types/json.d.ts b/src/types/json.d.ts index 5525320..da3fba6 100644 --- a/src/types/json.d.ts +++ b/src/types/json.d.ts @@ -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 + } } From 7370303b7a7123c0b154e121619b000052c0c0e1 Mon Sep 17 00:00:00 2001 From: tycrek Date: Sat, 24 Dec 2022 20:40:47 -0700 Subject: [PATCH 2/2] docs: explain how to use server-side embeds --- .github/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/README.md b/.github/README.md index 5acbfcc..ead4e41 100644 --- a/.github/README.md +++ b/.github/README.md @@ -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 | | **`×tamp`** | 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: