embed templates

pull/249/head
xwashere 7 months ago
parent 81cb4aa7e3
commit 7af42c7c89
No known key found for this signature in database
GPG Key ID: 042F8BFA1B0EF93B

@ -0,0 +1,26 @@
import { EmbedTemplate, EmbedTemplateOperation, PreparedEmbed } from "ass"
export const DEFAULT_EMBED: EmbedTemplate = {
title: "ass - The simple self-hosted ShareX server",
description: "ass is a self-hosted ShareX upload server written in Node.js"
}
const executeEmbedOperation = (op: EmbedTemplateOperation): string => {
if (typeof op == 'string') {
return op;
} else if (typeof op == 'object') {
switch (op.op) {
case 'random':
if (op.options.length > 0) {
return executeEmbedOperation(op.options[Math.round(Math.random() * (op.options.length - 1))]);
} else throw new Error("Random without child operations");
}
} else throw new Error("Invalid embed template operation");
};
export const prepareEmbed = (template: EmbedTemplate): PreparedEmbed => {
return {
title: executeEmbedOperation(template.title),
description: executeEmbedOperation(template.description)
};
};

@ -14,6 +14,7 @@ import { UserConfig } from '../UserConfig';
import { getFileS3, uploadFileS3 } from '../s3';
import { rateLimiterMiddleware } from '../ratelimit';
import { DBManager } from '../sql/database';
import { DEFAULT_EMBED, prepareEmbed } from '../embed';
const router = Router({ caseSensitive: true });
@ -121,7 +122,11 @@ router.get('/:fakeId', async (req, res) => {
url: `/direct/${fakeId}`,
uploader: user?.username ?? 'unknown',
size: meta.size,
time: meta.timestamp
time: meta.timestamp,
embed: prepareEmbed({
title: UserConfig.config.embed?.title ?? DEFAULT_EMBED.title,
description: UserConfig.config.embed?.description ?? DEFAULT_EMBED.description
})
});
}
});

46
common/types.d.ts vendored

@ -27,6 +27,25 @@ declare module 'ass' {
database?: DatabaseConfiguration;
rateLimit?: RateLimitConfiguration;
// to whoever has to make the config screen
// for this, im very verys sorry
embed?: EmbedTemplate;
}
/**
* Embed config
*/
interface EmbedConfiguration {
/**
* Title in embed
*/
title?: string,
/**
* Description(s) in embed
*/
description?: string[] | string,
}
interface S3Configuration {
@ -255,6 +274,33 @@ declare module 'ass' {
cliKey: string;
meta: { [key: string]: any };
}
// Generic embed template operation
type EmbedTemplateOperation = EmbedTemplateRandomOperation | string;
/**
* Selects one operation and executes it
*/
type EmbedTemplateRandomOperation = {
op: "random";
options: EmbedTemplateOperation[];
};
/**
* This is so beyond cursed
*/
interface EmbedTemplate {
title: EmbedTemplateOperation;
description: EmbedTemplateOperation;
}
/**
*
*/
interface PreparedEmbed {
title: string;
description: string;
}
}
//#region Dummy modules

@ -11,8 +11,8 @@ html.dark.sl-theme-dark(lang='en', prefix='og: https://ogp.me/ns')
title ass 🍑
//- embed data
meta(property='og:title', content=`image uploaded by ${user}`)
meta(property='og:description', content='a one to two sentence description of your objectg')
meta(property='og:title', content=embed.title)
meta(property='og:description', content=embed.description)
meta(property='og:type', content='website')
meta(property='og:image', content=url)
meta(property='og:url', content='.')

Loading…
Cancel
Save