summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/db-resolver.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
commit0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch)
tree40874799472fa07416f17b50a398ac33b7771905 /src/remote/activitypub/db-resolver.ts
parentupdate deps (diff)
downloadsharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip
refactoring
Resolve #7779
Diffstat (limited to 'src/remote/activitypub/db-resolver.ts')
-rw-r--r--src/remote/activitypub/db-resolver.ts140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/remote/activitypub/db-resolver.ts b/src/remote/activitypub/db-resolver.ts
deleted file mode 100644
index 289b6f0ee8..0000000000
--- a/src/remote/activitypub/db-resolver.ts
+++ /dev/null
@@ -1,140 +0,0 @@
-import config from '@/config/index';
-import { Note } from '@/models/entities/note';
-import { User, IRemoteUser } from '@/models/entities/user';
-import { UserPublickey } from '@/models/entities/user-publickey';
-import { MessagingMessage } from '@/models/entities/messaging-message';
-import { Notes, Users, UserPublickeys, MessagingMessages } from '@/models/index';
-import { IObject, getApId } from './type';
-import { resolvePerson } from './models/person';
-import escapeRegexp = require('escape-regexp');
-
-export default class DbResolver {
- constructor() {
- }
-
- /**
- * AP Note => Misskey Note in DB
- */
- public async getNoteFromApId(value: string | IObject): Promise<Note | null> {
- const parsed = this.parseUri(value);
-
- if (parsed.id) {
- return (await Notes.findOne({
- id: parsed.id
- })) || null;
- }
-
- if (parsed.uri) {
- return (await Notes.findOne({
- uri: parsed.uri
- })) || null;
- }
-
- return null;
- }
-
- public async getMessageFromApId(value: string | IObject): Promise<MessagingMessage | null> {
- const parsed = this.parseUri(value);
-
- if (parsed.id) {
- return (await MessagingMessages.findOne({
- id: parsed.id
- })) || null;
- }
-
- if (parsed.uri) {
- return (await MessagingMessages.findOne({
- uri: parsed.uri
- })) || null;
- }
-
- return null;
- }
-
- /**
- * AP Person => Misskey User in DB
- */
- public async getUserFromApId(value: string | IObject): Promise<User | null> {
- const parsed = this.parseUri(value);
-
- if (parsed.id) {
- return (await Users.findOne({
- id: parsed.id
- })) || null;
- }
-
- if (parsed.uri) {
- return (await Users.findOne({
- uri: parsed.uri
- })) || null;
- }
-
- return null;
- }
-
- /**
- * AP KeyId => Misskey User and Key
- */
- public async getAuthUserFromKeyId(keyId: string): Promise<AuthUser | null> {
- const key = await UserPublickeys.findOne({
- keyId
- });
-
- if (key == null) return null;
-
- const user = await Users.findOne(key.userId) as IRemoteUser;
-
- return {
- user,
- key
- };
- }
-
- /**
- * AP Actor id => Misskey User and Key
- */
- public async getAuthUserFromApId(uri: string): Promise<AuthUser | null> {
- const user = await resolvePerson(uri) as IRemoteUser;
-
- if (user == null) return null;
-
- const key = await UserPublickeys.findOne(user.id);
-
- return {
- user,
- key
- };
- }
-
- public parseUri(value: string | IObject): UriParseResult {
- const uri = getApId(value);
-
- const localRegex = new RegExp('^' + escapeRegexp(config.url) + '/' + '(\\w+)' + '/' + '(\\w+)');
- const matchLocal = uri.match(localRegex);
-
- if (matchLocal) {
- return {
- type: matchLocal[1],
- id: matchLocal[2]
- };
- } else {
- return {
- uri
- };
- }
- }
-}
-
-export type AuthUser = {
- user: IRemoteUser;
- key?: UserPublickey;
-};
-
-type UriParseResult = {
- /** id in DB (local object only) */
- id?: string;
- /** uri in DB (remote object only) */
- uri?: string;
- /** hint of type (local object only, ex: notes, users) */
- type?: string
-};