only show paths if the query was searching for paths

auto-update
Zlatin Balevsky 2021-10-10 00:00:50 +01:00
parent 1c5100f320
commit 296f8a9f4d
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 18 additions and 10 deletions

View File

@ -65,7 +65,8 @@ class ResultsSender {
this.collectionManager = collectionManager this.collectionManager = collectionManager
} }
void sendResults(UUID uuid, SharedFile[] results, Destination target, boolean oobInfohash, boolean compressedResults) { void sendResults(UUID uuid, SharedFile[] results, Destination target, boolean oobInfohash, boolean compressedResults,
boolean searchPaths) {
log.info("Sending $results.length results for uuid $uuid to ${target.toBase32()} oobInfohash : $oobInfohash") log.info("Sending $results.length results for uuid $uuid to ${target.toBase32()} oobInfohash : $oobInfohash")
if (target.equals(me.destination)) { if (target.equals(me.destination)) {
def uiResultEvents = [] def uiResultEvents = []
@ -85,9 +86,13 @@ class ResultsSender {
int certificates = certificateManager.getByInfoHash(ih).size() int certificates = certificateManager.getByInfoHash(ih).size()
Set<InfoHash> collections = collectionManager.collectionsForFile(ih) Set<InfoHash> collections = collectionManager.collectionsForFile(ih)
List<String> pathElements = new ArrayList<>() String [] path = null
for(String pathElement : it.getPathToSharedParent()) if (settings.showPaths && searchPaths) {
pathElements << pathElement List<String> pathElements = new ArrayList<>()
for (String pathElement : it.getPathToSharedParent())
pathElements << pathElement
path = pathElements.toArray(new String[0])
}
def uiResultEvent = new UIResultEvent( sender : me, def uiResultEvent = new UIResultEvent( sender : me,
name : it.getFile().getName(), name : it.getFile().getName(),
@ -104,14 +109,15 @@ class ResultsSender {
messages : settings.allowMessages, messages : settings.allowMessages,
feed : settings.fileFeed && settings.advertiseFeed, feed : settings.fileFeed && settings.advertiseFeed,
collections : collections, collections : collections,
path: pathElements.toArray(new String[0]) path: path
) )
uiResultEvents << uiResultEvent uiResultEvents << uiResultEvent
} }
eventBus.publish(new UIResultBatchEvent(uuid : uuid, results : uiResultEvents)) eventBus.publish(new UIResultBatchEvent(uuid : uuid, results : uiResultEvents))
} else { } else {
executor.execute(new ResultSendJob(uuid : uuid, results : results, executor.execute(new ResultSendJob(uuid : uuid, results : results,
target: target, oobInfohash : oobInfohash, compressedResults : compressedResults)) target: target, oobInfohash : oobInfohash, compressedResults : compressedResults,
showPaths: searchPaths && settings.showPaths))
} }
} }
@ -121,6 +127,7 @@ class ResultsSender {
Destination target Destination target
boolean oobInfohash boolean oobInfohash
boolean compressedResults boolean compressedResults
boolean showPaths
@Override @Override
public void run() { public void run() {
@ -138,8 +145,7 @@ class ResultsSender {
InfoHash ih = new InfoHash(it.getRoot()) InfoHash ih = new InfoHash(it.getRoot())
int certificates = certificateManager.getByInfoHash(ih).size() int certificates = certificateManager.getByInfoHash(ih).size()
Set<InfoHash> collections = collectionManager.collectionsForFile(ih) Set<InfoHash> collections = collectionManager.collectionsForFile(ih)
def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, showPaths)
settings.showPaths)
def json = jsonOutput.toJson(obj) def json = jsonOutput.toJson(obj)
os.writeShort((short)json.length()) os.writeShort((short)json.length())
os.write(json.getBytes(StandardCharsets.US_ASCII)) os.write(json.getBytes(StandardCharsets.US_ASCII))
@ -168,7 +174,7 @@ class ResultsSender {
InfoHash ih = new InfoHash(it.getRoot()) InfoHash ih = new InfoHash(it.getRoot())
int certificates = certificateManager.getByInfoHash(ih).size() int certificates = certificateManager.getByInfoHash(ih).size()
Set<InfoHash> collections = collectionManager.collectionsForFile(ih) Set<InfoHash> collections = collectionManager.collectionsForFile(ih)
def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, settings.showPaths) def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, showPaths)
def json = jsonOutput.toJson(obj) def json = jsonOutput.toJson(obj)
dos.writeShort((short)json.length()) dos.writeShort((short)json.length())
dos.write(json.getBytes(StandardCharsets.US_ASCII)) dos.write(json.getBytes(StandardCharsets.US_ASCII))

View File

@ -84,7 +84,9 @@ public class SearchManager {
SharedFile[] results = it.results.toArray() SharedFile[] results = it.results.toArray()
resultsSender.sendResults(it.resultsEvent.uuid, results, it.target, resultsSender.sendResults(it.resultsEvent.uuid, results, it.target,
it.resultsEvent.searchEvent.oobInfohash, it.resultsEvent.searchEvent.oobInfohash,
it.resultsEvent.searchEvent.compressedResults) it.resultsEvent.searchEvent.compressedResults,
it.resultsEvent.searchEvent.searchPaths
)
} }
} }