refactor: resolve #7139
This commit is contained in:
@@ -6,7 +6,6 @@ import { MessagingMessage } from '../../models/entities/messaging-message';
|
||||
import { Notes, Users, UserPublickeys, MessagingMessages } from '../../models';
|
||||
import { IObject, getApId } from './type';
|
||||
import { resolvePerson } from './models/person';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import escapeRegexp = require('escape-regexp');
|
||||
|
||||
export default class DbResolver {
|
||||
@@ -99,7 +98,7 @@ export default class DbResolver {
|
||||
|
||||
if (user == null) return null;
|
||||
|
||||
const key = await UserPublickeys.findOne(user.id).then(ensure);
|
||||
const key = await UserPublickeys.findOneOrFail(user.id);
|
||||
|
||||
return {
|
||||
user,
|
||||
|
@@ -5,7 +5,6 @@ import { fetchMeta } from '../../../misc/fetch-meta';
|
||||
import { apLogger } from '../logger';
|
||||
import { DriveFile } from '../../../models/entities/drive-file';
|
||||
import { DriveFiles } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
const logger = apLogger;
|
||||
|
||||
@@ -40,7 +39,7 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive
|
||||
uri: image.url
|
||||
});
|
||||
|
||||
file = await DriveFiles.findOne(file.id).then(ensure);
|
||||
file = await DriveFiles.findOneOrFail(file.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import { IObject, getOneApId, getApId, getOneApHrefNullable, validPost, IPost, i
|
||||
import { Emoji } from '../../../models/entities/emoji';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
import { getApLock } from '../../../misc/app-lock';
|
||||
import { createMessage } from '../../../services/messages/create';
|
||||
import { parseAudience } from '../audience';
|
||||
@@ -201,7 +200,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||
|
||||
// vote
|
||||
if (reply && reply.hasPoll) {
|
||||
const poll = await Polls.findOne(reply.id).then(ensure);
|
||||
const poll = await Polls.findOneOrFail(reply.id);
|
||||
|
||||
const tryCreateVote = async (name: string, index: number): Promise<null> => {
|
||||
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
||||
|
@@ -24,7 +24,6 @@ import { toPuny } from '../../../misc/convert-host';
|
||||
import { UserProfile } from '../../../models/entities/user-profile';
|
||||
import { validActor } from '../../../remote/activitypub/type';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
import { toArray } from '../../../prelude/array';
|
||||
import { fetchInstanceMetadata } from '../../../services/fetch-instance-metadata';
|
||||
import { normalizeForSearch } from '../../../misc/normalize-for-search';
|
||||
@@ -457,7 +456,7 @@ export function analyzeAttachments(attachments: IObject | IObject[] | undefined)
|
||||
}
|
||||
|
||||
export async function updateFeatured(userId: User['id']) {
|
||||
const user = await Users.findOne(userId).then(ensure);
|
||||
const user = await Users.findOneOrFail(userId);
|
||||
if (!Users.isRemoteUser(user)) return;
|
||||
if (!user.featured) return;
|
||||
|
||||
|
@@ -1,13 +1,12 @@
|
||||
import config from '../../../config';
|
||||
import { Users } from '../../../models';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
/**
|
||||
* Convert (local|remote)(Follower|Followee)ID to URL
|
||||
* @param id Follower|Followee ID
|
||||
*/
|
||||
export default async function renderFollowUser(id: User['id']): Promise<any> {
|
||||
const user = await Users.findOne(id).then(ensure);
|
||||
const user = await Users.findOneOrFail(id);
|
||||
return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri;
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import { IActivity } from '../type';
|
||||
import { LdSignature } from '../misc/ld-signature';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { UserKeypairs } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export const renderActivity = (x: any): IActivity | null => {
|
||||
if (x == null) return null;
|
||||
@@ -24,9 +23,9 @@ export const renderActivity = (x: any): IActivity | null => {
|
||||
export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => {
|
||||
if (activity == null) return null;
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
const keypair = await UserKeypairs.findOneOrFail({
|
||||
userId: user.id
|
||||
}).then(ensure);
|
||||
});
|
||||
|
||||
const obj = {
|
||||
// as non-standards
|
||||
|
@@ -10,7 +10,6 @@ import { DriveFiles, Notes, Users, Emojis, Polls } from '../../../models';
|
||||
import { In } from 'typeorm';
|
||||
import { Emoji } from '../../../models/entities/emoji';
|
||||
import { Poll } from '../../../models/entities/poll';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> {
|
||||
const getPromisedFiles = async (ids: string[]) => {
|
||||
@@ -54,7 +53,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
|
||||
}
|
||||
}
|
||||
|
||||
const user = await Users.findOne(note.userId).then(ensure);
|
||||
const user = await Users.findOneOrFail(note.userId);
|
||||
|
||||
const attributedTo = `${config.url}/users/${user.id}`;
|
||||
|
||||
|
@@ -9,7 +9,6 @@ import renderEmoji from './emoji';
|
||||
import { IIdentifier } from '../models/identifier';
|
||||
import renderHashtag from './hashtag';
|
||||
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export async function renderPerson(user: ILocalUser) {
|
||||
const id = `${config.url}/users/${user.id}`;
|
||||
@@ -18,7 +17,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
const [avatar, banner, profile] = await Promise.all([
|
||||
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
||||
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
||||
UserProfiles.findOne(user.id).then(ensure)
|
||||
UserProfiles.findOneOrFail(user.id)
|
||||
]);
|
||||
|
||||
const attachment: {
|
||||
@@ -50,7 +49,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
...hashtagTags,
|
||||
];
|
||||
|
||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
||||
const keypair = await UserKeypairs.findOneOrFail(user.id);
|
||||
|
||||
const person = {
|
||||
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
||||
|
@@ -6,7 +6,6 @@ import * as crypto from 'crypto';
|
||||
import config from '../../config';
|
||||
import { ILocalUser } from '../../models/entities/user';
|
||||
import { UserKeypairs } from '../../models';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { getAgentByUrl } from '../../misc/fetch';
|
||||
import { URL } from 'url';
|
||||
import got from 'got';
|
||||
@@ -23,9 +22,9 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
||||
sha256.update(data);
|
||||
const hash = sha256.digest('base64');
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
const keypair = await UserKeypairs.findOneOrFail({
|
||||
userId: user.id
|
||||
}).then(ensure);
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const req = https.request({
|
||||
@@ -75,9 +74,9 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
||||
export async function signedGet(url: string, user: ILocalUser) {
|
||||
const timeout = 10 * 1000;
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
const keypair = await UserKeypairs.findOneOrFail({
|
||||
userId: user.id
|
||||
}).then(ensure);
|
||||
});
|
||||
|
||||
const req = got.get<any>(url, {
|
||||
headers: {
|
||||
|
Reference in New Issue
Block a user