summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorslonkazoid <slonkazoid@slonk.ing>2024-07-12 14:28:19 +0300
committerslonkazoid <slonkazoid@slonk.ing>2024-07-12 14:28:19 +0300
commit0b6fb394c00d3eff77ae4e82e17887a397c7b932 (patch)
tree328c163d55de68be8b4581a368dcc1c09d75bef7
parentimplement fetching host-meta before the webfinger endpoint (diff)
downloadsharkey-0b6fb394c00d3eff77ae4e82e17887a397c7b932.tar.gz
sharkey-0b6fb394c00d3eff77ae4e82e17887a397c7b932.tar.bz2
sharkey-0b6fb394c00d3eff77ae4e82e17887a397c7b932.zip
apply fixes from review
-rw-r--r--packages/backend/src/core/WebfingerService.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/packages/backend/src/core/WebfingerService.ts b/packages/backend/src/core/WebfingerService.ts
index ec03f9124a..519eeb3764 100644
--- a/packages/backend/src/core/WebfingerService.ts
+++ b/packages/backend/src/core/WebfingerService.ts
@@ -42,11 +42,11 @@ export class WebfingerService {
private genUrl(query: string, template: string): string {
if (template.indexOf('{uri}') < 0) throw new Error(`Invalid webFingerUrl: ${template}`);
- if (query.match(/^https?:\/\//)) {
+ if (query.match(urlRegex)) {
return template.replace('{uri}', encodeURIComponent(query));
}
- const m = query.match(/^([^@]+)@(.*)/);
+ const m = query.match(mRegex);
if (m) {
return template.replace('{uri}', encodeURIComponent(`acct:${query}`));
}
@@ -56,12 +56,13 @@ export class WebfingerService {
@bindThis
private queryToWebFingerTemplate(query: string): string {
- if (query.match(/^https?:\/\//)) {
+ if (query.match(urlRegex)) {
const u = new URL(query);
- return `${u.protocol}//${u.hostname}/.well-known/webfinger?resource={uri}`;
+ const useHttp = process.env.MISSKEY_WEBFINGER_USE_HTTP && process.env.MISSKEY_WEBFINGER_USE_HTTP.toLowerCase() === 'true';
+ return `${useHttp ? 'http' : u.protocol}//${u.hostname}/.well-known/webfinger?resource={uri}`;
}
- const m = query.match(/^([^@]+)@(.*)/);
+ const m = query.match(mRegex);
if (m) {
const hostname = m[2];
return `https://${hostname}/.well-known/webfinger?resource={uri}`;
@@ -74,7 +75,8 @@ export class WebfingerService {
private queryToHostMetaUrl(query: string): string {
if (query.match(urlRegex)) {
const u = new URL(query);
- return `${u.protocol}//${u.hostname}/.well-known/host-meta`;
+ const useHttp = process.env.MISSKEY_WEBFINGER_USE_HTTP && process.env.MISSKEY_WEBFINGER_USE_HTTP.toLowerCase() === 'true';
+ return `${useHttp ? 'http' : u.protocol}//${u.hostname}/.well-known/host-meta`;
}
const m = query.match(mRegex);