fix: resolve biome lint errors

- Use optional chaining for nullable checks
- Replace template literals with string literals for plain SQL
- Add node: protocol to fs/promises import in setup.js
This commit is contained in:
Dimas R. Wisnu committed 2026-08-07 17:01:20 +07:00
1 parent 4a0f212289
commit 35ad8227d7
3 files changed
+11 -11

No files matched your search

+9 -9
View File
@@ -28,17 +28,17 @@ const getProxyHostsUsingAccessListInLocations = async (accessListId) => {
if (isMysql()) { if (isMysql()) {
const searchObj = JSON.stringify([{ access_list_id: accessListId }]); const searchObj = JSON.stringify([{ access_list_id: accessListId }]);
result = await db().raw( result = await db().raw(
`SELECT id FROM proxy_host WHERE is_deleted = 0 AND JSON_CONTAINS(locations, ?, ?)`, "SELECT id FROM proxy_host WHERE is_deleted = 0 AND JSON_CONTAINS(locations, ?, ?)",
[searchObj, "$"], [searchObj, "$"],
); );
} else if (isPostgres()) { } else if (isPostgres()) {
result = await db().raw( result = await db().raw(
`SELECT id FROM proxy_host WHERE is_deleted = 0 AND locations::jsonb @> ?::jsonb`, "SELECT id FROM proxy_host WHERE is_deleted = 0 AND locations::jsonb @> ?::jsonb",
[JSON.stringify([{ access_list_id: accessListId }])], [JSON.stringify([{ access_list_id: accessListId }])],
); );
} else { } else {
result = await db().raw( result = await db().raw(
`SELECT id FROM proxy_host WHERE is_deleted = 0 AND locations LIKE ?`, "SELECT id FROM proxy_host WHERE is_deleted = 0 AND locations LIKE ?",
[`%"access_list_id":${accessListId}%`], [`%"access_list_id":${accessListId}%`],
); );
} }
@@ -222,10 +222,10 @@ const internalAccessList = {
// Also regenerate configs for proxy hosts that reference this access list in their locations // Also regenerate configs for proxy hosts that reference this access list in their locations
const locationHostRows = await getProxyHostsUsingAccessListInLocations(data.id); const locationHostRows = await getProxyHostsUsingAccessListInLocations(data.id);
if (locationHostRows && locationHostRows.length) { if (locationHostRows?.length) {
const locationHostIds = locationHostRows.map((r) => r.id).filter((id) => { const locationHostIds = locationHostRows.map((r) => r.id).filter((id) => {
// Exclude hosts already regenerated above // Exclude hosts already regenerated above
return !freshRow.proxy_hosts || !freshRow.proxy_hosts.find((h) => h.id === id); return !freshRow.proxy_hosts?.find((h) => h.id === id);
}); });
if (locationHostIds.length) { if (locationHostIds.length) {
const locationHosts = await proxyHostModel.query() const locationHosts = await proxyHostModel.query()
@@ -235,7 +235,7 @@ const internalAccessList = {
.withGraphFetched("[owner, certificate, access_list.[clients,items]]"); .withGraphFetched("[owner, certificate, access_list.[clients,items]]");
for (const host of locationHosts) { for (const host of locationHosts) {
// Fetch access lists for locations // Fetch access lists for locations
if (host.locations && host.locations.length) { if (host.locations?.length) {
for (let i = 0; i < host.locations.length; i++) { for (let i = 0; i < host.locations.length; i++) {
const loc = host.locations[i]; const loc = host.locations[i];
if (loc.access_list_id && loc.access_list_id > 0) { if (loc.access_list_id && loc.access_list_id > 0) {
@@ -363,15 +363,15 @@ const internalAccessList = {
// Also handle proxy hosts that reference this access list in their locations JSON // Also handle proxy hosts that reference this access list in their locations JSON
const locationHostRows = await getProxyHostsUsingAccessListInLocations(row.id); const locationHostRows = await getProxyHostsUsingAccessListInLocations(row.id);
if (locationHostRows && locationHostRows.length) { if (locationHostRows?.length) {
const locationHostIds = locationHostRows.map((r) => r.id).filter((id) => { const locationHostIds = locationHostRows.map((r) => r.id).filter((id) => {
return !row.proxy_hosts || !row.proxy_hosts.find((h) => h.id === id); return !row.proxy_hosts?.find((h) => h.id === id);
}); });
if (locationHostIds.length) { if (locationHostIds.length) {
// Clear the access_list_id in locations JSON for these hosts // Clear the access_list_id in locations JSON for these hosts
for (const hostId of locationHostIds) { for (const hostId of locationHostIds) {
const host = await proxyHostModel.query().where("id", hostId).first(); const host = await proxyHostModel.query().where("id", hostId).first();
if (host && host.locations) { if (host?.locations) {
const updatedLocations = host.locations.map((loc) => { const updatedLocations = host.locations.map((loc) => {
if (loc.access_list_id === row.id) { if (loc.access_list_id === row.id) {
return { ...loc, access_list_id: 0 }; return { ...loc, access_list_id: 0 };
+1 -1
View File
@@ -21,7 +21,7 @@ const omissions = () => {
* @returns {Promise} * @returns {Promise}
*/ */
const fetchLocationAccessLists = async (host) => { const fetchLocationAccessLists = async (host) => {
if (!host.locations || !host.locations.length) { if (!host.locations?.length) {
return; return;
} }
for (let i = 0; i < host.locations.length; i++) { for (let i = 0; i < host.locations.length; i++) {
+1 -1
View File
@@ -6,7 +6,7 @@ import certificateModel from "./models/certificate.js";
import settingModel from "./models/setting.js"; import settingModel from "./models/setting.js";
import userModel from "./models/user.js"; import userModel from "./models/user.js";
import userPermissionModel from "./models/user_permission.js"; import userPermissionModel from "./models/user_permission.js";
import fs from "fs/promises"; import fs from "node:fs/promises";
export const isSetup = async () => { export const isSetup = async () => {
const row = await userModel.query().select("id").where("is_deleted", 0).first(); const row = await userModel.query().select("id").where("is_deleted", 0).first();