From 6571dbb0bc03e2a60ef457c82c5ce7213de74ed1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Sun, 1 Dec 2024 19:51:16 -0300 Subject: [PATCH] chore: clean code Signed-off-by: Vitor Mattos --- src/Components/Request/RequestPicker.vue | 3 +- src/domains/files/index.js | 1 - src/domains/files/service.js | 45 ------------------------ src/store/files.js | 22 ++++++++++++ 4 files changed, 23 insertions(+), 48 deletions(-) delete mode 100644 src/domains/files/index.js delete mode 100644 src/domains/files/service.js diff --git a/src/Components/Request/RequestPicker.vue b/src/Components/Request/RequestPicker.vue index 7688a9d05c..54f6138da2 100644 --- a/src/Components/Request/RequestPicker.vue +++ b/src/Components/Request/RequestPicker.vue @@ -87,7 +87,6 @@ import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js' import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js' import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' -import { filesService } from '../../domains/files/index.js' import { useActionsMenuStore } from '../../store/actionsmenu.js' import { useFilesStore } from '../../store/files.js' @@ -187,7 +186,7 @@ export default { }, async upload(file) { const data = await loadFileToBase64(file) - await filesService.uploadFile({ + await this.filesStore.upload({ name: file.name, file: data, }) diff --git a/src/domains/files/index.js b/src/domains/files/index.js deleted file mode 100644 index b4f4994d42..0000000000 --- a/src/domains/files/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as filesService } from './service.js' diff --git a/src/domains/files/service.js b/src/domains/files/service.js deleted file mode 100644 index f97568f381..0000000000 --- a/src/domains/files/service.js +++ /dev/null @@ -1,45 +0,0 @@ -import axios from '@nextcloud/axios' -import { generateOcsUrl } from '@nextcloud/router' - -/* eslint-disable valid-jsdoc */ -import '@nextcloud/password-confirmation/dist/style.css' // Required for dialog styles - -// from https://gist.github.com/codeguy/6684588 -const slugfy = (val) => - val - .normalize('NFD') - .replace(/[\u0300-\u036f]/g, '') - .toLowerCase() - .replace(/[^a-z0-9 -]/g, '') // remove invalid chars - .replace(/\s+/g, '-') // collapse whitespace and replace by - - .replace(/-+/g, '-') // collapse dashes - .replace(/^-+/, '') // trim - from start of text - .replace(/-+$/, '') - -/** - * @param {import('@nextcloud/axios').default} http axios instance - */ -const buildService = (http) => ({ - async uploadFile({ file, name }) { - const url = generateOcsUrl('/apps/libresign/api/v1/file') - - const settings = { - folderName: `requests/${Date.now().toString(16)}-${slugfy(name)}`, - } - - const { data } = await http.post(url, { file: { base64: file }, name, settings }) - - return { - id: data.ocs.data.id, - etag: data.ocs.data.etag, - path: data.ocs.data.path, - type: data.ocs.data.type, - fileId: data.ocs.data.fileId, - message: data.ocs.data.message, - name: data.ocs.data.name, - } - }, -}) - -export { buildService } -export default buildService(axios) diff --git a/src/store/files.js b/src/store/files.js index f3175be076..135e35d4e7 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -34,6 +34,18 @@ import { useFiltersStore } from './filters.js' import { useSidebarStore } from './sidebar.js' import { useSignStore } from './sign.js' +// from https://gist.github.com/codeguy/6684588 +const slugfy = (val) => + val + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase() + .replace(/[^a-z0-9 -]/g, '') // remove invalid chars + .replace(/\s+/g, '-') // collapse whitespace and replace by - + .replace(/-+/g, '-') // collapse dashes + .replace(/^-+/, '') // trim - from start of text + .replace(/-+$/, '') + export const useFilesStore = function(...args) { const store = defineStore('files', { state: () => { @@ -258,6 +270,16 @@ export const useFilesStore = function(...args) { del(this.files, ...toRemove) this.loading = false }, + async upload({ file, name }) { + const { data } = await axios.post(generateOcsUrl('/apps/libresign/api/v1/file'), { + file: { base64: file }, + name, + settings: { + folderName: `requests/${Date.now().toString(16)}-${slugfy(name)}`, + }, + }) + return { ...data.ocs.data } + }, async getAllFiles(filter) { if (this.loading || this.loadedAll) { if (!filter) {