fix: Add basic user-agent to all mastodon-bound requests (#2277)
This commit is contained in:
parent
008248ee0f
commit
302da09248
2 changed files with 11 additions and 0 deletions
server
|
@ -1,5 +1,7 @@
|
|||
import { stringifyQuery } from 'ufo'
|
||||
|
||||
import { defaultUserAgent } from '~/server/utils/shared'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let { server, origin } = getRouterParams(event)
|
||||
server = server.toLocaleLowerCase().trim()
|
||||
|
@ -24,6 +26,9 @@ export default defineEventHandler(async (event) => {
|
|||
try {
|
||||
const result: any = await $fetch(`https://${server}/oauth/token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'user-agent': defaultUserAgent,
|
||||
},
|
||||
body: {
|
||||
client_id: app.client_id,
|
||||
client_secret: app.client_secret,
|
||||
|
|
|
@ -13,6 +13,7 @@ import { env } from '#build-info'
|
|||
// @ts-expect-error virtual import
|
||||
import { driver } from '#storage-config'
|
||||
|
||||
import { version } from '~/config/env'
|
||||
import { APP_NAME } from '~/constants'
|
||||
import type { AppInfo } from '~/types'
|
||||
|
||||
|
@ -48,9 +49,14 @@ export function getRedirectURI(origin: string, server: string) {
|
|||
return `${origin}/api/${server}/oauth/${encodeURIComponent(origin)}`
|
||||
}
|
||||
|
||||
export const defaultUserAgent = `${APP_NAME}/${version}`
|
||||
|
||||
async function fetchAppInfo(origin: string, server: string) {
|
||||
const app: AppInfo = await $fetch(`https://${server}/api/v1/apps`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'user-agent': defaultUserAgent,
|
||||
},
|
||||
body: {
|
||||
client_name: APP_NAME + (env !== 'release' ? ` (${env})` : ''),
|
||||
website: 'https://elk.zone',
|
||||
|
|
Loading…
Add table
Reference in a new issue