From 25439c88e827de7180bb01ac3e564ce454ede33d Mon Sep 17 00:00:00 2001 From: mei23 Date: Wed, 10 Apr 2019 11:14:11 +0900 Subject: [PATCH 1/7] =?UTF-8?q?webfinger.js=20=E3=82=92=E4=BD=BF=E3=82=8F?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - src/@types/webfinger.js.d.ts | 65 ------------------------------------ src/remote/resolve-user.ts | 2 +- src/remote/webfinger.ts | 42 +++++++++++++++++------ 4 files changed, 33 insertions(+), 77 deletions(-) delete mode 100644 src/@types/webfinger.js.d.ts diff --git a/package.json b/package.json index 9f059b3834ab..15bc6c01d466 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,6 @@ "vuex": "3.1.0", "vuex-persistedstate": "2.5.4", "web-push": "3.3.3", - "webfinger.js": "2.7.0", "webpack": "4.28.4", "webpack-cli": "3.2.3", "websocket": "1.0.28", diff --git a/src/@types/webfinger.js.d.ts b/src/@types/webfinger.js.d.ts deleted file mode 100644 index 3556c457707c..000000000000 --- a/src/@types/webfinger.js.d.ts +++ /dev/null @@ -1,65 +0,0 @@ -declare module 'webfinger.js' { - interface IWebFingerConstructorConfig { - tls_only?: boolean; - webfist_fallback?: boolean; - uri_fallback?: boolean; - request_timeout?: number; - } - - type JRDProperties = { [type: string]: string }; - - interface IJRDLink { - rel: string; - type?: string; - href?: string; - template?: string; - titles?: { [lang: string]: string }; - properties?: JRDProperties; - } - - interface IJRD { - subject?: string; - expires?: Date; - aliases?: string[]; - properties?: JRDProperties; - links?: IJRDLink[]; - } - - interface IIDXLinks { - 'avatar': IJRDLink[]; - 'remotestorage': IJRDLink[]; - 'blog': IJRDLink[]; - 'vcard': IJRDLink[]; - 'updates': IJRDLink[]; - 'share': IJRDLink[]; - 'profile': IJRDLink[]; - 'webfist': IJRDLink[]; - 'camlistore': IJRDLink[]; - [type: string]: IJRDLink[]; - } - - interface IIDXProperties { - 'name': string; - [type: string]: string; - } - - interface IIDX { - links: IIDXLinks; - properties: IIDXProperties; - } - - interface ILookupCallbackResult { - object: IJRD; - json: string; - idx: IIDX; - } - - type LookupCallback = (err: Error | string, result?: ILookupCallbackResult) => void; - - export class WebFinger { - constructor(config?: IWebFingerConstructorConfig); - - public lookup(address: string, cb: LookupCallback): NodeJS.Timeout; - public lookupLink(address: string, rel: string, cb: IJRDLink): void; - } -} diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index 1ef07fef49e7..f979e4f5a75f 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -86,7 +86,7 @@ export default async (username: string, _host: string, option?: any, resync?: bo 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})`); + logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${e.statusCode || e.message}`); throw e; }); const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self'); diff --git a/src/remote/webfinger.ts b/src/remote/webfinger.ts index 1229dbaf9828..67535e37db81 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 { - 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 { + 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})`); } From 5af5631cd35c4def99aad4640d6dab3612856dcc Mon Sep 17 00:00:00 2001 From: mei23 Date: Wed, 10 Apr 2019 11:59:36 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Fix:=20=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=8C=E3=81=8F=E3=81=A9?= =?UTF-8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote/resolve-user.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index f979e4f5a75f..69bc0b4325c7 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -86,8 +86,8 @@ export default async (username: string, _host: string, option?: any, resync?: bo 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.statusCode || e.message}`); - 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) { From 044bf3b5094ae2d484a53bfd002e9306619d39ab Mon Sep 17 00:00:00 2001 From: mei23 Date: Wed, 10 Apr 2019 17:37:30 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Fix:=20Renote=E3=82=92=E5=8F=96=E3=82=8A?= =?UTF-8?q?=E6=B6=88=E3=81=95=E3=82=8C=E3=82=8B=E3=81=A8=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=81=8C=E5=A3=8A=E3=82=8C=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/app/common/views/deck/deck.notification.vue | 4 ++-- src/client/app/desktop/views/components/notifications.vue | 4 ++-- src/client/app/mobile/views/components/notification.vue | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/app/common/views/deck/deck.notification.vue b/src/client/app/common/views/deck/deck.notification.vue index 6a116260e5ef..61b14bea0374 100644 --- a/src/client/app/common/views/deck/deck.notification.vue +++ b/src/client/app/common/views/deck/deck.notification.vue @@ -18,7 +18,7 @@ -
+
@@ -28,7 +28,7 @@
- + diff --git a/src/client/app/desktop/views/components/notifications.vue b/src/client/app/desktop/views/components/notifications.vue index 57119bd3deaf..5eaef6dff3c2 100644 --- a/src/client/app/desktop/views/components/notifications.vue +++ b/src/client/app/desktop/views/components/notifications.vue @@ -30,7 +30,7 @@
-