From a218761e999a19b61ea48fc278165a9f7152df31 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 19 Aug 2024 16:53:10 +0200 Subject: [PATCH] frontend: fix various linter issues --- frontend/src/views/Home.vue | 194 +++++++++++++++++------------------- 1 file changed, 93 insertions(+), 101 deletions(-) diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index be2c14aac..51f3f3d26 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -213,6 +213,76 @@ export default { this.loadCwd(); } }, + async mounted() { + this.busy = true; + const type = this.$route.params.type || 'app'; + const resourceId = this.$route.params.resourceId; + const cwd = this.$route.params.cwd; + + if (type === 'app') { + let error, result; + try { + result = await superagent.get(`${this.apiOrigin}/api/v1/apps/${resourceId}`).query({ access_token: this.accessToken }); + } catch (e) { + error = e; + } + + if (error || result.statusCode !== 200) { + console.error(`Invalid resource ${type} ${resourceId}`, error || result.statusCode); + return this.onFatalError(`Invalid resource ${type} ${resourceId}`); + } + + this.appLink = `https://${result.body.fqdn}`; + this.title = `${result.body.label || result.body.fqdn} (${result.body.manifest.title})`; + } else if (type === 'volume') { + let error, result; + try { + result = await superagent.get(`${this.apiOrigin}/api/v1/volumes/${resourceId}`).query({ access_token: this.accessToken }); + } catch (e) { + error = e; + } + + if (error || result.statusCode !== 200) { + console.error(`Invalid resource ${type} ${resourceId}`, error || result.statusCode); + return this.onFatalError(`Invalid resource ${type} ${resourceId}`); + } + + this.title = result.body.name; + } else { + return this.onFatalError(`Unsupported type ${type}`); + } + + try { + const result = await superagent.get(`${this.apiOrigin}/api/v1/dashboard/config`).query({ access_token: this.accessToken }); + this.footerContent = marked.parse(result.body.footer); + } catch (e) { + console.error('Failed to fetch Cloudron config.', e); + } + + window.document.title = `File Manager - ${this.title}`; + + this.cwd = sanitize('/' + (cwd ? cwd.join('/') : '/')); + this.resourceType = type; + this.resourceId = resourceId; + + this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, type === 'volume' ? `volumes/${resourceId}` : `apps/${resourceId}`); + this.ownersModel = this.directoryModel.ownersModel; + + this.loadCwd(); + + this.$watch(() => this.$route.params, (toParams, previousParams) => { + if (toParams.type !== 'app' && toParams.type !== 'volume') return this.onFatalError(`Unknown type ${toParams.type}`); + + if ((toParams.type !== this.resourceType) || (toParams.resourceId !== this.resourceId)) { + this.resourceType = toParams.type; + this.resourceId = toParams.resourceId; + + this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, toParams.type === 'volume' ? `volumes/${toParams.resourceId}` : `apps/${toParams.resourceId}`); + } + + this.cwd = toParams.cwd ? `/${toParams.cwd.join('/')}` : '/'; + }); + }, methods: { onFatalError(errorMessage) { this.fatalError = errorMessage; @@ -301,29 +371,29 @@ export default { }); } - const fileList = []; - async function traverseFileTree(item, path) { - return new Promise(async (resolve, reject) => { - if (item.isFile) { - fileList.push(await getFile(item)); - resolve(); - } else if (item.isDirectory) { - // Get folder contents - const dirReader = item.createReader(); - const entries = await new Promise((resolve, reject) => { dirReader.readEntries(resolve, reject); }); - - for (let i in entries) { - await traverseFileTree(entries[i], item.name); - } - - resolve(); - } else { - console.log('Skipping uknown file type', item); - resolve(); - } + async function readEntries(dirReader) { + return new Promise((resolve, reject) => { + dirReader.readEntries(resolve, reject); }); } + const fileList = []; + async function traverseFileTree(item) { + if (item.isFile) { + fileList.push(await getFile(item)); + } else if (item.isDirectory) { + // Get folder contents + const dirReader = item.createReader(); + const entries = await readEntries(dirReader); + + for (let i in entries) { + await traverseFileTree(entries[i], item.name); + } + } else { + console.log('Skipping uknown file type', item); + } + } + // collect all files to upload for (const item of dataTransfer.items) { const entry = item.webkitGetAsEntry(); @@ -360,16 +430,8 @@ export default { async deleteHandler(files) { if (!files) return; - function start_and_end(str) { - if (str.length > 100) { - return str.substr(0, 45) + ' ... ' + str.substr(str.length-45, str.length); - } - return str; - } - const confirmed = await this.$refs.inputDialog.confirm({ message: this.$t('filemanager.removeDialog.reallyDelete'), - // message: start_and_end(files.map((f) => f.name).join(', ')), confirmStyle: 'danger', confirmLabel: this.$t('main.dialog.yes'), rejectLabel: this.$t('main.dialog.no'), @@ -472,7 +534,7 @@ export default { try { await this.uploadRequest; } catch (e) { - console.log('Upload cancelled.'); + console.log('Upload cancelled.', e); } this.uploadRequest = null; @@ -514,11 +576,11 @@ export default { } while(true) { - let error, result; + let result; try { result = await superagent.get(`${this.apiOrigin}/api/v1/apps/${this.resourceId}`).query({ access_token: this.accessToken }); } catch (e) { - error = e; + console.error('Failed to fetch app status.', e); } if (result && result.statusCode === 200 && result.body.installationState === ISTATES.INSTALLED) break; @@ -528,76 +590,6 @@ export default { this.busyRestart = false; } - }, - async mounted() { - this.busy = true; - const type = this.$route.params.type || 'app'; - const resourceId = this.$route.params.resourceId; - const cwd = this.$route.params.cwd; - - if (type === 'app') { - let error, result; - try { - result = await superagent.get(`${this.apiOrigin}/api/v1/apps/${resourceId}`).query({ access_token: this.accessToken }); - } catch (e) { - error = e; - } - - if (error || result.statusCode !== 200) { - console.error(`Invalid resource ${type} ${resourceId}`, error || result.statusCode); - return this.onFatalError(`Invalid resource ${type} ${resourceId}`); - } - - this.appLink = `https://${result.body.fqdn}`; - this.title = `${result.body.label || result.body.fqdn} (${result.body.manifest.title})`; - } else if (type === 'volume') { - let error, result; - try { - result = await superagent.get(`${this.apiOrigin}/api/v1/volumes/${resourceId}`).query({ access_token: this.accessToken }); - } catch (e) { - error = e; - } - - if (error || result.statusCode !== 200) { - console.error(`Invalid resource ${type} ${resourceId}`, error || result.statusCode); - return this.onFatalError(`Invalid resource ${type} ${resourceId}`); - } - - this.title = result.body.name; - } else { - return this.onFatalError(`Unsupported type ${type}`); - } - - try { - const result = await superagent.get(`${this.apiOrigin}/api/v1/dashboard/config`).query({ access_token: this.accessToken }); - this.footerContent = marked.parse(result.body.footer); - } catch (e) { - console.error('Failed to fetch Cloudron config.', e); - } - - window.document.title = `File Manager - ${this.title}`; - - this.cwd = sanitize('/' + (cwd ? cwd.join('/') : '/')); - this.resourceType = type; - this.resourceId = resourceId; - - this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, type === 'volume' ? `volumes/${resourceId}` : `apps/${resourceId}`); - this.ownersModel = this.directoryModel.ownersModel; - - this.loadCwd(); - - this.$watch(() => this.$route.params, (toParams, previousParams) => { - if (toParams.type !== 'app' && toParams.type !== 'volume') return this.onFatalError(`Unknown type ${toParams.type}`); - - if ((toParams.type !== this.resourceType) || (toParams.resourceId !== this.resourceId)) { - this.resourceType = toParams.type; - this.resourceId = toParams.resourceId; - - this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, toParams.type === 'volume' ? `volumes/${toParams.resourceId}` : `apps/${toParams.resourceId}`); - } - - this.cwd = toParams.cwd ? `/${toParams.cwd.join('/')}` : '/'; - }); } };