eslint: add no-shadow

This commit is contained in:
Girish Ramakrishnan
2026-02-18 08:18:37 +01:00
parent 4d3e9dc49b
commit 4ed6fbbd74
40 changed files with 250 additions and 249 deletions

View File

@@ -413,7 +413,7 @@ function postProcess(result) {
delete result.servicesConfigJson;
const subdomains = JSON.parse(result.subdomains),
domains = JSON.parse(result.domains),
parsedDomains = JSON.parse(result.domains),
subdomainTypes = JSON.parse(result.subdomainTypes),
subdomainEnvironmentVariables = JSON.parse(result.subdomainEnvironmentVariables),
subdomainCertificateJsons = JSON.parse(result.subdomainCertificateJsons);
@@ -428,7 +428,7 @@ function postProcess(result) {
result.redirectDomains = [];
result.aliasDomains = [];
for (let i = 0; i < subdomainTypes.length; i++) {
const subdomain = subdomains[i], domain = domains[i], certificate = safe.JSON.parse(subdomainCertificateJsons[i]);
const subdomain = subdomains[i], domain = parsedDomains[i], certificate = safe.JSON.parse(subdomainCertificateJsons[i]);
if (subdomainTypes[i] === Location.TYPE_PRIMARY) {
result.subdomain = subdomain;
@@ -504,14 +504,14 @@ function accessLevel(app, user) {
return canAccess(app, user) ? ACCESS_LEVEL_USER : ACCESS_LEVEL_NONE;
}
function pickFields(app, accessLevel) {
function pickFields(app, level) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof accessLevel, 'string');
assert.strictEqual(typeof level, 'string');
if (accessLevel === ACCESS_LEVEL_NONE) return null; // cannot happen!
if (level === ACCESS_LEVEL_NONE) return null; // cannot happen!
let result;
if (accessLevel === ACCESS_LEVEL_USER) {
if (level === ACCESS_LEVEL_USER) {
result = _.pick(app, [
'id', 'appStoreId', 'versionsUrl', 'installationState', 'error', 'runState', 'health', 'taskId', 'accessRestriction',
'secondaryDomains', 'redirectDomains', 'aliasDomains', 'sso', 'subdomain', 'domain', 'fqdn', 'certificate',
@@ -632,10 +632,10 @@ async function add(id, appStoreId, versionsUrl, manifest, subdomain, domain, por
args: [ id, domain, subdomain, Location.TYPE_PRIMARY ]
});
Object.keys(portBindings).forEach(function (env) {
Object.keys(portBindings).forEach(function (portEnv) {
queries.push({
query: 'INSERT INTO appPortBindings (environmentVariable, hostPort, type, appId, count) VALUES (?, ?, ?, ?, ?)',
args: [ env, portBindings[env].hostPort, portBindings[env].type, id, portBindings[env].count ]
args: [ portEnv, portBindings[portEnv].hostPort, portBindings[portEnv].type, id, portBindings[portEnv].count ]
});
});
@@ -1531,7 +1531,7 @@ async function downloadFile(app, filePath) {
for (;;) {
if (this._buffer.length < 8) break; // header is 8 bytes
const type = this._buffer.readUInt8(0);
const streamType = this._buffer.readUInt8(0);
const len = this._buffer.readUInt32BE(4);
if (this._buffer.length < (8 + len)) break; // not enough
@@ -1540,7 +1540,7 @@ async function downloadFile(app, filePath) {
this._buffer = this._buffer.slice(8+len); // consumed
if (type === 1) this.push(payload);
if (streamType === 1) this.push(payload);
}
callback();
@@ -2444,12 +2444,12 @@ async function restore(app, backupId, auditSource) {
if (error) throw error;
// for empty or null backupId, use existing manifest to mimic a reinstall
const backup = backupId ? await backups.get(backupId) : { manifest: app.manifest };
if (!backup) throw new BoxError(BoxError.BAD_FIELD, 'No such backup');
const manifest = backup.manifest;
const restoreBackup = backupId ? await backups.get(backupId) : { manifest: app.manifest };
if (!restoreBackup) throw new BoxError(BoxError.BAD_FIELD, 'No such backup');
const manifest = restoreBackup.manifest;
if (!manifest) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Could not get restore manifest');
if (backup.encryptionVersion === 1) throw new BoxError(BoxError.BAD_FIELD, 'This encrypted backup was created with an older Cloudron version and has to be restored using the CLI tool');
if (restoreBackup.encryptionVersion === 1) throw new BoxError(BoxError.BAD_FIELD, 'This encrypted backup was created with an older Cloudron version and has to be restored using the CLI tool');
// re-validate because this new box version may not accept old configs
error = await checkManifest(manifest);
@@ -2468,7 +2468,7 @@ async function restore(app, backupId, auditSource) {
values.inboxName = values.inboxDomain = null;
}
const restoreConfig = { backupId: backup.id };
const restoreConfig = { backupId: restoreBackup.id };
const task = {
args: {
@@ -2482,7 +2482,7 @@ async function restore(app, backupId, auditSource) {
const taskId = await addTask(appId, ISTATE_PENDING_RESTORE, task, auditSource);
await eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app, backupId: backup.id, remotePath: backup.remotePath, fromManifest: app.manifest, toManifest: manifest, taskId });
await eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app, backupId: restoreBackup.id, remotePath: restoreBackup.remotePath, fromManifest: app.manifest, toManifest: manifest, taskId });
return { taskId };
}
@@ -2573,13 +2573,13 @@ async function clone(app, data, user, auditSource) {
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof domain, 'string');
const backup = await backups.get(backupId);
const cloneBackup = await backups.get(backupId);
if (!backup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (!backup.manifest) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Could not detect restore manifest');
if (backup.encryptionVersion === 1) throw new BoxError(BoxError.BAD_FIELD, 'This encrypted backup was created with an older Cloudron version and cannot be cloned');
if (!cloneBackup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (!cloneBackup.manifest) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Could not detect restore manifest');
if (cloneBackup.encryptionVersion === 1) throw new BoxError(BoxError.BAD_FIELD, 'This encrypted backup was created with an older Cloudron version and cannot be cloned');
const manifest = backup.manifest, appStoreId = app.appStoreId, versionsUrl = app.versionsUrl;
const manifest = cloneBackup.manifest, appStoreId = app.appStoreId, versionsUrl = app.versionsUrl;
let error = validateSecondaryDomains(data.secondaryDomains || {}, manifest);
if (error) throw error;
@@ -2606,7 +2606,7 @@ async function clone(app, data, user, auditSource) {
const newAppId = crypto.randomUUID();
// label, checklist intentionally omitted . icon is loaded in apptask from the backup
const dolly = _.pick(backup.appConfig || app, ['memoryLimit', 'cpuQuota', 'crontab', 'reverseProxyConfig', 'env', 'servicesConfig', 'tags', 'devices',
const dolly = _.pick(cloneBackup.appConfig || app, ['memoryLimit', 'cpuQuota', 'crontab', 'reverseProxyConfig', 'env', 'servicesConfig', 'tags', 'devices',
'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain', 'debugMode',
'enableTurn', 'enableRedis', 'mounts', 'enableBackup', 'enableAutomaticUpdate', 'accessRestriction', 'operators', 'sso',
'notes', 'checklist']);
@@ -2628,7 +2628,7 @@ async function clone(app, data, user, auditSource) {
if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, portBindings);
if (addError) throw addError;
const restoreConfig = { backupId: backup.id };
const restoreConfig = { backupId: cloneBackup.id };
const task = {
args: { restoreConfig, overwriteDns, skipDnsSetup, oldManifest: null },
values: {},
@@ -2642,24 +2642,24 @@ async function clone(app, data, user, auditSource) {
newApp.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); });
newApp.aliasDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); });
await eventlog.add(eventlog.ACTION_APP_CLONE, auditSource, { appId: newAppId, oldAppId: app.id, backupId, remotePath: backup.remotePath, oldApp: app, newApp, taskId });
await eventlog.add(eventlog.ACTION_APP_CLONE, auditSource, { appId: newAppId, oldAppId: app.id, backupId, remotePath: cloneBackup.remotePath, oldApp: app, newApp, taskId });
return { id: newAppId, taskId };
}
async function unarchive(archive, data, auditSource) {
assert.strictEqual(typeof archive, 'object');
async function unarchive(archiveEntry, data, auditSource) {
assert.strictEqual(typeof archiveEntry, 'object');
assert.strictEqual(typeof data, 'object');
assert(auditSource && typeof auditSource === 'object');
const backup = await backups.get(archive.backupId);
const restoreConfig = { backupId: backup.id };
const archiveBackup = await backups.get(archiveEntry.backupId);
const restoreConfig = { backupId: archiveBackup.id };
const subdomain = data.subdomain.toLowerCase(),
domain = data.domain.toLowerCase(),
overwriteDns = 'overwriteDns' in data ? data.overwriteDns : false;
const manifest = backup.manifest, appStoreId = backup.manifest.id, versionsUrl = backup.appConfig?.versionsUrl || '';
const manifest = archiveBackup.manifest, appStoreId = archiveBackup.manifest.id, versionsUrl = archiveBackup.appConfig?.versionsUrl || '';
let error = validateSecondaryDomains(data.secondaryDomains || {}, manifest);
if (error) throw error;
@@ -2682,7 +2682,7 @@ async function unarchive(archive, data, auditSource) {
const appId = crypto.randomUUID();
// appConfig is null for pre-8.2 backups
const dolly = _.pick(backup.appConfig || {}, ['memoryLimit', 'cpuQuota', 'crontab', 'reverseProxyConfig', 'env', 'servicesConfig',
const dolly = _.pick(archiveBackup.appConfig || {}, ['memoryLimit', 'cpuQuota', 'crontab', 'reverseProxyConfig', 'env', 'servicesConfig',
'tags', 'label', 'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain', 'devices',
'enableTurn', 'enableRedis', 'mounts', 'enableBackup', 'enableAutomaticUpdate', 'accessRestriction', 'operators', 'sso',
'notes', 'checklist']);
@@ -2695,9 +2695,9 @@ async function unarchive(archive, data, auditSource) {
mailboxDomain: data.domain, // archive's mailboxDomain may not exist
runState: RSTATE_RUNNING,
installationState: ISTATE_PENDING_INSTALL,
sso: backup.appConfig ? backup.appConfig.sso : true // when no appConfig take a blind guess
sso: archiveBackup.appConfig ? archiveBackup.appConfig.sso : true // when no appConfig take a blind guess
});
obj.icon = (await archives.getIcons(archive.id))?.icon;
obj.icon = (await archives.getIcons(archiveEntry.id))?.icon;
const [addError] = await safe(add(appId, appStoreId, versionsUrl, manifest, subdomain, domain, portBindings, obj));
if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, portBindings);
@@ -2831,8 +2831,8 @@ async function backup(app, backupSiteId, auditSource) {
// background
tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit, oomScoreAdjust: -999 })
.then(async (backupId) => {
const backup = await backups.get(backupId); // if task crashed, no result
await eventlog.add(eventlog.ACTION_APP_BACKUP_FINISH, auditSource, { app, success: !!backup, errorMessage: '', remotePath: backup?.remotePath, backupId: backupId });
const completedBackup = await backups.get(backupId); // if task crashed, no result
await eventlog.add(eventlog.ACTION_APP_BACKUP_FINISH, auditSource, { app, success: !!completedBackup, errorMessage: '', remotePath: completedBackup?.remotePath, backupId: backupId });
})
.catch(async (error) => {
await eventlog.add(eventlog.ACTION_APP_BACKUP_FINISH, auditSource, { app, success: false, errorMessage: error.message });
@@ -2851,28 +2851,28 @@ async function updateBackup(app, backupId, data) {
assert.strictEqual(typeof backupId, 'string');
assert.strictEqual(typeof data, 'object');
const backup = await backups.get(backupId);
if (!backup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (backup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
const appBackup = await backups.get(backupId);
if (!appBackup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (appBackup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
await backups.update(backup, data);
await backups.update(appBackup, data);
}
async function getBackupDownloadStream(app, backupId) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof backupId, 'string');
const backup = await backups.get(backupId);
if (!backup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (backup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
const downloadBackup = await backups.get(backupId);
if (!downloadBackup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (downloadBackup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
const backupSite = await backupSites.get(backup.siteId);
const backupSite = await backupSites.get(downloadBackup.siteId);
if (!backupSite) throw new BoxError(BoxError.NOT_FOUND, 'Backup site not found'); // not possible
if (backupSite.format !== 'tgz') throw new BoxError(BoxError.BAD_STATE, 'only tgz backups can be downloaded');
const ps = new PassThrough();
const stream = await backupSites.storageApi(backupSite).download(backupSite.config, backup.remotePath);
const stream = await backupSites.storageApi(backupSite).download(backupSite.config, downloadBackup.remotePath);
stream.on('error', function(error) {
debug(`getBackupDownloadStream: read stream error: ${error.message}`);
ps.emit('error', new BoxError(BoxError.EXTERNAL_ERROR, error));
@@ -2880,7 +2880,7 @@ async function getBackupDownloadStream(app, backupId) {
stream.pipe(ps);
const now = (new Date()).toISOString().replace(/:|T/g,'-').replace(/\..*/,'');
const encryptionSuffix = backup.encryptionVersion ? '.enc' : '';
const encryptionSuffix = downloadBackup.encryptionVersion ? '.enc' : '';
const filename = `app-backup-${now} (${app.fqdn}).tar.gz${encryptionSuffix}`;
return { stream: ps, filename };