strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
This commit is contained in:
parent
4ee40c3345
commit
987168b863
214 changed files with 939 additions and 785 deletions
|
@ -12,7 +12,7 @@ import { queueLogger } from './logger';
|
|||
import { DriveFile } from '../models/entities/drive-file';
|
||||
|
||||
function initializeQueue(name: string) {
|
||||
return new Queue(name, config.redis != null ? {
|
||||
return new Queue(name, {
|
||||
redis: {
|
||||
port: config.redis.port,
|
||||
host: config.redis.host,
|
||||
|
@ -20,7 +20,7 @@ function initializeQueue(name: string) {
|
|||
db: config.redis.db || 0,
|
||||
},
|
||||
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : 'queue'
|
||||
} : null);
|
||||
});
|
||||
}
|
||||
|
||||
export const deliverQueue = initializeQueue('deliver');
|
||||
|
|
|
@ -10,9 +10,11 @@ const logger = queueLogger.createSubLogger('delete-drive-files');
|
|||
export async function deleteDriveFiles(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Deleting drive files of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
let deletedCount = 0;
|
||||
let ended = false;
|
||||
|
|
|
@ -14,9 +14,11 @@ const logger = queueLogger.createSubLogger('export-blocking');
|
|||
export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Exporting blocking of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create temp file
|
||||
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
||||
|
@ -56,6 +58,10 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
|
|||
|
||||
for (const block of blockings) {
|
||||
const u = await Users.findOne({ id: block.blockeeId });
|
||||
if (u == null) {
|
||||
exportedCount++; continue;
|
||||
}
|
||||
|
||||
const content = getFullApAccount(u.username, u.host);
|
||||
await new Promise((res, rej) => {
|
||||
stream.write(content + '\n', err => {
|
||||
|
|
|
@ -14,9 +14,11 @@ const logger = queueLogger.createSubLogger('export-following');
|
|||
export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Exporting following of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create temp file
|
||||
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
||||
|
@ -56,6 +58,10 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
|
|||
|
||||
for (const following of followings) {
|
||||
const u = await Users.findOne({ id: following.followeeId });
|
||||
if (u == null) {
|
||||
exportedCount++; continue;
|
||||
}
|
||||
|
||||
const content = getFullApAccount(u.username, u.host);
|
||||
await new Promise((res, rej) => {
|
||||
stream.write(content + '\n', err => {
|
||||
|
|
|
@ -14,9 +14,11 @@ const logger = queueLogger.createSubLogger('export-mute');
|
|||
export async function exportMute(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Exporting mute of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create temp file
|
||||
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
||||
|
@ -56,6 +58,10 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> {
|
|||
|
||||
for (const mute of mutes) {
|
||||
const u = await Users.findOne({ id: mute.muteeId });
|
||||
if (u == null) {
|
||||
exportedCount++; continue;
|
||||
}
|
||||
|
||||
const content = getFullApAccount(u.username, u.host);
|
||||
await new Promise((res, rej) => {
|
||||
stream.write(content + '\n', err => {
|
||||
|
|
|
@ -9,15 +9,18 @@ import { Users, Notes, Polls } from '../../../models';
|
|||
import { MoreThan } from 'typeorm';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { Poll } from '../../../models/entities/poll';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
const logger = queueLogger.createSubLogger('export-notes');
|
||||
|
||||
export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Exporting notes of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create temp file
|
||||
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
||||
|
@ -67,9 +70,9 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
|||
cursor = notes[notes.length - 1].id;
|
||||
|
||||
for (const note of notes) {
|
||||
let poll: Poll;
|
||||
let poll: Poll | undefined;
|
||||
if (note.hasPoll) {
|
||||
poll = await Polls.findOne({ noteId: note.id });
|
||||
poll = await Polls.findOne({ noteId: note.id }).then(ensure);
|
||||
}
|
||||
const content = JSON.stringify(serialize(note, poll));
|
||||
await new Promise((res, rej) => {
|
||||
|
@ -114,7 +117,7 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
|||
done();
|
||||
}
|
||||
|
||||
function serialize(note: Note, poll: Poll): any {
|
||||
function serialize(note: Note, poll: Poll | null = null): any {
|
||||
return {
|
||||
id: note.id,
|
||||
text: note.text,
|
||||
|
|
|
@ -14,9 +14,11 @@ const logger = queueLogger.createSubLogger('export-user-lists');
|
|||
export async function exportUserLists(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Exporting user lists of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const lists = await UserLists.find({
|
||||
userId: user.id
|
||||
|
|
|
@ -13,13 +13,19 @@ const logger = queueLogger.createSubLogger('import-following');
|
|||
export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Importing following of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const file = await DriveFiles.findOne({
|
||||
id: job.data.fileId
|
||||
});
|
||||
if (file == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const csv = await downloadTextFile(file.url);
|
||||
|
||||
|
@ -31,11 +37,11 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
|
|||
try {
|
||||
const { username, host } = parseAcct(line.trim());
|
||||
|
||||
let target = isSelfHost(host) ? await Users.findOne({
|
||||
let target = isSelfHost(host!) ? await Users.findOne({
|
||||
host: null,
|
||||
usernameLower: username.toLowerCase()
|
||||
}) : await Users.findOne({
|
||||
host: toPuny(host),
|
||||
host: toPuny(host!),
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
|
||||
|
|
|
@ -14,13 +14,19 @@ const logger = queueLogger.createSubLogger('import-user-lists');
|
|||
export async function importUserLists(job: Bull.Job, done: any): Promise<void> {
|
||||
logger.info(`Importing user lists of ${job.data.user.id} ...`);
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: job.data.user.id
|
||||
});
|
||||
const user = await Users.findOne(job.data.user.id);
|
||||
if (user == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const file = await DriveFiles.findOne({
|
||||
id: job.data.fileId
|
||||
});
|
||||
if (file == null) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const csv = await downloadTextFile(file.url);
|
||||
|
||||
|
@ -43,22 +49,20 @@ export async function importUserLists(job: Bull.Job, done: any): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
let target = isSelfHost(host) ? await Users.findOne({
|
||||
let target = isSelfHost(host!) ? await Users.findOne({
|
||||
host: null,
|
||||
usernameLower: username.toLowerCase()
|
||||
}) : await Users.findOne({
|
||||
host: toPuny(host),
|
||||
host: toPuny(host!),
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
|
||||
if (host == null && target == null) continue;
|
||||
|
||||
if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue;
|
||||
|
||||
if (target == null) {
|
||||
target = await resolveUser(username, host);
|
||||
}
|
||||
|
||||
if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue;
|
||||
|
||||
pushUserToUserList(target, list);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import { instanceChart } from '../../services/chart';
|
|||
|
||||
const logger = new Logger('deliver');
|
||||
|
||||
let latest: string = null;
|
||||
let latest: string | null = null;
|
||||
|
||||
export default async (job: Bull.Job) => {
|
||||
const { host } = new URL(job.data.to);
|
||||
|
|
|
@ -14,6 +14,7 @@ import { UserPublickey } from '../../models/entities/user-publickey';
|
|||
import fetchMeta from '../../misc/fetch-meta';
|
||||
import { toPuny } from '../../misc/convert-host';
|
||||
import { validActor } from '../../remote/activitypub/type';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
|
||||
const logger = new Logger('inbox');
|
||||
|
||||
|
@ -35,7 +36,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
|||
|
||||
if (keyIdLower.startsWith('acct:')) {
|
||||
const acct = parseAcct(keyIdLower.slice('acct:'.length));
|
||||
const host = toPuny(acct.host);
|
||||
const host = acct.host ? toPuny(acct.host) : null;
|
||||
const username = toPuny(acct.username);
|
||||
|
||||
if (host === null) {
|
||||
|
@ -64,9 +65,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
|||
host: host
|
||||
}) as IRemoteUser;
|
||||
|
||||
key = await UserPublickeys.findOne({
|
||||
userId: user.id
|
||||
});
|
||||
key = await UserPublickeys.findOne(user.id).then(ensure);
|
||||
} else {
|
||||
// アクティビティ内のホストの検証
|
||||
const host = toPuny(new URL(signature.keyId).hostname);
|
||||
|
@ -87,7 +86,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
|||
|
||||
key = await UserPublickeys.findOne({
|
||||
keyId: signature.keyId
|
||||
});
|
||||
}).then(ensure);
|
||||
|
||||
user = await Users.findOne(key.userId) as IRemoteUser;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue