mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-03 23:16:28 +09:00
refactor: migrate to typeorm 3.0 (#8443)
* wip * wip * wip * Update following.ts * wip * wip * wip * Update resolve-user.ts * maxQueryExecutionTime * wip * wip
This commit is contained in:
@ -21,9 +21,8 @@ export default async (token: string | null): Promise<[CacheableLocalUser | null
|
||||
}
|
||||
|
||||
if (isNativeToken(token)) {
|
||||
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる
|
||||
const user = await localUserByNativeTokenCache.fetch(token,
|
||||
() => Users.findOne({ token }).then(x => x || null) as Promise<ILocalUser | null>);
|
||||
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>);
|
||||
|
||||
if (user == null) {
|
||||
throw new AuthenticationError('user not found');
|
||||
@ -48,13 +47,13 @@ export default async (token: string | null): Promise<[CacheableLocalUser | null
|
||||
});
|
||||
|
||||
const user = await localUserByIdCache.fetch(accessToken.userId,
|
||||
() => Users.findOne({
|
||||
id: accessToken.userId, // findOne(accessToken.userId) のように書かないのは後方互換性のため
|
||||
() => Users.findOneBy({
|
||||
id: accessToken.userId,
|
||||
}) as Promise<ILocalUser>);
|
||||
|
||||
if (accessToken.appId) {
|
||||
const app = await appCache.fetch(accessToken.appId,
|
||||
() => Apps.findOneOrFail(accessToken.appId!));
|
||||
() => Apps.findOneByOrFail({ id: accessToken.appId! }));
|
||||
|
||||
return [user, {
|
||||
id: accessToken.id,
|
||||
|
@ -7,7 +7,7 @@ import { Notes, Users } from '@/models/index.js';
|
||||
* Get note for API processing
|
||||
*/
|
||||
export async function getNote(noteId: Note['id']) {
|
||||
const note = await Notes.findOne(noteId);
|
||||
const note = await Notes.findOneBy({ id: noteId });
|
||||
|
||||
if (note == null) {
|
||||
throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', 'No such note.');
|
||||
@ -20,7 +20,7 @@ export async function getNote(noteId: Note['id']) {
|
||||
* Get user for API processing
|
||||
*/
|
||||
export async function getUser(userId: User['id']) {
|
||||
const user = await Users.findOne(userId);
|
||||
const user = await Users.findOneBy({ id: userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new IdentifiableError('15348ddd-432d-49c2-8a5a-8069753becff', 'No such user.');
|
||||
|
@ -11,7 +11,7 @@ export async function injectFeatured(timeline: Note[], user?: User | null) {
|
||||
if (timeline.length < 5) return;
|
||||
|
||||
if (user) {
|
||||
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||
if (!profile.injectFeaturedNote) return;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ export async function injectPromo(timeline: Note[], user?: User | null) {
|
||||
|
||||
// TODO: readやexpireフィルタはクエリ側でやる
|
||||
|
||||
const reads = user ? await PromoReads.find({
|
||||
const reads = user ? await PromoReads.findBy({
|
||||
userId: user.id,
|
||||
}) : [];
|
||||
|
||||
@ -22,10 +22,10 @@ export async function injectPromo(timeline: Note[], user?: User | null) {
|
||||
// Pick random promo
|
||||
const promo = promos[Math.floor(Math.random() * promos.length)];
|
||||
|
||||
const note = await Notes.findOneOrFail(promo.noteId);
|
||||
const note = await Notes.findOneByOrFail({ id: promo.noteId });
|
||||
|
||||
// Join
|
||||
note.user = await Users.findOneOrFail(note.userId);
|
||||
note.user = await Users.findOneByOrFail({ id: note.userId });
|
||||
|
||||
(note as any)._prId_ = rndstr('a-z0-9', 8);
|
||||
|
||||
|
@ -23,7 +23,7 @@ export async function readUserMessagingMessage(
|
||||
) {
|
||||
if (messageIds.length === 0) return;
|
||||
|
||||
const messages = await MessagingMessages.find({
|
||||
const messages = await MessagingMessages.findBy({
|
||||
id: In(messageIds),
|
||||
});
|
||||
|
||||
@ -64,7 +64,7 @@ export async function readGroupMessagingMessage(
|
||||
if (messageIds.length === 0) return;
|
||||
|
||||
// check joined
|
||||
const joining = await UserGroupJoinings.findOne({
|
||||
const joining = await UserGroupJoinings.findOneBy({
|
||||
userId: userId,
|
||||
userGroupId: groupId,
|
||||
});
|
||||
@ -73,7 +73,7 @@ export async function readGroupMessagingMessage(
|
||||
throw new IdentifiableError('930a270c-714a-46b2-b776-ad27276dc569', 'Access denied (group).');
|
||||
}
|
||||
|
||||
const messages = await MessagingMessages.find({
|
||||
const messages = await MessagingMessages.findBy({
|
||||
id: In(messageIds),
|
||||
});
|
||||
|
||||
|
@ -36,7 +36,7 @@ export default function(ctx: Koa.Context, user: ILocalUser, redirect = false) {
|
||||
ip: ctx.ip,
|
||||
headers: ctx.headers,
|
||||
success: true,
|
||||
}).then(x => Signins.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Signins.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
// Publish signin event
|
||||
publishMainStream(user.id, 'signin', await Signins.pack(record));
|
||||
|
@ -4,12 +4,13 @@ import generateUserToken from './generate-native-user-token.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Users, UsedUsernames } from '@/models/index.js';
|
||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { IsNull } from 'typeorm';
|
||||
import { genId } from '@/misc/gen-id.js';
|
||||
import { toPunyNullable } from '@/misc/convert-host.js';
|
||||
import { UserKeypair } from '@/models/entities/user-keypair.js';
|
||||
import { usersChart } from '@/services/chart/index.js';
|
||||
import { UsedUsername } from '@/models/entities/used-username.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export async function signup(opts: {
|
||||
username: User['username'];
|
||||
@ -40,12 +41,12 @@ export async function signup(opts: {
|
||||
const secret = generateUserToken();
|
||||
|
||||
// Check username duplication
|
||||
if (await Users.findOne({ usernameLower: username.toLowerCase(), host: null })) {
|
||||
if (await Users.findOneBy({ usernameLower: username.toLowerCase(), host: IsNull() })) {
|
||||
throw new Error('DUPLICATED_USERNAME');
|
||||
}
|
||||
|
||||
// Check deleted username duplication
|
||||
if (await UsedUsernames.findOne({ username: username.toLowerCase() })) {
|
||||
if (await UsedUsernames.findOneBy({ username: username.toLowerCase() })) {
|
||||
throw new Error('USED_USERNAME');
|
||||
}
|
||||
|
||||
@ -69,10 +70,10 @@ export async function signup(opts: {
|
||||
let account!: User;
|
||||
|
||||
// Start transaction
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
const exist = await transactionalEntityManager.findOne(User, {
|
||||
await db.transaction(async transactionalEntityManager => {
|
||||
const exist = await transactionalEntityManager.findOneBy(User, {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: null,
|
||||
host: IsNull(),
|
||||
});
|
||||
|
||||
if (exist) throw new Error(' the username is already used');
|
||||
@ -84,8 +85,8 @@ export async function signup(opts: {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: toPunyNullable(host),
|
||||
token: secret,
|
||||
isAdmin: (await Users.count({
|
||||
host: null,
|
||||
isAdmin: (await Users.countBy({
|
||||
host: IsNull(),
|
||||
})) === 0,
|
||||
}));
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import define from '../../../define.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { signup } from '../../../common/signup.js';
|
||||
import { IsNull } from 'typeorm';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -29,9 +30,9 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, _me) => {
|
||||
const me = _me ? await Users.findOneOrFail(_me.id) : null;
|
||||
const noUsers = (await Users.count({
|
||||
host: null,
|
||||
const me = _me ? await Users.findOneByOrFail({ id: _me.id }) : null;
|
||||
const noUsers = (await Users.countBy({
|
||||
host: IsNull(),
|
||||
})) === 0;
|
||||
if (!noUsers && !me?.isAdmin) throw new Error('access denied');
|
||||
|
||||
|
@ -21,7 +21,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const ad = await Ads.findOne(ps.id);
|
||||
const ad = await Ads.findOneBy({ id: ps.id });
|
||||
|
||||
if (ad == null) throw new ApiError(meta.errors.noSuchAd);
|
||||
|
||||
|
@ -34,7 +34,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const ad = await Ads.findOne(ps.id);
|
||||
const ad = await Ads.findOneBy({ id: ps.id });
|
||||
|
||||
if (ad == null) throw new ApiError(meta.errors.noSuchAd);
|
||||
|
||||
|
@ -63,7 +63,7 @@ export default define(meta, paramDef, async (ps) => {
|
||||
title: ps.title,
|
||||
text: ps.text,
|
||||
imageUrl: ps.imageUrl,
|
||||
}).then(x => Announcements.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Announcements.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return Object.assign({}, announcement, { createdAt: announcement.createdAt.toISOString(), updatedAt: null });
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const announcement = await Announcements.findOne(ps.id);
|
||||
const announcement = await Announcements.findOneBy({ id: ps.id });
|
||||
|
||||
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||
|
||||
|
@ -69,7 +69,7 @@ export default define(meta, paramDef, async (ps) => {
|
||||
const announcements = await query.take(ps.limit).getMany();
|
||||
|
||||
for (const announcement of announcements) {
|
||||
(announcement as any).reads = await AnnouncementReads.count({
|
||||
(announcement as any).reads = await AnnouncementReads.countBy({
|
||||
announcementId: announcement.id,
|
||||
});
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const announcement = await Announcements.findOne(ps.id);
|
||||
const announcement = await Announcements.findOneBy({ id: ps.id });
|
||||
|
||||
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||
|
||||
|
@ -19,7 +19,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const files = await DriveFiles.find({
|
||||
const files = await DriveFiles.findBy({
|
||||
userId: ps.userId,
|
||||
});
|
||||
|
||||
|
@ -18,7 +18,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const files = await DriveFiles.find({
|
||||
const files = await DriveFiles.findBy({
|
||||
userId: IsNull(),
|
||||
});
|
||||
|
||||
|
@ -160,7 +160,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const file = ps.fileId ? await DriveFiles.findOne(ps.fileId) : await DriveFiles.findOne({
|
||||
const file = ps.fileId ? await DriveFiles.findOneBy({ id: ps.fileId }) : await DriveFiles.findOne({
|
||||
where: [{
|
||||
url: ps.url,
|
||||
}, {
|
||||
|
@ -1,7 +1,8 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection, In } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -25,7 +26,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const emojis = await Emojis.find({
|
||||
const emojis = await Emojis.findBy({
|
||||
id: In(ps.ids),
|
||||
});
|
||||
|
||||
@ -36,5 +37,5 @@ export default define(meta, paramDef, async (ps) => {
|
||||
});
|
||||
}
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
});
|
||||
|
@ -1,11 +1,11 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis, DriveFiles } from '@/models/index.js';
|
||||
import { genId } from '@/misc/gen-id.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import rndstr from 'rndstr';
|
||||
import { publishBroadcastStream } from '@/services/stream.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -32,7 +32,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const file = await DriveFiles.findOne(ps.fileId);
|
||||
const file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
|
||||
if (file == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
|
||||
@ -48,9 +48,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
originalUrl: file.url,
|
||||
publicUrl: file.webpublicUrl ?? file.url,
|
||||
type: file.webpublicType ?? file.type,
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Emojis.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
|
||||
publishBroadcastStream('emojiAdded', {
|
||||
emoji: await Emojis.pack(emoji.id),
|
||||
|
@ -1,11 +1,11 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { genId } from '@/misc/gen-id.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { DriveFile } from '@/models/entities/drive-file.js';
|
||||
import { uploadFromUrl } from '@/services/drive/upload-from-url.js';
|
||||
import { publishBroadcastStream } from '@/services/stream.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -44,7 +44,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const emoji = await Emojis.findOne(ps.emojiId);
|
||||
const emoji = await Emojis.findOneBy({ id: ps.emojiId });
|
||||
|
||||
if (emoji == null) {
|
||||
throw new ApiError(meta.errors.noSuchEmoji);
|
||||
@ -68,9 +68,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
originalUrl: driveFile.url,
|
||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
||||
type: driveFile.webpublicType ?? driveFile.type,
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Emojis.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
|
||||
publishBroadcastStream('emojiAdded', {
|
||||
emoji: await Emojis.pack(copied.id),
|
||||
|
@ -1,8 +1,9 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection, In } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -23,14 +24,14 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const emojis = await Emojis.find({
|
||||
const emojis = await Emojis.findBy({
|
||||
id: In(ps.ids),
|
||||
});
|
||||
|
||||
for (const emoji of emojis) {
|
||||
await Emojis.delete(emoji.id);
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
|
||||
insertModerationLog(me, 'deleteEmoji', {
|
||||
emoji: emoji,
|
||||
|
@ -1,8 +1,8 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -29,13 +29,13 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const emoji = await Emojis.findOne(ps.id);
|
||||
const emoji = await Emojis.findOneBy({ id: ps.id });
|
||||
|
||||
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
|
||||
|
||||
await Emojis.delete(emoji.id);
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
|
||||
insertModerationLog(me, 'deleteEmoji', {
|
||||
emoji: emoji,
|
||||
|
@ -1,7 +1,8 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection, In } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -25,7 +26,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const emojis = await Emojis.find({
|
||||
const emojis = await Emojis.findBy({
|
||||
id: In(ps.ids),
|
||||
});
|
||||
|
||||
@ -36,5 +37,5 @@ export default define(meta, paramDef, async (ps) => {
|
||||
});
|
||||
}
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
});
|
||||
|
@ -1,7 +1,8 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection, In } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -32,5 +33,5 @@ export default define(meta, paramDef, async (ps) => {
|
||||
aliases: ps.aliases,
|
||||
});
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
});
|
||||
|
@ -1,7 +1,8 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection, In } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -30,5 +31,5 @@ export default define(meta, paramDef, async (ps) => {
|
||||
category: ps.category,
|
||||
});
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import define from '../../../define.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { ApiError } from '../../../error.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -33,7 +33,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const emoji = await Emojis.findOne(ps.id);
|
||||
const emoji = await Emojis.findOneBy({ id: ps.id });
|
||||
|
||||
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
|
||||
|
||||
@ -44,5 +44,5 @@ export default define(meta, paramDef, async (ps) => {
|
||||
aliases: ps.aliases,
|
||||
});
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
await db.queryResultCache!.remove(['meta_emojis']);
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const files = await DriveFiles.find({
|
||||
const files = await DriveFiles.findBy({
|
||||
userHost: ps.host,
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const instance = await Instances.findOne({ host: toPuny(ps.host) });
|
||||
const instance = await Instances.findOneBy({ host: toPuny(ps.host) });
|
||||
|
||||
if (instance == null) {
|
||||
throw new Error('instance not found');
|
||||
|
@ -19,13 +19,13 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const followings = await Followings.find({
|
||||
const followings = await Followings.findBy({
|
||||
followerHost: ps.host,
|
||||
});
|
||||
|
||||
const pairs = await Promise.all(followings.map(f => Promise.all([
|
||||
Users.findOneOrFail(f.followerId),
|
||||
Users.findOneOrFail(f.followeeId),
|
||||
Users.findOneByOrFail({ id: f.followerId }),
|
||||
Users.findOneByOrFail({ id: f.followeeId }),
|
||||
])));
|
||||
|
||||
for (const pair of pairs) {
|
||||
|
@ -20,7 +20,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const instance = await Instances.findOne({ host: toPuny(ps.host) });
|
||||
const instance = await Instances.findOneBy({ host: toPuny(ps.host) });
|
||||
|
||||
if (instance == null) {
|
||||
throw new Error('instance not found');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import define from '../../define.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -16,15 +16,13 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async () => {
|
||||
const stats = await
|
||||
getConnection().query(`SELECT * FROM pg_indexes;`)
|
||||
.then(recs => {
|
||||
const res = [] as { tablename: string; indexname: string; }[];
|
||||
for (const rec of recs) {
|
||||
res.push(rec);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
const stats = await db.query(`SELECT * FROM pg_indexes;`).then(recs => {
|
||||
const res = [] as { tablename: string; indexname: string; }[];
|
||||
for (const rec of recs) {
|
||||
res.push(rec);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
return stats;
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { db } from '@/db/postgre.js';
|
||||
import define from '../../define.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -28,7 +28,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async () => {
|
||||
const sizes = await
|
||||
getConnection().query(`
|
||||
db.query(`
|
||||
SELECT relname AS "table", reltuples as "count", pg_total_relation_size(C.oid) AS "size"
|
||||
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
||||
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
|
@ -19,7 +19,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -18,7 +18,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -40,7 +40,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw e;
|
||||
});
|
||||
|
||||
const exist = await PromoNotes.findOne(note.id);
|
||||
const exist = await PromoNotes.findOneBy({ noteId: note.id });
|
||||
|
||||
if (exist != null) {
|
||||
throw new ApiError(meta.errors.alreadyPromoted);
|
||||
|
@ -33,7 +33,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -23,7 +23,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const report = await AbuseUserReports.findOne(ps.reportId);
|
||||
const report = await AbuseUserReports.findOneByOrFail({ id: ps.reportId });
|
||||
|
||||
if (report == null) {
|
||||
throw new Error('report not found');
|
||||
@ -31,7 +31,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
|
||||
if (ps.forward && report.targetUserHost != null) {
|
||||
const actor = await getInstanceActor();
|
||||
const targetUser = await Users.findOneOrFail(report.targetUserId);
|
||||
const targetUser = await Users.findOneByOrFail({ id: report.targetUserId });
|
||||
|
||||
deliver(actor, renderActivity(renderFlag(actor, [targetUser.uri!], report.comment)), targetUser.inbox);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import * as os from 'node:os';
|
||||
import si from 'systeminformation';
|
||||
import { getConnection } from 'typeorm';
|
||||
import define from '../../define.js';
|
||||
import { redisClient } from '../../../../db/redis.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -103,7 +103,7 @@ export default define(meta, paramDef, async () => {
|
||||
machine: os.hostname(),
|
||||
os: os.platform(),
|
||||
node: process.version,
|
||||
psql: await getConnection().query('SHOW server_version').then(x => x[0].server_version),
|
||||
psql: await db.query('SHOW server_version').then(x => x[0].server_version),
|
||||
redis: redisClient.server_info.redis_version,
|
||||
cpu: {
|
||||
model: os.cpus()[0].model,
|
||||
|
@ -23,13 +23,13 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
}
|
||||
|
||||
const _me = await Users.findOneOrFail(me.id);
|
||||
const _me = await Users.findOneByOrFail({ id: me.id });
|
||||
if ((_me.isModerator && !_me.isAdmin) && user.isAdmin) {
|
||||
throw new Error('cannot show info of admin');
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -23,7 +23,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
@ -58,12 +58,12 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
});
|
||||
|
||||
async function unFollowAll(follower: User) {
|
||||
const followings = await Followings.find({
|
||||
const followings = await Followings.findBy({
|
||||
followerId: follower.id,
|
||||
});
|
||||
|
||||
for (const following of followings) {
|
||||
const followee = await Users.findOne({
|
||||
const followee = await Users.findOneBy({
|
||||
id: following.followeeId,
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -20,7 +20,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId as string);
|
||||
const user = await Users.findOneBy({ id: ps.userId });
|
||||
|
||||
if (user == null) {
|
||||
throw new Error('user not found');
|
||||
|
@ -1,8 +1,8 @@
|
||||
import define from '../../define.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { Meta } from '@/models/entities/meta.js';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { DB_MAX_NOTE_TEXT_LENGTH } from '@/misc/hard-limits.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -396,7 +396,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
set.deeplIsPro = ps.deeplIsPro;
|
||||
}
|
||||
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
await db.transaction(async transactionalEntityManager => {
|
||||
const meta = await transactionalEntityManager.findOne(Meta, {
|
||||
order: {
|
||||
id: 'DESC',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import define from '../../define.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -30,7 +30,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
params.push('ANALYZE');
|
||||
}
|
||||
|
||||
getConnection().query('VACUUM ' + params.join(' '));
|
||||
db.query('VACUUM ' + params.join(' '));
|
||||
|
||||
insertModerationLog(me, 'vacuum', ps);
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
const announcements = await query.take(ps.limit).getMany();
|
||||
|
||||
if (user) {
|
||||
const reads = (await AnnouncementReads.find({
|
||||
const reads = (await AnnouncementReads.findBy({
|
||||
userId: user.id,
|
||||
})).map(x => x.announcementId);
|
||||
|
||||
|
@ -66,7 +66,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
let userGroupJoining;
|
||||
|
||||
if (ps.src === 'list' && ps.userListId) {
|
||||
userList = await UserLists.findOne({
|
||||
userList = await UserLists.findOneBy({
|
||||
id: ps.userListId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -75,7 +75,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchUserList);
|
||||
}
|
||||
} else if (ps.src === 'group' && ps.userGroupId) {
|
||||
userGroupJoining = await UserGroupJoinings.findOne({
|
||||
userGroupJoining = await UserGroupJoinings.findOneBy({
|
||||
userGroupId: ps.userGroupId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -100,7 +100,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
withReplies: ps.withReplies,
|
||||
withFile: ps.withFile,
|
||||
notify: ps.notify,
|
||||
}).then(x => Antennas.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Antennas.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
publishInternalEvent('antennaCreated', antenna);
|
||||
|
||||
|
@ -29,7 +29,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const antenna = await Antennas.findOne({
|
||||
const antenna = await Antennas.findOneBy({
|
||||
id: ps.antennaId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const antennas = await Antennas.find({
|
||||
const antennas = await Antennas.findBy({
|
||||
userId: me.id,
|
||||
});
|
||||
|
||||
|
@ -48,7 +48,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const antenna = await Antennas.findOne({
|
||||
const antenna = await Antennas.findOneBy({
|
||||
id: ps.antennaId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
// Fetch the antenna
|
||||
const antenna = await Antennas.findOne({
|
||||
const antenna = await Antennas.findOneBy({
|
||||
id: ps.antennaId,
|
||||
userId: me.id,
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Fetch the antenna
|
||||
const antenna = await Antennas.findOne({
|
||||
const antenna = await Antennas.findOneBy({
|
||||
id: ps.antennaId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -82,7 +82,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
let userGroupJoining;
|
||||
|
||||
if (ps.src === 'list' && ps.userListId) {
|
||||
userList = await UserLists.findOne({
|
||||
userList = await UserLists.findOneBy({
|
||||
id: ps.userListId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -91,7 +91,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchUserList);
|
||||
}
|
||||
} else if (ps.src === 'group' && ps.userGroupId) {
|
||||
userGroupJoining = await UserGroupJoinings.findOne({
|
||||
userGroupJoining = await UserGroupJoinings.findOneBy({
|
||||
userGroupId: ps.userGroupId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -115,7 +115,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
notify: ps.notify,
|
||||
});
|
||||
|
||||
publishInternalEvent('antennaUpdated', await Antennas.findOneOrFail(antenna.id));
|
||||
publishInternalEvent('antennaUpdated', await Antennas.findOneByOrFail({ id: antenna.id }));
|
||||
|
||||
return await Antennas.pack(antenna.id);
|
||||
});
|
||||
|
@ -97,7 +97,7 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
const type = parts.pop();
|
||||
|
||||
if (type === 'notes') {
|
||||
const note = await Notes.findOne(id);
|
||||
const note = await Notes.findOneBy({ id });
|
||||
|
||||
if (note) {
|
||||
return {
|
||||
@ -106,7 +106,7 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
};
|
||||
}
|
||||
} else if (type === 'users') {
|
||||
const user = await Users.findOne(id);
|
||||
const user = await Users.findOneBy({ id });
|
||||
|
||||
if (user) {
|
||||
return {
|
||||
@ -124,8 +124,8 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
// URI(AP Object id)としてDB検索
|
||||
{
|
||||
const [user, note] = await Promise.all([
|
||||
Users.findOne({ uri: uri }),
|
||||
Notes.findOne({ uri: uri }),
|
||||
Users.findOneBy({ uri: uri }),
|
||||
Notes.findOneBy({ uri: uri }),
|
||||
]);
|
||||
|
||||
const packed = await mergePack(user, note);
|
||||
@ -145,7 +145,7 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
const type = parts.pop();
|
||||
|
||||
if (type === 'notes') {
|
||||
const note = await Notes.findOne(id);
|
||||
const note = await Notes.findOneBy({ id });
|
||||
|
||||
if (note) {
|
||||
return {
|
||||
@ -154,7 +154,7 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
};
|
||||
}
|
||||
} else if (type === 'users') {
|
||||
const user = await Users.findOne(id);
|
||||
const user = await Users.findOneBy({ id });
|
||||
|
||||
if (user) {
|
||||
return {
|
||||
@ -166,8 +166,8 @@ async function fetchAny(uri: string): Promise<SchemaType<typeof meta['res']> | n
|
||||
}
|
||||
|
||||
const [user, note] = await Promise.all([
|
||||
Users.findOne({ uri: object.id }),
|
||||
Notes.findOne({ uri: object.id }),
|
||||
Users.findOneBy({ uri: object.id }),
|
||||
Notes.findOneBy({ uri: object.id }),
|
||||
]);
|
||||
|
||||
const packed = await mergePack(user, note);
|
||||
|
@ -47,7 +47,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
permission,
|
||||
callbackUrl: ps.callbackUrl,
|
||||
secret: secret,
|
||||
}).then(x => Apps.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Apps.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return await Apps.pack(app, null, {
|
||||
detail: true,
|
||||
|
@ -33,7 +33,7 @@ export default define(meta, paramDef, async (ps, user, token) => {
|
||||
const isSecure = user != null && token == null;
|
||||
|
||||
// Lookup app
|
||||
const ap = await Apps.findOne(ps.appId);
|
||||
const ap = await Apps.findOneBy({ id: ps.appId });
|
||||
|
||||
if (ap == null) {
|
||||
throw new ApiError(meta.errors.noSuchApp);
|
||||
|
@ -33,7 +33,7 @@ export const paramDef = {
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Fetch token
|
||||
const session = await AuthSessions
|
||||
.findOne({ token: ps.token });
|
||||
.findOneBy({ token: ps.token });
|
||||
|
||||
if (session == null) {
|
||||
throw new ApiError(meta.errors.noSuchSession);
|
||||
@ -43,14 +43,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
const accessToken = secureRndstr(32, true);
|
||||
|
||||
// Fetch exist access token
|
||||
const exist = await AccessTokens.findOne({
|
||||
const exist = await AccessTokens.findOneBy({
|
||||
appId: session.appId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
// Lookup app
|
||||
const app = await Apps.findOneOrFail(session.appId);
|
||||
const app = await Apps.findOneByOrFail({ id: session.appId });
|
||||
|
||||
// Generate Hash
|
||||
const sha256 = crypto.createHash('sha256');
|
||||
|
@ -46,7 +46,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
// Lookup app
|
||||
const app = await Apps.findOne({
|
||||
const app = await Apps.findOneBy({
|
||||
secret: ps.appSecret,
|
||||
});
|
||||
|
||||
@ -63,7 +63,7 @@ export default define(meta, paramDef, async (ps) => {
|
||||
createdAt: new Date(),
|
||||
appId: app.id,
|
||||
token: token,
|
||||
}).then(x => AuthSessions.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => AuthSessions.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return {
|
||||
token: doc.token,
|
||||
|
@ -48,7 +48,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Lookup session
|
||||
const session = await AuthSessions.findOne({
|
||||
const session = await AuthSessions.findOneBy({
|
||||
token: ps.token,
|
||||
});
|
||||
|
||||
|
@ -57,7 +57,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
// Lookup app
|
||||
const app = await Apps.findOne({
|
||||
const app = await Apps.findOneBy({
|
||||
secret: ps.appSecret,
|
||||
});
|
||||
|
||||
@ -66,7 +66,7 @@ export default define(meta, paramDef, async (ps) => {
|
||||
}
|
||||
|
||||
// Fetch token
|
||||
const session = await AuthSessions.findOne({
|
||||
const session = await AuthSessions.findOneBy({
|
||||
token: ps.token,
|
||||
appId: app.id,
|
||||
});
|
||||
@ -80,7 +80,7 @@ export default define(meta, paramDef, async (ps) => {
|
||||
}
|
||||
|
||||
// Lookup access token
|
||||
const accessToken = await AccessTokens.findOneOrFail({
|
||||
const accessToken = await AccessTokens.findOneByOrFail({
|
||||
appId: app.id,
|
||||
userId: session.userId,
|
||||
});
|
||||
|
@ -54,7 +54,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const blocker = await Users.findOneOrFail(user.id);
|
||||
const blocker = await Users.findOneByOrFail({ id: user.id });
|
||||
|
||||
// 自分自身
|
||||
if (user.id === ps.userId) {
|
||||
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check if already blocking
|
||||
const exist = await Blockings.findOne({
|
||||
const exist = await Blockings.findOneBy({
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
});
|
||||
|
@ -54,7 +54,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const blocker = await Users.findOneOrFail(user.id);
|
||||
const blocker = await Users.findOneByOrFail({ id: user.id });
|
||||
|
||||
// Check if the blockee is yourself
|
||||
if (user.id === ps.userId) {
|
||||
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check not blocking
|
||||
const exist = await Blockings.findOne({
|
||||
const exist = await Blockings.findOneBy({
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
});
|
||||
|
@ -40,7 +40,7 @@ export const paramDef = {
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
let banner = null;
|
||||
if (ps.bannerId != null) {
|
||||
banner = await DriveFiles.findOne({
|
||||
banner = await DriveFiles.findOneBy({
|
||||
id: ps.bannerId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -57,7 +57,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
name: ps.name,
|
||||
description: ps.description || null,
|
||||
bannerId: banner ? banner.id : null,
|
||||
} as Channel).then(x => Channels.findOneOrFail(x.identifiers[0]));
|
||||
} as Channel).then(x => Channels.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return await Channels.pack(channel, user);
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const channel = await Channels.findOne({
|
||||
const channel = await Channels.findOneBy({
|
||||
id: ps.channelId,
|
||||
});
|
||||
|
||||
|
@ -32,7 +32,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const channel = await Channels.findOne({
|
||||
const channel = await Channels.findOneBy({
|
||||
id: ps.channelId,
|
||||
});
|
||||
|
||||
|
@ -43,7 +43,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const channel = await Channels.findOne({
|
||||
const channel = await Channels.findOneBy({
|
||||
id: ps.channelId,
|
||||
});
|
||||
|
||||
|
@ -29,7 +29,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const channel = await Channels.findOne({
|
||||
const channel = await Channels.findOneBy({
|
||||
id: ps.channelId,
|
||||
});
|
||||
|
||||
|
@ -49,7 +49,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const channel = await Channels.findOne({
|
||||
const channel = await Channels.findOneBy({
|
||||
id: ps.channelId,
|
||||
});
|
||||
|
||||
@ -64,7 +64,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
// eslint:disable-next-line:no-unnecessary-initializer
|
||||
let banner = undefined;
|
||||
if (ps.bannerId != null) {
|
||||
banner = await DriveFiles.findOne({
|
||||
banner = await DriveFiles.findOneBy({
|
||||
id: ps.bannerId,
|
||||
userId: me.id,
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const clip = await Clips.findOne({
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -57,7 +57,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw e;
|
||||
});
|
||||
|
||||
const exist = await ClipNotes.findOne({
|
||||
const exist = await ClipNotes.findOneBy({
|
||||
noteId: note.id,
|
||||
clipId: clip.id,
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
name: ps.name,
|
||||
isPublic: ps.isPublic,
|
||||
description: ps.description,
|
||||
}).then(x => Clips.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => Clips.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return await Clips.pack(clip);
|
||||
});
|
||||
|
@ -28,7 +28,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const clip = await Clips.findOne({
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const clips = await Clips.find({
|
||||
const clips = await Clips.findBy({
|
||||
userId: me.id,
|
||||
});
|
||||
|
||||
|
@ -45,7 +45,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const clip = await Clips.findOne({
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
});
|
||||
|
||||
|
@ -35,7 +35,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
// Fetch the clip
|
||||
const clip = await Clips.findOne({
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
});
|
||||
|
||||
|
@ -38,7 +38,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Fetch the clip
|
||||
const clip = await Clips.findOne({
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -39,7 +39,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Fetch file
|
||||
const file = await DriveFiles.findOne({
|
||||
const file = await DriveFiles.findOneBy({
|
||||
id: ps.fileId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const file = await DriveFiles.findOne({
|
||||
const file = await DriveFiles.findOneBy({
|
||||
md5: ps.md5,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const file = await DriveFiles.findOne(ps.fileId);
|
||||
const file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
|
@ -29,7 +29,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const files = await DriveFiles.find({
|
||||
const files = await DriveFiles.findBy({
|
||||
md5: ps.md5,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
import define from '../../../define.js';
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import { IsNull } from 'typeorm';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -30,10 +31,10 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const files = await DriveFiles.find({
|
||||
const files = await DriveFiles.findBy({
|
||||
name: ps.name,
|
||||
userId: user.id,
|
||||
folderId: ps.folderId,
|
||||
folderId: ps.folderId ?? IsNull(),
|
||||
});
|
||||
|
||||
return await Promise.all(files.map(file => DriveFiles.pack(file, { self: true })));
|
||||
|
@ -51,7 +51,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
let file: DriveFile | undefined;
|
||||
|
||||
if (ps.fileId) {
|
||||
file = await DriveFiles.findOne(ps.fileId);
|
||||
file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
} else if (ps.url) {
|
||||
file = await DriveFiles.findOne({
|
||||
where: [{
|
||||
|
@ -58,7 +58,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const file = await DriveFiles.findOne(ps.fileId);
|
||||
const file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
@ -81,7 +81,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
if (ps.folderId === null) {
|
||||
file.folderId = null;
|
||||
} else {
|
||||
const folder = await DriveFolders.findOne({
|
||||
const folder = await DriveFolders.findOneBy({
|
||||
id: ps.folderId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -41,7 +41,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
let parent = null;
|
||||
if (ps.parentId) {
|
||||
// Fetch parent folder
|
||||
parent = await DriveFolders.findOne({
|
||||
parent = await DriveFolders.findOneBy({
|
||||
id: ps.parentId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -58,7 +58,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
name: ps.name,
|
||||
parentId: parent !== null ? parent.id : null,
|
||||
userId: user.id,
|
||||
}).then(x => DriveFolders.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => DriveFolders.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
const folderObj = await DriveFolders.pack(folder);
|
||||
|
||||
|
@ -36,7 +36,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Get folder
|
||||
const folder = await DriveFolders.findOne({
|
||||
const folder = await DriveFolders.findOneBy({
|
||||
id: ps.folderId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -46,8 +46,8 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
|
||||
const [childFoldersCount, childFilesCount] = await Promise.all([
|
||||
DriveFolders.count({ parentId: folder.id }),
|
||||
DriveFiles.count({ folderId: folder.id }),
|
||||
DriveFolders.countBy({ parentId: folder.id }),
|
||||
DriveFiles.countBy({ folderId: folder.id }),
|
||||
]);
|
||||
|
||||
if (childFoldersCount !== 0 || childFilesCount !== 0) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import define from '../../../define.js';
|
||||
import { DriveFolders } from '@/models/index.js';
|
||||
import { IsNull } from 'typeorm';
|
||||
|
||||
export const meta = {
|
||||
tags: ['drive'],
|
||||
@ -30,10 +31,10 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const folders = await DriveFolders.find({
|
||||
const folders = await DriveFolders.findBy({
|
||||
name: ps.name,
|
||||
userId: user.id,
|
||||
parentId: ps.parentId,
|
||||
parentId: ps.parentId ?? IsNull(),
|
||||
});
|
||||
|
||||
return await Promise.all(folders.map(folder => DriveFolders.pack(folder)));
|
||||
|
@ -35,7 +35,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Get folder
|
||||
const folder = await DriveFolders.findOne({
|
||||
const folder = await DriveFolders.findOneBy({
|
||||
id: ps.folderId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Fetch folder
|
||||
const folder = await DriveFolders.findOne({
|
||||
const folder = await DriveFolders.findOneBy({
|
||||
id: ps.folderId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
folder.parentId = null;
|
||||
} else {
|
||||
// Get parent folder
|
||||
const parent = await DriveFolders.findOne({
|
||||
const parent = await DriveFolders.findOneBy({
|
||||
id: ps.parentId,
|
||||
userId: user.id,
|
||||
});
|
||||
@ -78,9 +78,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
|
||||
// Check if the circular reference will occur
|
||||
async function checkCircle(folderId: any): Promise<boolean> {
|
||||
async function checkCircle(folderId: string): Promise<boolean> {
|
||||
// Fetch folder
|
||||
const folder2 = await DriveFolders.findOne({
|
||||
const folder2 = await DriveFolders.findOneBy({
|
||||
id: folderId,
|
||||
});
|
||||
|
||||
|
@ -28,7 +28,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const instance = await Instances
|
||||
.findOne({ host: toPuny(ps.host) });
|
||||
.findOneBy({ host: toPuny(ps.host) });
|
||||
|
||||
return instance ? await Instances.pack(instance) : null;
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check if already following
|
||||
const exist = await Followings.findOne({
|
||||
const exist = await Followings.findOneBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check not following
|
||||
const exist = await Followings.findOne({
|
||||
const exist = await Followings.findOneBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check not following
|
||||
const exist = await Followings.findOne({
|
||||
const exist = await Followings.findOneBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const reqs = await FollowRequests.find({
|
||||
const reqs = await FollowRequests.findBy({
|
||||
followeeId: user.id,
|
||||
});
|
||||
|
||||
|
@ -45,7 +45,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const files = (await Promise.all(ps.fileIds.map(fileId =>
|
||||
DriveFiles.findOne({
|
||||
DriveFiles.findOneBy({
|
||||
id: fileId,
|
||||
userId: user.id,
|
||||
})
|
||||
@ -64,7 +64,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
userId: user.id,
|
||||
isSensitive: ps.isSensitive,
|
||||
fileIds: files.map(file => file.id),
|
||||
})).then(x => GalleryPosts.findOneOrFail(x.identifiers[0]));
|
||||
})).then(x => GalleryPosts.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return await GalleryPosts.pack(post, user);
|
||||
});
|
||||
|
@ -28,7 +28,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const post = await GalleryPosts.findOne({
|
||||
const post = await GalleryPosts.findOneBy({
|
||||
id: ps.postId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -41,7 +41,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const post = await GalleryPosts.findOne(ps.postId);
|
||||
const post = await GalleryPosts.findOneBy({ id: ps.postId });
|
||||
if (post == null) {
|
||||
throw new ApiError(meta.errors.noSuchPost);
|
||||
}
|
||||
@ -51,7 +51,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
|
||||
// if already liked
|
||||
const exist = await GalleryLikes.findOne({
|
||||
const exist = await GalleryLikes.findOneBy({
|
||||
postId: post.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const post = await GalleryPosts.findOne({
|
||||
const post = await GalleryPosts.findOneBy({
|
||||
id: ps.postId,
|
||||
});
|
||||
|
||||
|
@ -34,12 +34,12 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const post = await GalleryPosts.findOne(ps.postId);
|
||||
const post = await GalleryPosts.findOneBy({ id: ps.postId });
|
||||
if (post == null) {
|
||||
throw new ApiError(meta.errors.noSuchPost);
|
||||
}
|
||||
|
||||
const exist = await GalleryLikes.findOne({
|
||||
const exist = await GalleryLikes.findOneBy({
|
||||
postId: post.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
@ -45,7 +45,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const files = (await Promise.all(ps.fileIds.map(fileId =>
|
||||
DriveFiles.findOne({
|
||||
DriveFiles.findOneBy({
|
||||
id: fileId,
|
||||
userId: user.id,
|
||||
})
|
||||
@ -66,7 +66,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
fileIds: files.map(file => file.id),
|
||||
});
|
||||
|
||||
const post = await GalleryPosts.findOneOrFail(ps.postId);
|
||||
const post = await GalleryPosts.findOneByOrFail({ id: ps.postId });
|
||||
|
||||
return await GalleryPosts.pack(post, user);
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async () => {
|
||||
const count = await Users.count({
|
||||
const count = await Users.countBy({
|
||||
lastActiveDate: MoreThan(new Date(Date.now() - USER_ONLINE_THRESHOLD)),
|
||||
});
|
||||
|
||||
|
@ -33,7 +33,7 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const hashtag = await Hashtags.findOne({ name: normalizeForSearch(ps.tag) });
|
||||
const hashtag = await Hashtags.findOneBy({ name: normalizeForSearch(ps.tag) });
|
||||
if (hashtag == null) {
|
||||
throw new ApiError(meta.errors.noSuchHashtag);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user