Skip to content

Commit

Permalink
Merge pull request #4089 from LibreSign/backport/4087/stable29
Browse files Browse the repository at this point in the history
[stable29] chore: clean code
  • Loading branch information
vitormattos authored Dec 1, 2024
2 parents e244fe8 + 6571dbb commit f3d51a6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 48 deletions.
3 changes: 1 addition & 2 deletions src/Components/Request/RequestPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
})
Expand Down
1 change: 0 additions & 1 deletion src/domains/files/index.js

This file was deleted.

45 changes: 0 additions & 45 deletions src/domains/files/service.js

This file was deleted.

22 changes: 22 additions & 0 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f3d51a6

Please sign in to comment.