aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/database-utils.ts13
-rw-r--r--server/helpers/webfinger.ts8
2 files changed, 12 insertions, 9 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index 169b80065..dacd747c9 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -4,12 +4,15 @@ import * as Bluebird from 'bluebird'
4import { logger } from './logger' 4import { logger } from './logger'
5 5
6type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } 6type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] }
7function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | Bluebird<any>, options: RetryTransactionWrapperOptions) { 7function retryTransactionWrapper <T> (
8 functionToRetry: (...args) => Promise<T> | Bluebird<T>,
9 options: RetryTransactionWrapperOptions
10): Promise<T> {
8 const args = options.arguments ? options.arguments : [] 11 const args = options.arguments ? options.arguments : []
9 12
10 return transactionRetryer(callback => { 13 return transactionRetryer<T>(callback => {
11 functionToRetry.apply(this, args) 14 functionToRetry.apply(this, args)
12 .then(result => callback(null, result)) 15 .then((result: T) => callback(null, result))
13 .catch(err => callback(err)) 16 .catch(err => callback(err))
14 }) 17 })
15 .catch(err => { 18 .catch(err => {
@@ -18,8 +21,8 @@ function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | B
18 }) 21 })
19} 22}
20 23
21function transactionRetryer (func: Function) { 24function transactionRetryer <T> (func: (err: any, data: T) => any) {
22 return new Promise((res, rej) => { 25 return new Promise<T>((res, rej) => {
23 retry({ 26 retry({
24 times: 5, 27 times: 5,
25 28
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
index b7408c845..a5b4785fe 100644
--- a/server/helpers/webfinger.ts
+++ b/server/helpers/webfinger.ts
@@ -1,9 +1,9 @@
1import * as WebFinger from 'webfinger.js' 1import * as WebFinger from 'webfinger.js'
2import { WebFingerData } from '../../shared' 2import { WebFingerData } from '../../shared'
3import { fetchRemoteAccount } from '../lib/activitypub/account'
3 4
4import { isTestInstance } from './core-utils' 5import { isTestInstance } from './core-utils'
5import { isActivityPubUrlValid } from './custom-validators' 6import { isActivityPubUrlValid } from './custom-validators'
6import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account'
7 7
8const webfinger = new WebFinger({ 8const webfinger = new WebFinger({
9 webfist_fallback: false, 9 webfist_fallback: false,
@@ -22,10 +22,10 @@ async function getAccountFromWebfinger (nameWithHost: string) {
22 throw new Error('Cannot find self link or href is not a valid URL.') 22 throw new Error('Cannot find self link or href is not a valid URL.')
23 } 23 }
24 24
25 const res = await fetchRemoteAccountAndCreateServer(selfLink.href) 25 const account = await fetchRemoteAccount(selfLink.href)
26 if (res === undefined) throw new Error('Cannot fetch and create server of remote account ' + selfLink.href) 26 if (account === undefined) throw new Error('Cannot fetch remote account ' + selfLink.href)
27 27
28 return res.account 28 return account
29} 29}
30 30
31// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------