summaryrefslogtreecommitdiff
path: root/src/remote/resolve-user.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:15:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:15:27 +0900
commitcd2542e0fd8578f6e41114ffebbda1f16f7d04ce (patch)
treec339b7808fc2a3d72ae30cb86ddb7b9c21852652 /src/remote/resolve-user.ts
parentRefactor (diff)
downloadsharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.tar.gz
sharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.tar.bz2
sharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.zip
Refactor
Diffstat (limited to 'src/remote/resolve-user.ts')
-rw-r--r--src/remote/resolve-user.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts
new file mode 100644
index 0000000000..a393092839
--- /dev/null
+++ b/src/remote/resolve-user.ts
@@ -0,0 +1,26 @@
+import { toUnicode, toASCII } from 'punycode';
+import User from '../models/user';
+import resolvePerson from './activitypub/resolve-person';
+import webFinger from './webfinger';
+
+export default async (username, host, option) => {
+ const usernameLower = username.toLowerCase();
+ const hostLowerAscii = toASCII(host).toLowerCase();
+ const hostLower = toUnicode(hostLowerAscii);
+
+ let user = await User.findOne({ usernameLower, hostLower }, option);
+
+ if (user === null) {
+ const acctLower = `${usernameLower}@${hostLowerAscii}`;
+
+ const finger = await webFinger(acctLower, acctLower);
+ const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self');
+ if (!self) {
+ throw new Error();
+ }
+
+ user = await resolvePerson(self.href, usernameLower, hostLower, acctLower);
+ }
+
+ return user;
+};