server: fix various type errors in services

This commit is contained in:
Norm 2022-12-07 14:59:08 -05:00
parent b8fb7a38cc
commit 3dec9a47f0
9 changed files with 21 additions and 18 deletions

View file

@ -6,7 +6,7 @@ import { isUserRelated } from '@/misc/is-user-related.js';
import { publishAntennaStream, publishMainStream } from '@/services/stream.js'; import { publishAntennaStream, publishMainStream } from '@/services/stream.js';
import { User } from '@/models/entities/user.js'; import { User } from '@/models/entities/user.js';
export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }) { export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }): Promise<void> {
// 通知しない設定になっているか、自分自身の投稿なら既読にする // 通知しない設定になっているか、自分自身の投稿なら既読にする
const read = !antenna.notify || (antenna.userId === noteUser.id); const read = !antenna.notify || (antenna.userId === noteUser.id);

View file

@ -9,7 +9,7 @@ export async function createNotification(
notifieeId: User['id'], notifieeId: User['id'],
type: Notification['type'], type: Notification['type'],
data: Partial<Notification>, data: Partial<Notification>,
) { ): Promise<Notification | null> {
if (data.notifierId && (notifieeId === data.notifierId)) { if (data.notifierId && (notifieeId === data.notifierId)) {
return null; return null;
} }

View file

@ -81,6 +81,7 @@ type NodeInfo = {
nodeName?: any; nodeName?: any;
nodeDescription?: any; nodeDescription?: any;
description?: any; description?: any;
themeColor?: any;
maintainer?: { maintainer?: {
name?: any; name?: any;
email?: any; email?: any;
@ -125,7 +126,8 @@ async function fetchNodeinfo(instance: Instance): Promise<NodeInfo> {
return info as NodeInfo; return info as NodeInfo;
} catch (e) { } catch (e) {
logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${e.message}`); const message = e instanceof Error ? e.message : e;
logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${message}`);
throw e; throw e;
} }

View file

@ -2,7 +2,7 @@ import { ModerationLogs } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js'; import { genId } from '@/misc/gen-id.js';
import { User } from '@/models/entities/user.js'; import { User } from '@/models/entities/user.js';
export async function insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record<string, any>) { export async function insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record<string, any>): Promise<void> {
await ModerationLogs.insert({ await ModerationLogs.insert({
id: genId(), id: genId(),
createdAt: new Date(), createdAt: new Date(),

View file

@ -16,7 +16,7 @@ type pushNotificationsTypes = {
}; };
// Reduce the content of the push message because of the character limit // Reduce the content of the push message because of the character limit
function truncateNotification(notification: Packed<'Notification'>): any { function truncateNotification(notification: Packed<'Notification'>): Record<string, any> {
if (notification.note) { if (notification.note) {
return { return {
...notification, ...notification,
@ -37,7 +37,7 @@ function truncateNotification(notification: Packed<'Notification'>): any {
return notification; return notification;
} }
export async function pushNotification<T extends keyof pushNotificationsTypes>(userId: string, type: T, body: pushNotificationsTypes[T]) { export async function pushNotification<T extends keyof pushNotificationsTypes>(userId: string, type: T, body: pushNotificationsTypes[T]): Promise<void> {
const meta = await fetchMeta(); const meta = await fetchMeta();
// Register key pair information // Register key pair information

View file

@ -36,7 +36,7 @@ export async function getRelayActor(): Promise<ILocalUser> {
return created as ILocalUser; return created as ILocalUser;
} }
export async function addRelay(inbox: string) { export async function addRelay(inbox: string): Promise<Relay> {
const relay = await Relays.insert({ const relay = await Relays.insert({
id: genId(), id: genId(),
inbox, inbox,
@ -51,7 +51,7 @@ export async function addRelay(inbox: string) {
return relay; return relay;
} }
export async function removeRelay(inbox: string) { export async function removeRelay(inbox: string): Promise<void> {
const relay = await Relays.findOneBy({ const relay = await Relays.findOneBy({
inbox, inbox,
}); });
@ -69,12 +69,12 @@ export async function removeRelay(inbox: string) {
await Relays.delete(relay.id); await Relays.delete(relay.id);
} }
export async function listRelay() { export async function listRelay(): Promise<Relay[]> {
const relays = await Relays.find(); const relays = await Relays.find();
return relays; return relays;
} }
export async function relayAccepted(id: string) { export async function relayAccepted(id: string): Promise<string> {
const result = await Relays.update(id, { const result = await Relays.update(id, {
status: 'accepted', status: 'accepted',
}); });
@ -82,7 +82,7 @@ export async function relayAccepted(id: string) {
return JSON.stringify(result); return JSON.stringify(result);
} }
export async function relayRejected(id: string) { export async function relayRejected(id: string): Promise<string> {
const result = await Relays.update(id, { const result = await Relays.update(id, {
status: 'rejected', status: 'rejected',
}); });
@ -90,11 +90,11 @@ export async function relayRejected(id: string) {
return JSON.stringify(result); return JSON.stringify(result);
} }
export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any) { export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise<void> {
if (activity == null) return; if (activity == null) return;
const relays = await relaysCache.fetch(null); const relays = await relaysCache.fetch(null);
if (relays.length === 0) return; if (relays == null || relays.length === 0) return;
// TODO // TODO
//const copy = structuredClone(activity); //const copy = structuredClone(activity);

View file

@ -8,7 +8,7 @@ import { User } from '@/models/entities/user.js';
import { Users, Followings } from '@/models/index.js'; import { Users, Followings } from '@/models/index.js';
import { publishInternalEvent } from '@/services/stream.js'; import { publishInternalEvent } from '@/services/stream.js';
export async function doPostUnsuspend(user: User) { export async function doPostUnsuspend(user: User): Promise<void> {
publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false }); publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
if (Users.isLocalUser(user)) { if (Users.isLocalUser(user)) {

View file

@ -16,7 +16,7 @@ export async function updateUsertags(user: User, tags: string[]): Promise<void>
await updateHashtag(user, tag, true, true); await updateHashtag(user, tag, true, true);
} }
for (const tag of (user.tags || []).filter(x => !tags.includes(x))) { for (const tag of user.tags.filter(x => !tags.includes(x))) {
await updateHashtag(user, tag, true, false); await updateHashtag(user, tag, true, false);
} }
} }

View file

@ -1,3 +1,4 @@
import { IsNull } from 'typeorm';
import { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/entities/user.js'; import { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js'; import { Users } from '@/models/index.js';
import { Cache } from '@/misc/cache.js'; import { Cache } from '@/misc/cache.js';
@ -5,15 +6,15 @@ import { subscriber } from '@/db/redis.js';
export const userByIdCache = new Cache<CacheableUser>( export const userByIdCache = new Cache<CacheableUser>(
Infinity, Infinity,
(id) => Users.findOneBy({ id }).then(x => x ?? undefined), async (id) => id ? (await Users.findOneBy({ id }) ?? undefined) : undefined,
); );
export const localUserByNativeTokenCache = new Cache<CacheableLocalUser>( export const localUserByNativeTokenCache = new Cache<CacheableLocalUser>(
Infinity, Infinity,
(token) => Users.findOneBy({ token }).then(x => x ?? undefined), async (token) => token ? (await Users.findOneBy({ token, host: IsNull() }) as ILocalUser | null ?? undefined) : undefined,
); );
export const uriPersonCache = new Cache<CacheableUser>( export const uriPersonCache = new Cache<CacheableUser>(
Infinity, Infinity,
(uri) => Users.findOneBy({ uri }).then(x => x ?? undefined), async (uri) => uri ? (await Users.findOneBy({ uri }) ?? undefined) : undefined,
); );
subscriber.on('message', async (_, data) => { subscriber.on('message', async (_, data) => {