diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/database-utils.ts | 12 | ||||
-rw-r--r-- | server/helpers/webfinger.ts | 5 |
2 files changed, 16 insertions, 1 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index fb8ad22b0..78ca768b9 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as retry from 'async/retry' | 1 | import * as retry from 'async/retry' |
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { Model } from 'sequelize-typescript' | ||
3 | import { logger } from './logger' | 4 | import { logger } from './logger' |
4 | 5 | ||
5 | type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } | 6 | type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } |
@@ -34,9 +35,18 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) { | |||
34 | }) | 35 | }) |
35 | } | 36 | } |
36 | 37 | ||
38 | function updateInstanceWithAnother <T> (instanceToUpdate: Model<T>, baseInstance: Model<T>) { | ||
39 | const obj = baseInstance.toJSON() | ||
40 | |||
41 | for (const key of Object.keys(obj)) { | ||
42 | instanceToUpdate.set(key, obj[key]) | ||
43 | } | ||
44 | } | ||
45 | |||
37 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
38 | 47 | ||
39 | export { | 48 | export { |
40 | retryTransactionWrapper, | 49 | retryTransactionWrapper, |
41 | transactionRetryer | 50 | transactionRetryer, |
51 | updateInstanceWithAnother | ||
42 | } | 52 | } |
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts index de8d52c9b..688bf2bab 100644 --- a/server/helpers/webfinger.ts +++ b/server/helpers/webfinger.ts | |||
@@ -15,6 +15,10 @@ async function loadActorUrlOrGetFromWebfinger (name: string, host: string) { | |||
15 | const actor = await ActorModel.loadByNameAndHost(name, host) | 15 | const actor = await ActorModel.loadByNameAndHost(name, host) |
16 | if (actor) return actor.url | 16 | if (actor) return actor.url |
17 | 17 | ||
18 | return getUrlFromWebfinger(name, host) | ||
19 | } | ||
20 | |||
21 | async function getUrlFromWebfinger (name: string, host: string) { | ||
18 | const webfingerData: WebFingerData = await webfingerLookup(name + '@' + host) | 22 | const webfingerData: WebFingerData = await webfingerLookup(name + '@' + host) |
19 | return getLinkOrThrow(webfingerData) | 23 | return getLinkOrThrow(webfingerData) |
20 | } | 24 | } |
@@ -22,6 +26,7 @@ async function loadActorUrlOrGetFromWebfinger (name: string, host: string) { | |||
22 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
23 | 27 | ||
24 | export { | 28 | export { |
29 | getUrlFromWebfinger, | ||
25 | loadActorUrlOrGetFromWebfinger | 30 | loadActorUrlOrGetFromWebfinger |
26 | } | 31 | } |
27 | 32 | ||