dbに保存するようにした

Signed-off-by: mattyatea <mattyacocacora0@gmail.com>
This commit is contained in:
mattyatea 2023-11-08 15:33:46 +09:00
parent e133a6b6a4
commit 387faf55cf
No known key found for this signature in database
GPG key ID: 068E54E2C33BEF9A
8 changed files with 160 additions and 42 deletions

View file

@ -7,6 +7,8 @@ import { Inject, Injectable } from '@nestjs/common';
import type Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import { NoteCreateService } from '@/core/NoteCreateService.js';
import type { NoteScheduleRepository, UsersRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { ScheduleNotePostJobData } from '../types.js';
@ -16,6 +18,12 @@ export class ScheduleNotePostProcessorService {
private logger: Logger;
constructor(
@Inject(DI.noteScheduleRepository)
private noteScheduleRepository: NoteScheduleRepository,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
private noteCreateService: NoteCreateService,
private queueLoggerService: QueueLoggerService,
) {
@ -24,7 +32,15 @@ export class ScheduleNotePostProcessorService {
@bindThis
public async process(job: Bull.Job<ScheduleNotePostJobData>): Promise<void> {
job.data.note.createdAt = new Date();
await this.noteCreateService.create(job.data.user, job.data.note);
this.noteScheduleRepository.findOneBy({ id: job.data.scheduleNoteId }).then(async (data) => {
if (!data) {
this.logger.warn(`Schedule note ${job.data.scheduleNoteId} not found`);
} else {
data.note.createdAt = new Date();
const me = await this.usersRepository.findOneByOrFail({ id: data.userId });
await this.noteCreateService.create(me, data.note);
await this.noteScheduleRepository.remove(data);
}
});
}
}

View file

@ -109,28 +109,7 @@ export type EndedPollNotificationJobData = {
};
export type ScheduleNotePostJobData = {
note: {
name?: string | null;
text?: string | null;
reply?: MiNote | null;
renote?: MiNote | null;
files?: MiDriveFile[] | null;
poll?: IPoll | null;
schedule?: MiNoteSchedule | null;
localOnly?: boolean | null;
reactionAcceptance?: MiNote['reactionAcceptance'];
cw?: string | null;
visibility?: string;
visibleUsers?: MinimumUser[] | null;
channel?: MiChannel | null;
apMentions?: MinimumUser[] | null;
apHashtags?: string[] | null;
apEmojis?: string[] | null;
uri?: string | null;
url?: string | null;
app?: MiApp | null;
};
user: MiUser & {host: null, uri: null};
scheduleNoteId: MiNote['id'];
}
type MinimumUser = {