mirror of
				https://github.com/filebrowser/filebrowser.git
				synced 2025-11-04 03:12:57 +00:00 
			
		
		
		
	fix: search results absolute url
This commit is contained in:
		
							parent
							
								
									babd7783af
								
							
						
					
					
						commit
						26d62e4117
					
				@ -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)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -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)
 | 
					        this.results = await search(path, this.value)
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        this.$showError(error)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      this.ongoing = false
 | 
					      this.ongoing = false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user