Fix author duplication - add optional chaining

This commit is contained in:
Zach Aw 2026-03-03 21:55:06 +08:00
parent 6d3404272c
commit 9cf02e4981
3 changed files with 3 additions and 3 deletions

View file

@ -61,7 +61,7 @@ describe('AuthorCard', () => {
const height = $el.height() const height = $el.height()
const defaultHeight = 192 const defaultHeight = 192
const defaultWidth = defaultHeight * 0.8 const defaultWidth = defaultHeight * 0.8
expect(width).to.be.closeTo(defaultWidth, 0.01) expect(width).to?.be?.closeTo(defaultWidth, 0.01)
expect(height).to.be.closeTo(defaultHeight, 0.01) expect(height).to.be.closeTo(defaultHeight, 0.01)
}) })
}) })

View file

@ -31,7 +31,7 @@ class SocketAuthority {
Object.values(this.clients) Object.values(this.clients)
.filter((c) => c.user) .filter((c) => c.user)
.forEach((client) => { .forEach((client) => {
if (onlineUsersMap[client.user.id]) { if (onlineUsersMap[client?.user?.id]) {
onlineUsersMap[client.user.id].connections++ onlineUsersMap[client.user.id].connections++
} else { } else {
onlineUsersMap[client.user.id] = { onlineUsersMap[client.user.id] = {

View file

@ -38,7 +38,7 @@ class AuthorController {
* @param {Response} res * @param {Response} res
*/ */
async findOne(req, res) { async findOne(req, res) {
const include = (req.query.include || '').split(',') const include = (req?.query?.include || '').split(',')
const authorJson = req.author.toOldJSON() const authorJson = req.author.toOldJSON()