refactor (backend): change !== null to != null

This commit is contained in:
sup39 2024-02-07 16:35:11 +09:00 committed by naskya
parent 18aeeaabd2
commit 9c6ac248ff
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
14 changed files with 22 additions and 22 deletions

View file

@ -46,7 +46,7 @@ export class Cache<T> {
for (const [i, key] of keys.entries()) { for (const [i, key] of keys.entries()) {
const val = values[i]; const val = values[i];
if (val !== null) { if (val != null) {
map.set(key, decode(val) as T); map.set(key, decode(val) as T);
} }
} }

View file

@ -196,7 +196,7 @@ router.get("/notes/:note", async (ctx, next) => {
} }
// redirect if remote // redirect if remote
if (note.userHost !== null) { if (note.userHost != null) {
if (note.uri == null || isSelfHost(note.userHost)) { if (note.uri == null || isSelfHost(note.userHost)) {
ctx.status = 500; ctx.status = 500;
return; return;

View file

@ -82,7 +82,7 @@ export default define(
async (ps, user, _, file, cleanup, ip, headers) => { async (ps, user, _, file, cleanup, ip, headers) => {
// Get 'name' parameter // Get 'name' parameter
let name = ps.name || file.originalname; let name = ps.name || file.originalname;
if (name !== undefined && name !== null) { if (name != null) {
name = name.trim(); name = name.trim();
if (name.length === 0) { if (name.length === 0) {
name = null; name = null;

View file

@ -56,7 +56,7 @@ export default define(meta, paramDef, async (ps, user) => {
id: genId(), id: genId(),
createdAt: new Date(), createdAt: new Date(),
name: ps.name, name: ps.name,
parentId: parent !== null ? parent.id : null, parentId: parent != null ? parent.id : null,
userId: user.id, userId: user.id,
}).then((x) => DriveFolders.findOneByOrFail(x.identifiers[0])); }).then((x) => DriveFolders.findOneByOrFail(x.identifiers[0]));

View file

@ -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)) { if (await checkCircle(parent.parentId)) {
throw new ApiError(meta.errors.recursiveNesting); throw new ApiError(meta.errors.recursiveNesting);
} }

View file

@ -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 // 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 }); const u = await Users.findOneBy({ id: note.reply.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
} }
// Post is a renote and remote user is the contributor of the original post // 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 }); const u = await Users.findOneBy({ id: note.renote.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
} }

View file

@ -31,7 +31,7 @@ export default class extends Channel {
} }
private async onNote(note: Packed<"Note">) { 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.visibility !== "public") return;
if (note.channelId != null && !this.followingChannels.has(note.channelId)) if (note.channelId != null && !this.followingChannels.has(note.channelId))
return; return;

View file

@ -46,14 +46,14 @@ function urlPathJoin(
url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname, url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname,
); );
url.pathname = pathParts url.pathname = pathParts
.filter((x) => x !== null && x.toString().length > 0) .filter((x) => x != null && x.toString().length > 0)
.join("/"); .join("/");
} }
return url.toString(); return url.toString();
} }
const baseParts = baseOrParts.concat(pathParts ?? []); const baseParts = baseOrParts.concat(pathParts ?? []);
return baseParts return baseParts
.filter((x) => x !== null && x.toString().length > 0) .filter((x) => x != null && x.toString().length > 0)
.join("/"); .join("/");
} }
@ -572,7 +572,7 @@ export async function addFile({
file.createdAt = new Date(); file.createdAt = new Date();
file.userId = user ? user.id : null; file.userId = user ? user.id : null;
file.userHost = user ? user.host : 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.comment = comment;
file.properties = properties; file.properties = properties;
file.blurhash = info.blurhash || null; file.blurhash = info.blurhash || null;
@ -582,12 +582,12 @@ export async function addFile({
file.isSensitive = user file.isSensitive = user
? Users.isLocalUser(user) && profile?.alwaysMarkNsfw ? Users.isLocalUser(user) && profile?.alwaysMarkNsfw
? true ? true
: sensitive !== null && sensitive !== undefined : sensitive != null
? sensitive ? sensitive
: false : false
: false; : false;
if (url !== null) { if (url != null) {
file.src = url; file.src = url;
if (isLink) { if (isLink) {
@ -599,7 +599,7 @@ export async function addFile({
} }
} }
if (uri !== null) { if (uri != null) {
file.uri = uri; file.uri = uri;
} }

View file

@ -64,7 +64,7 @@ export async function deleteFileSync(file: DriveFile, isExpired = false) {
async function postProcess(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, { DriveFiles.update(file.id, {
isLink: true, isLink: true,
url: file.uri, url: file.uri,

View file

@ -50,7 +50,7 @@ export async function uploadFromUrl({
// If the comment is same as the name, skip comment // If the comment is same as the name, skip comment
// (image.name is passed in when receiving attachment) // (image.name is passed in when receiving attachment)
if (comment !== null && name === comment) { if (comment != null && name === comment) {
comment = null; comment = null;
} }

View file

@ -115,7 +115,7 @@ export default class Logger {
console.log(important ? chalk.bold(log) : log); console.log(important ? chalk.bold(log) : log);
if (level === "error" && data !== null) { if (level === "error" && data != null) {
console.log(data); console.log(data);
} }

View file

@ -486,7 +486,7 @@ export default async (
const lock = new Mutex(redisClient, "publishedNote"); const lock = new Mutex(redisClient, "publishedNote");
await lock.acquire(); await lock.acquire();
try { try {
const published = (await redisClient.get(publishKey)) !== null; const published = (await redisClient.get(publishKey)) != null;
if (!published) { if (!published) {
await redisClient.set(publishKey, "done", "EX", 30); await redisClient.set(publishKey, "done", "EX", 30);
if (noteToPublish.renoteId) { 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 }); const u = await Users.findOneBy({ id: data.reply.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
} }
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送 // 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
if (data.renote && data.renote.userHost !== null) { if (data.renote?.userHost != null) {
const u = await Users.findOneBy({ id: data.renote.userId }); const u = await Users.findOneBy({ id: data.renote.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
} }

View file

@ -148,7 +148,7 @@ export default async (
) { ) {
const content = renderActivity(await renderLike(record, note)); const content = renderActivity(await renderLike(record, note));
const dm = new DeliverManager(user, content); const dm = new DeliverManager(user, content);
if (note.userHost !== null) { if (note.userHost != null) {
const reactee = await Users.findOneBy({ id: note.userId }); const reactee = await Users.findOneBy({ id: note.userId });
dm.addDirectRecipe(reactee as IRemoteUser); dm.addDirectRecipe(reactee as IRemoteUser);
} }

View file

@ -59,7 +59,7 @@ export default async (
renderUndo(await renderLike(reaction, note), user), renderUndo(await renderLike(reaction, note), user),
); );
const dm = new DeliverManager(user, content); const dm = new DeliverManager(user, content);
if (note.userHost !== null) { if (note.userHost != null) {
const reactee = await Users.findOneBy({ id: note.userId }); const reactee = await Users.findOneBy({ id: note.userId });
dm.addDirectRecipe(reactee as IRemoteUser); dm.addDirectRecipe(reactee as IRemoteUser);
} }