-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
152 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { config } from '../config'; | ||
import { log } from '../logger'; | ||
import { onUpload as discordOnUpload, onShorten as discordOnShorten } from './discord'; | ||
|
||
const logger = log('webhooks').c('http'); | ||
|
||
export async function onUpload({ user, file, link }: Parameters<typeof discordOnUpload>[0]) { | ||
if (!config.httpWebhook.onUpload) return; | ||
if (!URL.canParse(config.httpWebhook.onUpload)) { | ||
logger.debug('invalid url for http onUpload'); | ||
return; | ||
} | ||
|
||
delete (<any>user).oauthProviders; | ||
delete user.passkeys; | ||
delete user.token; | ||
delete user.password; | ||
delete user.totpSecret; | ||
delete (<any>file).password; | ||
|
||
const payload = { | ||
type: 'upload', | ||
data: { | ||
user, | ||
file, | ||
link, | ||
}, | ||
}; | ||
|
||
const res = await fetch(config.httpWebhook.onUpload, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-zipline-webhook': 'true', | ||
'x-zipline-webhook-type': 'upload', | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
const text = await res.text(); | ||
logger.error('webhook failed', { response: text, status: res.status }); | ||
} | ||
|
||
return; | ||
} | ||
|
||
export async function onShorten({ user, url, link }: Parameters<typeof discordOnShorten>[0]) { | ||
if (!config.httpWebhook.onShorten) return; | ||
if (!URL.canParse(config.httpWebhook.onShorten)) { | ||
logger.debug('invalid url for http onShorten'); | ||
return; | ||
} | ||
|
||
delete (<any>user).oauthProviders; | ||
delete user.passkeys; | ||
delete user.token; | ||
delete user.password; | ||
delete user.totpSecret; | ||
delete (<any>url).password; | ||
|
||
const payload = { | ||
type: 'shorten', | ||
data: { | ||
user, | ||
url, | ||
link, | ||
}, | ||
}; | ||
|
||
const res = await fetch(config.httpWebhook.onShorten, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-zipline-webhook': 'true', | ||
'x-zipline-webhook-type': 'shorten', | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
const text = await res.text(); | ||
logger.error('webhook failed', { response: text, status: res.status }); | ||
} | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { onUpload as discordOnUpload, onShorten as discordOnShorten } from './discord'; | ||
import { onUpload as httpOnUpload, onShorten as httpOnShorten } from './http'; | ||
|
||
export async function onUpload(args: Parameters<typeof discordOnUpload>[0]) { | ||
Promise.all([discordOnUpload(args), httpOnUpload(args)]); | ||
|
||
return; | ||
} | ||
|
||
export async function onShorten(args: Parameters<typeof discordOnShorten>[0]) { | ||
Promise.all([discordOnShorten(args), httpOnShorten(args)]); | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters