From 2cec30fd45d4e7046918139c09e3b23a4937639b Mon Sep 17 00:00:00 2001 From: sup39 Date: Wed, 7 Feb 2024 16:35:11 +0900 Subject: [PATCH] refactor (backend): change `!== null` to `!= null` --- packages/backend/src/misc/cache.ts | 2 +- packages/backend/src/server/activitypub.ts | 2 +- .../src/server/api/endpoints/drive/files/create.ts | 2 +- .../src/server/api/endpoints/drive/folders/create.ts | 2 +- .../src/server/api/endpoints/drive/folders/update.ts | 2 +- .../backend/src/server/api/endpoints/notes/edit.ts | 4 ++-- .../src/server/api/stream/channels/local-timeline.ts | 2 +- packages/backend/src/services/drive/add-file.ts | 12 ++++++------ packages/backend/src/services/drive/delete-file.ts | 2 +- .../backend/src/services/drive/upload-from-url.ts | 2 +- packages/backend/src/services/logger.ts | 2 +- packages/backend/src/services/note/create.ts | 6 +++--- .../backend/src/services/note/reaction/create.ts | 2 +- .../backend/src/services/note/reaction/delete.ts | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index 913258f0..30a50e57 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -46,7 +46,7 @@ export class Cache { for (const [i, key] of keys.entries()) { const val = values[i]; - if (val !== null) { + if (val != null) { map.set(key, decode(val) as T); } } diff --git a/packages/backend/src/server/activitypub.ts b/packages/backend/src/server/activitypub.ts index 4115b625..68befcdd 100644 --- a/packages/backend/src/server/activitypub.ts +++ b/packages/backend/src/server/activitypub.ts @@ -196,7 +196,7 @@ router.get("/notes/:note", async (ctx, next) => { } // redirect if remote - if (note.userHost !== null) { + if (note.userHost != null) { if (note.uri == null || isSelfHost(note.userHost)) { ctx.status = 500; return; diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts index a59e8dca..835a5cb5 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -82,7 +82,7 @@ export default define( async (ps, user, _, file, cleanup, ip, headers) => { // Get 'name' parameter let name = ps.name || file.originalname; - if (name !== undefined && name !== null) { + if (name != null) { name = name.trim(); if (name.length === 0) { name = null; diff --git a/packages/backend/src/server/api/endpoints/drive/folders/create.ts b/packages/backend/src/server/api/endpoints/drive/folders/create.ts index 554e61ec..55814419 100644 --- a/packages/backend/src/server/api/endpoints/drive/folders/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/folders/create.ts @@ -56,7 +56,7 @@ export default define(meta, paramDef, async (ps, user) => { id: genId(), createdAt: new Date(), name: ps.name, - parentId: parent !== null ? parent.id : null, + parentId: parent != null ? parent.id : null, userId: user.id, }).then((x) => DriveFolders.findOneByOrFail(x.identifiers[0])); diff --git a/packages/backend/src/server/api/endpoints/drive/folders/update.ts b/packages/backend/src/server/api/endpoints/drive/folders/update.ts index 137499fa..f869ee93 100644 --- a/packages/backend/src/server/api/endpoints/drive/folders/update.ts +++ b/packages/backend/src/server/api/endpoints/drive/folders/update.ts @@ -93,7 +93,7 @@ export default define(meta, paramDef, async (ps, user) => { } } - if (parent.parentId !== null) { + if (parent.parentId != null) { if (await checkCircle(parent.parentId)) { throw new ApiError(meta.errors.recursiveNesting); } diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index 0c277ec9..6d245d7d 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -647,13 +647,13 @@ export default define(meta, paramDef, async (ps, user) => { } // Post is a reply and remote user is the contributor of the original post - if (note.reply && note.reply.userHost !== null) { + if (note.reply?.userHost != null) { const u = await Users.findOneBy({ id: note.reply.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } // Post is a renote and remote user is the contributor of the original post - if (note.renote && note.renote.userHost !== null) { + if (note.renote?.userHost != null) { const u = await Users.findOneBy({ id: note.renote.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 51205e9d..723e009a 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -31,7 +31,7 @@ export default class extends Channel { } private async onNote(note: Packed<"Note">) { - if (note.user.host !== null) return; + if (note.user.host != null) return; if (note.visibility !== "public") return; if (note.channelId != null && !this.followingChannels.has(note.channelId)) return; diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index 8f25c095..0c68a46d 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -46,14 +46,14 @@ function urlPathJoin( url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname, ); url.pathname = pathParts - .filter((x) => x !== null && x.toString().length > 0) + .filter((x) => x != null && x.toString().length > 0) .join("/"); } return url.toString(); } const baseParts = baseOrParts.concat(pathParts ?? []); return baseParts - .filter((x) => x !== null && x.toString().length > 0) + .filter((x) => x != null && x.toString().length > 0) .join("/"); } @@ -572,7 +572,7 @@ export async function addFile({ file.createdAt = new Date(); file.userId = user ? user.id : null; file.userHost = user ? user.host : null; - file.folderId = folder !== null ? folder.id : null; + file.folderId = folder != null ? folder.id : null; file.comment = comment; file.properties = properties; file.blurhash = info.blurhash || null; @@ -582,12 +582,12 @@ export async function addFile({ file.isSensitive = user ? Users.isLocalUser(user) && profile?.alwaysMarkNsfw ? true - : sensitive !== null && sensitive !== undefined + : sensitive != null ? sensitive : false : false; - if (url !== null) { + if (url != null) { file.src = url; if (isLink) { @@ -599,7 +599,7 @@ export async function addFile({ } } - if (uri !== null) { + if (uri != null) { file.uri = uri; } diff --git a/packages/backend/src/services/drive/delete-file.ts b/packages/backend/src/services/drive/delete-file.ts index 3b597bae..7d855af2 100644 --- a/packages/backend/src/services/drive/delete-file.ts +++ b/packages/backend/src/services/drive/delete-file.ts @@ -64,7 +64,7 @@ export async function deleteFileSync(file: DriveFile, isExpired = false) { async function postProcess(file: DriveFile, isExpired = false) { // リモートファイル期限切れ削除後は直リンクにする - if (isExpired && file.userHost !== null && file.uri != null) { + if (isExpired && file.userHost != null && file.uri != null) { DriveFiles.update(file.id, { isLink: true, url: file.uri, diff --git a/packages/backend/src/services/drive/upload-from-url.ts b/packages/backend/src/services/drive/upload-from-url.ts index 0638bcab..adbeee5a 100644 --- a/packages/backend/src/services/drive/upload-from-url.ts +++ b/packages/backend/src/services/drive/upload-from-url.ts @@ -50,7 +50,7 @@ export async function uploadFromUrl({ // If the comment is same as the name, skip comment // (image.name is passed in when receiving attachment) - if (comment !== null && name === comment) { + if (comment != null && name === comment) { comment = null; } diff --git a/packages/backend/src/services/logger.ts b/packages/backend/src/services/logger.ts index 63b7176a..3eb4829d 100644 --- a/packages/backend/src/services/logger.ts +++ b/packages/backend/src/services/logger.ts @@ -115,7 +115,7 @@ export default class Logger { console.log(important ? chalk.bold(log) : log); - if (level === "error" && data !== null) { + if (level === "error" && data != null) { console.log(data); } diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 814b869e..9beb4e6c 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -486,7 +486,7 @@ export default async ( const lock = new Mutex(redisClient, "publishedNote"); await lock.acquire(); try { - const published = (await redisClient.get(publishKey)) !== null; + const published = (await redisClient.get(publishKey)) != null; if (!published) { await redisClient.set(publishKey, "done", "EX", 30); if (noteToPublish.renoteId) { @@ -613,13 +613,13 @@ export default async ( } // 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送 - if (data.reply && data.reply.userHost !== null) { + if (data.reply?.userHost != null) { const u = await Users.findOneBy({ id: data.reply.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } // 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送 - if (data.renote && data.renote.userHost !== null) { + if (data.renote?.userHost != null) { const u = await Users.findOneBy({ id: data.renote.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 1ea4b45e..64d8d985 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -148,7 +148,7 @@ export default async ( ) { const content = renderActivity(await renderLike(record, note)); const dm = new DeliverManager(user, content); - if (note.userHost !== null) { + if (note.userHost != null) { const reactee = await Users.findOneBy({ id: note.userId }); dm.addDirectRecipe(reactee as IRemoteUser); } diff --git a/packages/backend/src/services/note/reaction/delete.ts b/packages/backend/src/services/note/reaction/delete.ts index 15c6d1cf..49879a0c 100644 --- a/packages/backend/src/services/note/reaction/delete.ts +++ b/packages/backend/src/services/note/reaction/delete.ts @@ -59,7 +59,7 @@ export default async ( renderUndo(await renderLike(reaction, note), user), ); const dm = new DeliverManager(user, content); - if (note.userHost !== null) { + if (note.userHost != null) { const reactee = await Users.findOneBy({ id: note.userId }); dm.addDirectRecipe(reactee as IRemoteUser); }