refactor: remove CacheableUser & co

The CacheableUser, CacheableLocalUser and CacheableRemoteUser are
identical types to User, ILocalUser and IRemoteUser so it seems
nonsensical to have different types for them.
This commit is contained in:
Johann150 2023-05-18 13:25:57 +02:00
parent 9675ced915
commit 1516ddfc9b
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
44 changed files with 107 additions and 112 deletions

View file

@ -260,9 +260,3 @@ export interface IRemoteUser extends User {
host: string;
token: null;
}
export type CacheableLocalUser = ILocalUser;
export type CacheableRemoteUser = IRemoteUser;
export type CacheableUser = CacheableLocalUser | CacheableRemoteUser;

View file

@ -1,5 +1,5 @@
import promiseLimit from 'promise-limit';
import { CacheableRemoteUser, CacheableUser } from '@/models/entities/user.js';
import { IRemoteUser, User } from '@/models/entities/user.js';
import { unique, concat } from '@/prelude/array.js';
import { resolvePerson } from './models/person.js';
import { Resolver } from './resolver.js';
@ -9,20 +9,20 @@ type Visibility = 'public' | 'home' | 'followers' | 'specified';
type AudienceInfo = {
visibility: Visibility,
mentionedUsers: CacheableUser[],
visibleUsers: CacheableUser[],
mentionedUsers: User[],
visibleUsers: User[],
};
export async function parseAudience(actor: CacheableRemoteUser, to?: ApObject, cc?: ApObject, resolver?: Resolver): Promise<AudienceInfo> {
export async function parseAudience(actor: IRemoteUser, to?: ApObject, cc?: ApObject, resolver?: Resolver): Promise<AudienceInfo> {
const toGroups = groupingAudience(getApIds(to), actor);
const ccGroups = groupingAudience(getApIds(cc), actor);
const others = unique(concat([toGroups.other, ccGroups.other]));
const limit = promiseLimit<CacheableUser | null>(2);
const limit = promiseLimit<User | null>(2);
const mentionedUsers = (await Promise.all(
others.map(id => limit(() => resolvePerson(id, resolver).catch(() => null))),
)).filter((x): x is CacheableUser => x != null);
)).filter((x): x is User => x != null);
if (toGroups.public.length > 0) {
return {
@ -55,7 +55,7 @@ export async function parseAudience(actor: CacheableRemoteUser, to?: ApObject, c
};
}
function groupingAudience(ids: string[], actor: CacheableRemoteUser) {
function groupingAudience(ids: string[], actor: IRemoteUser) {
const groups = {
public: [] as string[],
followers: [] as string[],
@ -85,7 +85,7 @@ function isPublic(id: string) {
].includes(id);
}
function isFollowers(id: string, actor: CacheableRemoteUser) {
function isFollowers(id: string, actor: IRemoteUser) {
return (
id === (actor.followersUri || `${actor.uri}/followers`)
);

View file

@ -1,7 +1,7 @@
import escapeRegexp from 'escape-regexp';
import config from '@/config/index.js';
import { Note } from '@/models/entities/note.js';
import { CacheableUser } from '@/models/entities/user.js';
import { User } from '@/models/entities/user.js';
import { MessagingMessage } from '@/models/entities/messaging-message.js';
import { Notes, MessagingMessages } from '@/models/index.js';
import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
@ -89,7 +89,7 @@ export class DbResolver {
/**
* AP Person => FoundKey User in DB
*/
public async getUserFromApId(value: string | IObject): Promise<CacheableUser | null> {
public async getUserFromApId(value: string | IObject): Promise<User | null> {
const parsed = parseUri(value);
if (parsed.local) {

View file

@ -1,11 +1,11 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { acceptFollowRequest } from '@/services/following/requests/accept.js';
import { relayAccepted } from '@/services/relay.js';
import { IFollow } from '@/remote/activitypub/type.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<string> => {
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
// activity is a follow request started by this server, so activity.actor must be an existing local user.
const dbResolver = new DbResolver();
const follower = await dbResolver.getUserFromApId(activity.actor);

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { apLogger } from '@/remote/activitypub/logger.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IAccept, isFollow, getApType } from '@/remote/activitypub/type.js';
import acceptFollow from './follow.js';
export default async (actor: CacheableRemoteUser, activity: IAccept, resolver: Resolver): Promise<string> => {
export default async (actor: IRemoteUser, activity: IAccept, resolver: Resolver): Promise<string> => {
const uri = activity.id || activity;
apLogger.info(`Accept: ${uri}`);

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { addPinned } from '@/services/i/pin.js';
import { resolveNote } from '@/remote/activitypub/models/note.js';
import { IAdd } from '@/remote/activitypub/type.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
export default async (actor: CacheableRemoteUser, activity: IAdd, resolver: Resolver): Promise<void> => {
export default async (actor: IRemoteUser, activity: IAdd, resolver: Resolver): Promise<void> => {
if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor');
}

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { apLogger } from '@/remote/activitypub/logger.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IAnnounce, getApId } from '@/remote/activitypub/type.js';
import announceNote from './note.js';
export default async (actor: CacheableRemoteUser, activity: IAnnounce, resolver: Resolver): Promise<void> => {
export default async (actor: IRemoteUser, activity: IAnnounce, resolver: Resolver): Promise<void> => {
const uri = getApId(activity);
apLogger.info(`Announce: ${uri}`);

View file

@ -1,5 +1,5 @@
import post from '@/services/note/create.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { extractDbHost } from '@/misc/convert-host.js';
import { getApLock } from '@/misc/app-lock.js';
import { StatusError } from '@/misc/fetch.js';
@ -11,7 +11,7 @@ import { Resolver } from '@/remote/activitypub/resolver.js';
import { IAnnounce, getApId } from '@/remote/activitypub/type.js';
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
export default async function(resolver: Resolver, actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
export default async function(resolver: Resolver, actor: IRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
const uri = getApId(activity);
if (actor.isSuspended) {

View file

@ -1,11 +1,11 @@
import block from '@/services/blocking/create.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
import { IBlock } from '@/remote/activitypub/type.js';
export default async (actor: CacheableRemoteUser, activity: IBlock): Promise<string> => {
// ※ activity.objectにブロック対象があり、それは存在するローカルユーザーのはず
export default async (actor: IRemoteUser, activity: IBlock): Promise<string> => {
// There is a block target in activity.object, which should be a local user that exists.
const dbResolver = new DbResolver();
const blockee = await dbResolver.getUserFromApId(activity.object);
@ -15,7 +15,7 @@ export default async (actor: CacheableRemoteUser, activity: IBlock): Promise<str
}
if (blockee.host != null) {
return 'skip: ブロックしようとしているユーザーはローカルユーザーではありません';
return 'skip: blockee is not local';
}
await block(await Users.findOneByOrFail({ id: actor.id }), await Users.findOneByOrFail({ id: blockee.id }));

View file

@ -1,11 +1,11 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { toArray, concat, unique } from '@/prelude/array.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { ICreate, getApId, isPost, getApType } from '../../type.js';
import { apLogger } from '../../logger.js';
import createNote from './note.js';
export default async (actor: CacheableRemoteUser, activity: ICreate, resolver: Resolver): Promise<void> => {
export default async (actor: IRemoteUser, activity: ICreate, resolver: Resolver): Promise<void> => {
const uri = getApId(activity);
apLogger.info(`Create: ${uri}`);

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { getApLock } from '@/misc/app-lock.js';
import { extractDbHost } from '@/misc/convert-host.js';
import { StatusError } from '@/misc/fetch.js';
@ -9,7 +9,7 @@ import { getApId, IObject } from '@/remote/activitypub/type.js';
/**
* 稿
*/
export default async function(resolver: Resolver, actor: CacheableRemoteUser, note: IObject, silent = false): Promise<string> {
export default async function(resolver: Resolver, actor: IRemoteUser, note: IObject, silent = false): Promise<string> {
const uri = getApId(note);
if (typeof note === 'object') {

View file

@ -1,9 +1,9 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js';
import { apLogger } from '@/remote/activitypub/logger.js';
import { deleteAccount } from '@/services/delete-account.js';
export async function deleteActor(actor: CacheableRemoteUser, uri: string): Promise<string> {
export async function deleteActor(actor: IRemoteUser, uri: string): Promise<string> {
apLogger.info(`Deleting the Actor: ${uri}`);
if (actor.uri !== uri) {

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { toSingle } from '@/prelude/array.js';
import { IDelete, getApId, isTombstone, IObject, validPost, validActor } from '@/remote/activitypub/type.js';
import { deleteActor } from './actor.js';
@ -7,7 +7,7 @@ import deleteNote from './note.js';
/**
*
*/
export default async (actor: CacheableRemoteUser, activity: IDelete): Promise<string> => {
export default async (actor: IRemoteUser, activity: IDelete): Promise<string> => {
if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor');
}

View file

@ -1,11 +1,11 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { deleteNotes } from '@/services/note/delete.js';
import { getApLock } from '@/misc/app-lock.js';
import { deleteMessage } from '@/services/messages/delete.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
import { apLogger } from '@/remote/activitypub/logger.js';
export default async function(actor: CacheableRemoteUser, uri: string): Promise<string> {
export default async function(actor: IRemoteUser, uri: string): Promise<string> {
apLogger.info(`Deleting the Note: ${uri}`);
const unlock = await getApLock(uri);

View file

@ -1,13 +1,14 @@
import { In } from 'typeorm';
import config from '@/config/index.js';
import { genId } from '@/misc/gen-id.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { AbuseUserReports, Users } from '@/models/index.js';
import { IFlag, getApIds } from '@/remote/activitypub/type.js';
export default async (actor: CacheableRemoteUser, activity: IFlag): Promise<string> => {
// objectは `(User|Note) | (User|Note)[]` だけど、全パターンDBスキーマと対応させられないので
// 対象ユーザーは一番最初のユーザー として あとはコメントとして格納する
export default async (actor: IRemoteUser, activity: IFlag): Promise<string> => {
// The object is `(User|Note) | (User|Note)[]`, but since the database schema
// cannot be made to handle every possible case, the target user is the first user
// and everything else is stored by URL.
const uris = getApIds(activity.object);
const userIds = uris.filter(uri => uri.startsWith(config.url + '/users/')).map(uri => uri.split('/').pop()!);

View file

@ -1,9 +1,9 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import follow from '@/services/following/create.js';
import { IFollow } from '../type.js';
import { DbResolver } from '../db-resolver.js';
export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<string> => {
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
const dbResolver = new DbResolver();
const followee = await dbResolver.getUserFromApId(activity.object);

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { toArray } from '@/prelude/array.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { extractDbHost } from '@/misc/convert-host.js';
@ -21,7 +21,7 @@ import block from './block/index.js';
import flag from './flag/index.js';
import { move } from './move/index.js';
export async function performActivity(actor: CacheableRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
export async function performActivity(actor: IRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
if (isCollectionOrOrderedCollection(activity)) {
for (const item of toArray(isCollection(activity) ? activity.items : activity.orderedItems)) {
const act = await resolver.resolve(item);
@ -38,7 +38,7 @@ export async function performActivity(actor: CacheableRemoteUser, activity: IObj
}
}
async function performOneActivity(actor: CacheableRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
async function performOneActivity(actor: IRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
if (actor.isSuspended) return;
if (typeof activity.id !== 'undefined') {

View file

@ -1,9 +1,9 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { createReaction } from '@/services/note/reaction/create.js';
import { ILike, getApId } from '../type.js';
import { fetchNote, extractEmojis } from '../models/note.js';
export default async (actor: CacheableRemoteUser, activity: ILike) => {
export default async (actor: IRemoteUser, activity: ILike) => {
const targetUri = getApId(activity.object);
const note = await fetchNote(targetUri);

View file

@ -1,12 +1,12 @@
import { IsNull } from 'typeorm';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { resolvePerson } from '@/remote/activitypub/models/person.js';
import { Followings, Users } from '@/models/index.js';
import { createNotification } from '@/services/create-notification.js';
import Resolver from '../../resolver.js';
import { IMove, isActor, getApId } from '../../type.js';
export async function move(actor: CacheableRemoteUser, activity: IMove, resolver: Resolver): Promise<void> {
export async function move(actor: IRemoteUser, activity: IMove, resolver: Resolver): Promise<void> {
// actor is not move origin
if (activity.object == null || getApId(activity.object) !== actor.uri) return;

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { isSelfHost, extractDbHost } from '@/misc/convert-host.js';
import { MessagingMessages } from '@/models/index.js';
import { readUserMessagingMessage } from '@/server/api/common/read-messaging-message.js';
import { IRead, getApId } from '../type.js';
export const performReadActivity = async (actor: CacheableRemoteUser, activity: IRead): Promise<string> => {
export const performReadActivity = async (actor: IRemoteUser, activity: IRead): Promise<string> => {
const id = await getApId(activity.object);
if (!isSelfHost(extractDbHost(id))) {

View file

@ -1,12 +1,12 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { remoteReject } from '@/services/following/reject.js';
import { relayRejected } from '@/services/relay.js';
import { Users } from '@/models/index.js';
import { IFollow } from '../../type.js';
import { DbResolver } from '../../db-resolver.js';
export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<string> => {
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
// activity is a follow request started by this server, so activity.actor must be an existing local user.
const dbResolver = new DbResolver();
const follower = await dbResolver.getUserFromApId(activity.actor);

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { apLogger } from '../../logger.js';
import { IReject, isFollow, getApType } from '../../type.js';
import rejectFollow from './follow.js';
export default async (actor: CacheableRemoteUser, activity: IReject, resolver: Resolver): Promise<string> => {
export default async (actor: IRemoteUser, activity: IReject, resolver: Resolver): Promise<string> => {
const uri = activity.id || activity;
apLogger.info(`Reject: ${uri}`);

View file

@ -1,10 +1,10 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { removePinned } from '@/services/i/pin.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IRemove } from '../../type.js';
import { resolveNote } from '../../models/note.js';
export default async (actor: CacheableRemoteUser, activity: IRemove, resolver: Resolver): Promise<void> => {
export default async (actor: IRemoteUser, activity: IRemove, resolver: Resolver): Promise<void> => {
if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor');
}

View file

@ -1,10 +1,10 @@
import unfollow from '@/services/following/delete.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Followings } from '@/models/index.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
import { IAccept } from '@/remote/activitypub/type.js';
export default async (actor: CacheableRemoteUser, activity: IAccept): Promise<string> => {
export default async (actor: IRemoteUser, activity: IAccept): Promise<string> => {
const dbResolver = new DbResolver();
const follower = await dbResolver.getUserFromApId(activity.object);

View file

@ -1,9 +1,9 @@
import { Notes } from '@/models/index.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { deleteNotes } from '@/services/note/delete.js';
import { IAnnounce, getApId } from '@/remote/activitypub/type.js';
export const undoAnnounce = async (actor: CacheableRemoteUser, activity: IAnnounce): Promise<string> => {
export const undoAnnounce = async (actor: IRemoteUser, activity: IAnnounce): Promise<string> => {
const uri = getApId(activity);
const note = await Notes.findOneBy({

View file

@ -1,10 +1,10 @@
import unblock from '@/services/blocking/delete.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js';
import { IBlock } from '@/remote/activitypub/type.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
export default async (actor: CacheableRemoteUser, activity: IBlock): Promise<string> => {
export default async (actor: IRemoteUser, activity: IBlock): Promise<string> => {
const dbResolver = new DbResolver();
const blockee = await dbResolver.getUserFromApId(activity.object);

View file

@ -1,11 +1,11 @@
import unfollow from '@/services/following/delete.js';
import { cancelFollowRequest } from '@/services/following/requests/cancel.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { FollowRequests, Followings } from '@/models/index.js';
import { IFollow } from '@/remote/activitypub/type.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<string> => {
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
const dbResolver = new DbResolver();
const followee = await dbResolver.getUserFromApId(activity.object);

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { apLogger } from '@/remote/activitypub/logger.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IUndo, isFollow, isBlock, isLike, isAnnounce, getApType, isAccept } from '@/remote/activitypub/type.js';
@ -8,7 +8,7 @@ import undoLike from './like.js';
import undoAccept from './accept.js';
import { undoAnnounce } from './announce.js';
export default async (actor: CacheableRemoteUser, activity: IUndo, resolver: Resolver): Promise<string> => {
export default async (actor: IRemoteUser, activity: IUndo, resolver: Resolver): Promise<string> => {
if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor');
}

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { deleteReaction } from '@/services/note/reaction/delete.js';
import { ILike, getApId } from '@/remote/activitypub/type.js';
import { fetchNote } from '@/remote/activitypub/models/note.js';
@ -6,7 +6,7 @@ import { fetchNote } from '@/remote/activitypub/models/note.js';
/**
* Process Undo.Like activity
*/
export default async (actor: CacheableRemoteUser, activity: ILike) => {
export default async (actor: IRemoteUser, activity: ILike) => {
const targetUri = getApId(activity.object);
const note = await fetchNote(targetUri);

View file

@ -1,4 +1,4 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { getApId, getApType, IUpdate, isActor } from '@/remote/activitypub/type.js';
import { apLogger } from '@/remote/activitypub/logger.js';
import { updateQuestion } from '@/remote/activitypub/models/question.js';
@ -8,7 +8,7 @@ import { updatePerson } from '@/remote/activitypub/models/person.js';
/**
* Updateアクティビティを捌きます
*/
export default async (actor: CacheableRemoteUser, activity: IUpdate, resolver: Resolver): Promise<string> => {
export default async (actor: IRemoteUser, activity: IUpdate, resolver: Resolver): Promise<string> => {
if ('actor' in activity && actor.uri !== activity.actor) {
return 'skip: invalid actor';
}

View file

@ -1,12 +1,12 @@
import { Cache } from '@/misc/cache.js';
import { UserPublickeys } from '@/models/index.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { UserPublickey } from '@/models/entities/user-publickey.js';
import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
import { createPerson } from '@/remote/activitypub/models/person.js';
export type AuthUser = {
user: CacheableRemoteUser;
user: IRemoteUser;
key: UserPublickey;
};

View file

@ -1,5 +1,5 @@
import { uploadFromUrl } from '@/services/drive/upload-from-url.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { DriveFiles } from '@/models/index.js';
@ -11,7 +11,7 @@ import { apLogger } from '../logger.js';
/**
* Imageを作成します
*/
export async function createImage(actor: CacheableRemoteUser, value: any, resolver: Resolver): Promise<DriveFile> {
export async function createImage(actor: IRemoteUser, value: any, resolver: Resolver): Promise<DriveFile> {
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
throw new Error('actor has been suspended');
@ -58,7 +58,7 @@ export async function createImage(actor: CacheableRemoteUser, value: any, resolv
* If the target Image is registered in FoundKey, return it; otherwise, fetch it from the remote server and return it.
* Fetch the image from the remote server, register it in FoundKey and return it.
*/
export async function resolveImage(actor: CacheableRemoteUser, value: any, resolver: Resolver): Promise<DriveFile> {
export async function resolveImage(actor: IRemoteUser, value: any, resolver: Resolver): Promise<DriveFile> {
// TODO
// Fetch from remote server and register it.

View file

@ -1,17 +1,17 @@
import promiseLimit from 'promise-limit';
import { toArray, unique } from '@/prelude/array.js';
import { CacheableUser } from '@/models/entities/user.js';
import { User } from '@/models/entities/user.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IObject, isMention, IApMention } from '../type.js';
import { resolvePerson } from './person.js';
export async function extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver): Promise<CacheableUser[]> {
export async function extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver): Promise<User[]> {
const hrefs = unique(extractApMentionObjects(tags).map(x => x.href as string));
const limit = promiseLimit<CacheableUser | null>(2);
const limit = promiseLimit<User | null>(2);
const mentionedUsers = (await Promise.all(
hrefs.map(x => limit(() => resolvePerson(x, resolver).catch(() => null))),
)).filter((x): x is CacheableUser => x != null);
)).filter((x): x is User => x != null);
return mentionedUsers;
}

View file

@ -2,7 +2,7 @@ import promiseLimit from 'promise-limit';
import config from '@/config/index.js';
import post from '@/services/note/create.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { unique, toArray, toSingle } from '@/prelude/array.js';
import { vote } from '@/services/note/polls/vote.js';
import { DriveFile } from '@/models/entities/drive-file.js';
@ -91,7 +91,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
apLogger.info(`Creating the Note: ${note.id}`);
// 投稿者をフェッチ
const actor = await resolvePerson(getOneApId(note.attributedTo), resolver) as CacheableRemoteUser;
const actor = await resolvePerson(getOneApId(note.attributedTo), resolver) as IRemoteUser;
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {

View file

@ -6,7 +6,7 @@ import { registerOrFetchInstanceDoc } from '@/services/register-or-fetch-instanc
import { Note } from '@/models/entities/note.js';
import { updateUsertags } from '@/services/update-hashtag.js';
import { Users, Instances, Followings, UserProfiles, UserPublickeys } from '@/models/index.js';
import { User, IRemoteUser, CacheableUser } from '@/models/entities/user.js';
import { User, IRemoteUser, User } from '@/models/entities/user.js';
import { Emoji } from '@/models/entities/emoji.js';
import { UserNotePining } from '@/models/entities/user-note-pining.js';
import { genId } from '@/misc/gen-id.js';
@ -121,7 +121,7 @@ async function validateActor(x: IObject, resolver: Resolver): Promise<IActor> {
*
* If the target Person is registered in FoundKey, it is returned.
*/
export async function fetchPerson(uri: string): Promise<CacheableUser | null> {
export async function fetchPerson(uri: string): Promise<User | null> {
if (typeof uri !== 'string') throw new Error('uri is not string');
const cached = uriPersonCache.get(uri);
@ -394,7 +394,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
* If the target Person is registered in FoundKey, return it; otherwise, fetch it from a remote server and return it.
* Fetch the person from the remote server, register it in FoundKey, and return it.
*/
export async function resolvePerson(uri: string, resolver: Resolver, hint?: IObject): Promise<CacheableUser> {
export async function resolvePerson(uri: string, resolver: Resolver, hint?: IObject): Promise<User> {
if (typeof uri !== 'string') throw new Error('uri is not string');
//#region このサーバーに既に登録されていたらそれを返す

View file

@ -1,11 +1,11 @@
import { DAY } from '@/const.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { IObject } from './type.js';
import { performActivity } from './kernel/index.js';
import { updatePerson } from './models/person.js';
export async function perform(actor: CacheableRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
export async function perform(actor: IRemoteUser, activity: IObject, resolver: Resolver): Promise<void> {
await performActivity(actor, activity, resolver);
// And while I'm at it, I'll update the remote user information if it's out of date.

View file

@ -1,4 +1,4 @@
import { CacheableLocalUser } from '@/models/entities/user.js';
import { ILocalUser } from '@/models/entities/user.js';
import { Users, AccessTokens } from '@/models/index.js';
import { AccessToken } from '@/models/entities/access-token.js';
import { userByIdCache, localUserByNativeTokenCache } from '@/services/user-cache.js';
@ -11,7 +11,7 @@ export class AuthenticationError extends Error {
}
}
export default async (authorization: string | null | undefined, bodyToken: string | null | undefined): Promise<[CacheableLocalUser | null | undefined, AccessToken | null | undefined]> => {
export default async (authorization: string | null | undefined, bodyToken: string | null | undefined): Promise<[ILocalUser | null | undefined, AccessToken | null | undefined]> => {
let maybeToken: string | null = null;
// check if there is an authorization header set

View file

@ -1,6 +1,6 @@
import { performance } from 'perf_hooks';
import Koa from 'koa';
import { CacheableLocalUser } from '@/models/entities/user.js';
import { ILocalUser } from '@/models/entities/user.js';
import { AccessToken } from '@/models/entities/access-token.js';
import { getIpHash } from '@/misc/get-ip-hash.js';
import { limiter } from './limiter.js';
@ -8,7 +8,7 @@ import endpoints, { IEndpointMeta } from './endpoints.js';
import { ApiError } from './error.js';
import { apiLogger } from './logger.js';
export default async (endpoint: string, user: CacheableLocalUser | null | undefined, token: AccessToken | null | undefined, data: any, ctx?: Koa.Context) => {
export default async (endpoint: string, user: ILocalUser | null | undefined, token: AccessToken | null | undefined, data: any, ctx?: Koa.Context) => {
const isSecure = user != null && token == null;
const isModerator = user != null && (user.isModerator || user.isAdmin);

View file

@ -1,6 +1,6 @@
import * as fs from 'node:fs';
import Ajv from 'ajv';
import { CacheableLocalUser } from '@/models/entities/user.js';
import { ILocalUser } from '@/models/entities/user.js';
import { Schema, SchemaType } from '@/misc/schema.js';
import { AccessToken } from '@/models/entities/access-token.js';
import { IEndpointMeta } from './endpoints.js';
@ -10,7 +10,7 @@ export type Response = Record<string, any> | void;
// TODO: paramsの型をT['params']のスキーマ定義から推論する
type executor<T extends IEndpointMeta, Ps extends Schema> =
(params: SchemaType<Ps>, user: T['requireCredential'] extends true ? CacheableLocalUser : CacheableLocalUser | null, token: AccessToken | null, file?: any, cleanup?: () => any) =>
(params: SchemaType<Ps>, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any, cleanup?: () => any) =>
Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
const ajv = new Ajv({
@ -20,10 +20,10 @@ const ajv = new Ajv({
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
export default function <T extends IEndpointMeta, Ps extends Schema>(meta: T, paramDef: Ps, cb: executor<T, Ps>)
: (params: any, user: T['requireCredential'] extends true ? CacheableLocalUser : CacheableLocalUser | null, token: AccessToken | null, file?: any) => Promise<any> {
: (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => Promise<any> {
const validate = ajv.compile(paramDef);
return (params: any, user: T['requireCredential'] extends true ? CacheableLocalUser : CacheableLocalUser | null, token: AccessToken | null, file?: any) => {
return (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => {
function cleanup() {
fs.unlink(file.path, () => {});
}

View file

@ -5,7 +5,7 @@ import { Resolver } from '@/remote/activitypub/resolver.js';
import { extractDbHost } from '@/misc/convert-host.js';
import { Users, Notes } from '@/models/index.js';
import { Note } from '@/models/entities/note.js';
import { CacheableLocalUser, User } from '@/models/entities/user.js';
import { ILocalUser, User } from '@/models/entities/user.js';
import { isActor, isPost } from '@/remote/activitypub/type.js';
import { SchemaType } from '@/misc/schema.js';
import { HOUR } from '@/const.js';
@ -85,7 +85,7 @@ export default define(meta, paramDef, async (ps, me) => {
/***
* URIからUserかNoteを解決する
*/
async function fetchAny(uri: string, me: CacheableLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
async function fetchAny(uri: string, me: ILocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
// Stop if the host is blocked.
const host = extractDbHost(uri);
if (await shouldBlockInstance(host)) {
@ -122,7 +122,7 @@ async function fetchAny(uri: string, me: CacheableLocalUser | null | undefined):
);
}
async function mergePack(me: CacheableLocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
async function mergePack(me: ILocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
if (user != null) {
return {
type: 'User',

View file

@ -2,13 +2,13 @@ import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import { renderBlock } from '@/remote/activitypub/renderer/block.js';
import renderUndo from '@/remote/activitypub/renderer/undo.js';
import { deliver } from '@/queue/index.js';
import { CacheableUser } from '@/models/entities/user.js';
import { User } from '@/models/entities/user.js';
import { Blockings, Users } from '@/models/index.js';
import Logger from '../logger.js';
const logger = new Logger('blocking/delete');
export default async function(blocker: CacheableUser, blockee: CacheableUser) {
export default async function(blocker: User, blockee: User) {
const blocking = await Blockings.findOneBy({
blockerId: blocker.id,
blockeeId: blockee.id,

View file

@ -1,5 +1,5 @@
import { Not } from 'typeorm';
import { CacheableUser, User } from '@/models/entities/user.js';
import { User } from '@/models/entities/user.js';
import { UserGroup } from '@/models/entities/user-group.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { MessagingMessages, UserGroupJoinings, Mutings, Users } from '@/models/index.js';
@ -13,7 +13,7 @@ import renderCreate from '@/remote/activitypub/renderer/create.js';
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import { deliver } from '@/queue/index.js';
export async function createMessage(user: { id: User['id']; host: User['host']; }, recipientUser: CacheableUser | undefined, recipientGroup: UserGroup | undefined, text: string | null | undefined, file: DriveFile | null, uri?: string) {
export async function createMessage(user: { id: User['id']; host: User['host']; }, recipientUser: User | undefined, recipientGroup: UserGroup | undefined, text: string | null | undefined, file: DriveFile | null, uri?: string) {
const message = {
id: genId(),
createdAt: new Date(),

View file

@ -1,12 +1,12 @@
import { ArrayOverlap, Not } from 'typeorm';
import { publishNoteStream } from '@/services/stream.js';
import { CacheableUser } from '@/models/entities/user.js';
import { User } from '@/models/entities/user.js';
import { Note } from '@/models/entities/note.js';
import { PollVotes, NoteWatchings, Polls, Blockings, NoteThreadMutings } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js';
import { createNotification } from '@/services/create-notification.js';
export async function vote(user: CacheableUser, note: Note, choice: number): Promise<void> {
export async function vote(user: User, note: Note, choice: number): Promise<void> {
const poll = await Polls.findOneBy({ noteId: note.id });
if (poll == null) throw new Error('poll not found');

View file

@ -1,5 +1,5 @@
import { IsNull } from 'typeorm';
import { CacheableLocalUser, ILocalUser, User } from '@/models/entities/user.js';
import { ILocalUser, User } from '@/models/entities/user.js';
import { Users } from '@/models/index.js';
import { Cache } from '@/misc/cache.js';
import { subscriber } from '@/db/redis.js';
@ -8,7 +8,7 @@ export const userByIdCache = new Cache<User>(
Infinity,
async (id) => await Users.findOneBy({ id, isDeleted: false }) ?? undefined,
);
export const localUserByNativeTokenCache = new Cache<CacheableLocalUser>(
export const localUserByNativeTokenCache = new Cache<ILocalUser>(
Infinity,
async (token) => await Users.findOneBy({ token, host: IsNull(), isDeleted: false }) as ILocalUser | null ?? undefined,
);