feat: seperate discord webhooks (shorten/upload) (#260)
This commit is contained in:
parent
b7772128d7
commit
5379374135
4 changed files with 31 additions and 14 deletions
|
@ -74,15 +74,18 @@ export interface ConfigWebsiteExternalLinks {
|
|||
}
|
||||
|
||||
export interface ConfigDiscord {
|
||||
url: string;
|
||||
username: string;
|
||||
avatar_url: string;
|
||||
url?: string;
|
||||
username?: string;
|
||||
avatar_url?: string;
|
||||
|
||||
upload: ConfigDiscordContent;
|
||||
shorten: ConfigDiscordContent;
|
||||
}
|
||||
|
||||
export interface ConfigDiscordContent {
|
||||
url?: string;
|
||||
username?: string;
|
||||
avatar_url?: string;
|
||||
content: string;
|
||||
embed: ConfigDiscordEmbed;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,9 @@ export default function readConfig() {
|
|||
map('DISCORD_USERNAME', 'string', 'discord.username'),
|
||||
map('DISCORD_AVATAR_URL', 'string', 'discord.avatar_url'),
|
||||
|
||||
map('DISCORD_UPLOAD_URL', 'string', 'discord.upload.url'),
|
||||
map('DISCORD_UPLOAD_USERNAME', 'string', 'discord.upload.username'),
|
||||
map('DISCORD_UPLOAD_AVATAR_URL', 'string', 'discord.upload.avatar_url'),
|
||||
map('DISCORD_UPLOAD_CONTENT', 'string', 'discord.upload.content'),
|
||||
map('DISCORD_UPLOAD_EMBED_TITLE', 'string', 'discord.upload.embed.title'),
|
||||
map('DISCORD_UPLOAD_EMBED_DESCRIPTION', 'string', 'discord.upload.embed.description'),
|
||||
|
@ -116,6 +119,9 @@ export default function readConfig() {
|
|||
map('DISCORD_UPLOAD_EMBED_THUMBNAIL', 'boolean', 'discord.upload.embed.thumbnail'),
|
||||
map('DISCORD_UPLOAD_EMBED_TIMESTAMP', 'boolean', 'discord.upload.embed.timestamp'),
|
||||
|
||||
map('DISCORD_SHORTEN_URL', 'string', 'discord.shorten.url'),
|
||||
map('DISCORD_SHORTEN_USERNAME', 'string', 'discord.shorten.username'),
|
||||
map('DISCORD_SHORTEN_AVATAR_URL', 'string', 'discord.shorten.avatar_url'),
|
||||
map('DISCORD_SHORTEN_CONTENT', 'string', 'discord.shorten.content'),
|
||||
map('DISCORD_SHORTEN_EMBED_TITLE', 'string', 'discord.shorten.embed.title'),
|
||||
map('DISCORD_SHORTEN_EMBED_DESCRIPTION', 'string', 'discord.shorten.embed.description'),
|
||||
|
|
|
@ -6,6 +6,9 @@ import { humanToBytes } from 'utils/bytes';
|
|||
|
||||
const discord_content = s
|
||||
.object({
|
||||
url: s.string.nullish.default(null),
|
||||
username: s.string.nullish.default(null),
|
||||
avatar_url: s.string.nullish.default(null),
|
||||
content: s.string.nullish.default(null),
|
||||
embed: s
|
||||
.object({
|
||||
|
@ -141,11 +144,9 @@ const validator = s.object({
|
|||
}),
|
||||
discord: s
|
||||
.object({
|
||||
url: s.string,
|
||||
username: s.string.default('Zipline'),
|
||||
avatar_url: s.string.default(
|
||||
'https://raw.githubusercontent.com/diced/zipline/9b60147e112ec5b70170500b85c75ea621f41d03/public/zipline.png'
|
||||
),
|
||||
url: s.string.nullish.default(null),
|
||||
username: s.string.nullish.default(null),
|
||||
avatar_url: s.string.nullish.default(null),
|
||||
upload: discord_content,
|
||||
shorten: discord_content,
|
||||
})
|
||||
|
|
|
@ -29,7 +29,9 @@ export function parseContent(
|
|||
|
||||
export async function sendUpload(user: User, file: File, raw_link: string, link: string) {
|
||||
if (!config.discord.upload) return;
|
||||
if (!config.discord.url && !config.discord.upload.url) return;
|
||||
|
||||
logger.debug(`discord config:\n${JSON.stringify(config.discord)}`);
|
||||
const parsed = parseContent(config.discord.upload, {
|
||||
file,
|
||||
user,
|
||||
|
@ -40,8 +42,10 @@ export async function sendUpload(user: User, file: File, raw_link: string, link:
|
|||
const isImage = file.mimetype.startsWith('image/');
|
||||
|
||||
const body = JSON.stringify({
|
||||
username: config.discord.username,
|
||||
avatar_url: config.discord.avatar_url,
|
||||
username: (config.discord.username ?? config.discord.upload.username) || 'Zipline',
|
||||
avatar_url:
|
||||
(config.discord.avatar_url ?? config.discord.upload.avatar_url) ||
|
||||
'https://raw.githubusercontent.com/diced/zipline/9b60147e112ec5b70170500b85c75ea621f41d03/public/zipline.png',
|
||||
content: parsed.content ?? null,
|
||||
embeds: parsed.embed
|
||||
? [
|
||||
|
@ -74,7 +78,7 @@ export async function sendUpload(user: User, file: File, raw_link: string, link:
|
|||
});
|
||||
|
||||
logger.debug('attempting to send upload notification to discord', body);
|
||||
const res = await fetch(config.discord.url, {
|
||||
const res = await fetch(config.discord.url || config.discord.upload.url, {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers: {
|
||||
|
@ -94,6 +98,7 @@ export async function sendUpload(user: User, file: File, raw_link: string, link:
|
|||
|
||||
export async function sendShorten(user: User, url: Url, link: string) {
|
||||
if (!config.discord.shorten) return;
|
||||
if (!config.discord.url && !config.discord.shorten.url) return;
|
||||
|
||||
const parsed = parseContent(config.discord.shorten, {
|
||||
url,
|
||||
|
@ -102,8 +107,10 @@ export async function sendShorten(user: User, url: Url, link: string) {
|
|||
});
|
||||
|
||||
const body = JSON.stringify({
|
||||
username: config.discord.username,
|
||||
avatar_url: config.discord.avatar_url,
|
||||
username: (config.discord.username ?? config.discord.shorten.username) || 'Zipline',
|
||||
avatar_url:
|
||||
(config.discord.avatar_url ?? config.discord.shorten.avatar_url) ||
|
||||
'https://raw.githubusercontent.com/diced/zipline/9b60147e112ec5b70170500b85c75ea621f41d03/public/zipline.png',
|
||||
content: parsed.content ?? null,
|
||||
embeds: parsed.embed
|
||||
? [
|
||||
|
@ -124,7 +131,7 @@ export async function sendShorten(user: User, url: Url, link: string) {
|
|||
});
|
||||
|
||||
logger.debug('attempting to send shorten notification to discord', body);
|
||||
const res = await fetch(config.discord.url, {
|
||||
const res = await fetch(config.discord.url || config.discord.shorten.url, {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers: {
|
||||
|
|
Loading…
Add table
Reference in a new issue