summaryrefslogtreecommitdiff
path: root/src/remote
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-10 15:07:21 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-10 15:07:21 +0900
commit30172b92e62eba16e1d8a51babd83ad5b76a81ec (patch)
tree55fccab757aca2acc51ab863bf3088a358b635f9 /src/remote
parent11.0.0-alpha.9 (diff)
downloadsharkey-30172b92e62eba16e1d8a51babd83ad5b76a81ec.tar.gz
sharkey-30172b92e62eba16e1d8a51babd83ad5b76a81ec.tar.bz2
sharkey-30172b92e62eba16e1d8a51babd83ad5b76a81ec.zip
WebFingerリクエストで Proxy, Keep-Alive などをサポート #4658
Co-Authored-By: MeiMei <mei23@users.noreply.github.com>
Diffstat (limited to 'src/remote')
-rw-r--r--src/remote/resolve-user.ts4
-rw-r--r--src/remote/webfinger.ts42
2 files changed, 34 insertions, 12 deletions
diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts
index e6a11bc0da..6a8ce45c91 100644
--- a/src/remote/resolve-user.ts
+++ b/src/remote/resolve-user.ts
@@ -73,8 +73,8 @@ export async function resolveUser(username: string, host: string, option?: any,
async function resolveSelf(acctLower: string) {
logger.info(`WebFinger for ${chalk.yellow(acctLower)}`);
const finger = await webFinger(acctLower).catch(e => {
- logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${e.message} (${e.status})`);
- throw e;
+ logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${ e.statusCode || e.message }`);
+ throw new Error(`Failed to WebFinger for ${acctLower}: ${ e.statusCode || e.message }`);
});
const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self');
if (!self) {
diff --git a/src/remote/webfinger.ts b/src/remote/webfinger.ts
index 1229dbaf98..67535e37db 100644
--- a/src/remote/webfinger.ts
+++ b/src/remote/webfinger.ts
@@ -1,6 +1,7 @@
-import { WebFinger } from 'webfinger.js';
-
-const webFinger = new WebFinger({ });
+import config from '../config';
+import * as request from 'request-promise-native';
+import { URL } from 'url';
+import { query as urlQuery } from '../prelude/url';
type ILink = {
href: string;
@@ -12,12 +13,33 @@ type IWebFinger = {
subject: string;
};
-export default async function resolve(query: any): Promise<IWebFinger> {
- return await new Promise((res, rej) => webFinger.lookup(query, (error: Error | string, result: any) => {
- if (error) {
- return rej(error);
- }
+export default async function(query: string): Promise<IWebFinger> {
+ const url = genUrl(query);
+
+ return await request({
+ url,
+ proxy: config.proxy,
+ timeout: 10 * 1000,
+ forever: true,
+ headers: {
+ 'User-Agent': config.userAgent,
+ Accept: 'application/jrd+json, application/json'
+ },
+ json: true
+ });
+}
+
+function genUrl(query: string) {
+ if (query.match(/^https?:\/\//)) {
+ const u = new URL(query);
+ return `${u.protocol}//${u.hostname}/.well-known/webfinger?` + urlQuery({ resource: query });
+ }
+
+ const m = query.match(/^([^@]+)@(.*)/);
+ if (m) {
+ const hostname = m[2];
+ return `https://${hostname}/.well-known/webfinger?` + urlQuery({ resource: `acct:${query}` });
+ }
- res(result.object);
- })) as IWebFinger;
+ throw new Error(`Invalied query (${query})`);
}