Merge pull request #1100 from ramiresviana/fixes-3

This commit is contained in:
Oleg Lobanov 2020-10-01 16:53:35 +02:00 committed by GitHub
commit 4c2a094255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 26 deletions

View File

@ -1,8 +1,26 @@
import { fetchJSON, removePrefix } from './utils' import { fetchURL, removePrefix } from './utils'
import url from '../utils/url'
export default async function search (url, query) { export default async function search (base, query) {
url = removePrefix(url) base = removePrefix(base)
query = encodeURIComponent(query) query = encodeURIComponent(query)
return fetchJSON(`/api/search${url}?query=${query}`, {}) if (!base.endsWith('/')) {
} base += '/'
}
let res = await fetchURL(`/api/search${base}?query=${query}`, {})
if (res.status === 200) {
let data = await res.json()
data = data.map((item) => {
item.url = `/files${base}` + url.encodePath(item.path)
return item
})
return data
} else {
throw Error(res.status)
}
}

View File

@ -49,7 +49,7 @@
</template> </template>
<ul v-show="results.length > 0"> <ul v-show="results.length > 0">
<li v-for="(s,k) in filteredResults" :key="k"> <li v-for="(s,k) in filteredResults" :key="k">
<router-link @click.native="close" :to="'./' + s.path"> <router-link @click.native="close" :to="s.url">
<i v-if="s.dir" class="material-icons">folder</i> <i v-if="s.dir" class="material-icons">folder</i>
<i v-else class="material-icons">insert_drive_file</i> <i v-else class="material-icons">insert_drive_file</i>
<span>./{{ s.path }}</span> <span>./{{ s.path }}</span>
@ -183,8 +183,12 @@ export default {
this.ongoing = true this.ongoing = true
try {
this.results = await search(path, this.value)
} catch (error) {
this.$showError(error)
}
this.results = await search(path, this.value)
this.ongoing = false this.ongoing = false
} }
} }

View File

@ -103,7 +103,7 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['req', 'user', 'oldReq', 'jwt', 'loading']), ...mapState(['req', 'user', 'oldReq', 'jwt', 'loading', 'show']),
hasPrevious () { hasPrevious () {
return (this.previousLink !== '') return (this.previousLink !== '')
}, },
@ -159,6 +159,10 @@ export default {
key (event) { key (event) {
event.preventDefault() event.preventDefault()
if (this.show !== null) {
return
}
if (event.which === 13 || event.which === 39) { // right arrow if (event.which === 13 || event.which === 39) { // right arrow
if (this.hasNext) this.next() if (this.hasNext) this.next()
} else if (event.which === 37) { // left arrow } else if (event.which === 37) { // left arrow

View File

@ -16,7 +16,11 @@ export default {
return this.commands.join(' ') return this.commands.join(' ')
}, },
set (value) { set (value) {
this.$emit('update:commands', value.split(' ')) if (value !== '') {
this.$emit('update:commands', value.split(' '))
} else {
this.$emit('update:commands', [])
}
} }
} }
} }

View File

@ -96,31 +96,25 @@ export function scanFiles(dt) {
}) })
} }
export function handleFiles(files, path, overwrite = false) { export function handleFiles(files, base, overwrite = false) {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
let id = store.state.upload.id
let path = base
let file = files[i] let file = files[i]
let filename = (file.fullPath !== undefined) ? file.fullPath : file.name if (file.fullPath !== undefined) {
let filenameEncoded = url.encodeRFC5987ValueChars(filename) path += url.encodePath(file.fullPath)
} else {
let id = store.state.upload.id path += url.encodeRFC5987ValueChars(file.name)
}
let itemPath = path + filenameEncoded
if (file.isDir) { if (file.isDir) {
itemPath = path path += '/'
let folders = file.fullPath.split("/")
for (let i = 0; i < folders.length; i++) {
let folder = folders[i]
let folderEncoded = encodeURIComponent(folder)
itemPath += folderEncoded + "/"
}
} }
const item = { const item = {
id, id,
path: itemPath, path,
file, file,
overwrite overwrite
} }

View File

@ -60,7 +60,9 @@ func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(
if len(search.Terms) > 0 { if len(search.Terms) > 0 {
for _, term := range search.Terms { for _, term := range search.Terms {
if strings.Contains(path, term) { if strings.Contains(path, term) {
return found(strings.TrimPrefix(originalPath, scope), f) originalPath = strings.TrimPrefix(originalPath, scope)
originalPath = strings.TrimPrefix(originalPath, "/")
return found(originalPath, f)
} }
} }
} }