Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CGsama committed Jan 26, 2025
1 parent fb8312f commit e5d178d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/backend/src/server/web/FeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import { parse as mfmParse } from 'mfm-js';
import { MiNote } from '@/models/Note.js';
import { isQuote, isRenote } from '@/misc/is-renote.js';
import { getNoteSummary } from '@/misc/get-note-summary.js';
import Logger from '@/logger.js';
import { LoggerService } from '@/core/LoggerService.js';

@Injectable()
export class FeedService {
private readonly logger: Logger;

constructor(
@Inject(DI.config)
private config: Config,
Expand All @@ -39,7 +43,10 @@ export class FeedService {
private driveFileEntityService: DriveFileEntityService,
private idService: IdService,
private mfmService: MfmService,

loggerService: LoggerService,
) {
this.logger = loggerService.getLogger('feed');
}

@bindThis
Expand All @@ -55,7 +62,6 @@ export class FeedService {
const notes = await this.notesRepository.find({
where: {
userId: user.id,
renoteId: IsNull(),
visibility: In(['public', 'home']),
},
order: { id: -1 },
Expand Down Expand Up @@ -120,10 +126,11 @@ export class FeedService {
}

private escapeCDATA(str: string) {
return str.replaceAll("]]>", "]]]]><![CDATA[>").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
return str?.replaceAll("]]>", "]]]]><![CDATA[>").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
}

private async noteToString(note: MiNote, isTheNote = false) {
this.logger.info(`note2str ${note.userId} ${note.text}`);
const author = isTheNote
? null
: await this.userProfilesRepository.findOneByOrFail({ userId: note.userId });
Expand All @@ -134,7 +141,7 @@ export class FeedService {
note.renoteId ? "renotes" : note.replyId ? "replies" : "says"
}: <br>`
: "";
const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({
const files = note.fileIds?.length ? await this.driveFilesRepository.findBy({
id: In(note.fileIds),
}) : [];
let fileEle = "";
Expand Down Expand Up @@ -172,19 +179,17 @@ export class FeedService {
private async findById(id : String) {

Check failure on line 179 in packages/backend/src/server/web/FeedService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Don't use `String` as a type. Use string instead
let text = "";
let next = null;
const findings = await this.notesRepository.find({
where: {
id: id,
renoteId: IsNull(),
visibility: In(['public', 'home']),
},
order: { id: -1 },
take: 1,
const findings = await this.notesRepository.findOneBy({
id: id,
visibility: In(['public', 'home']),
});

if (findings) {
text += `<hr>`;
text += await this.noteToString(findings);
next = findings.renoteId ? findings.renoteId : findings.replyId;
} else {
this.logger.info(`Note ${id} not in scope`);
}
return { text, next };
}
Expand Down

0 comments on commit e5d178d

Please sign in to comment.