diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index e3c8be86..1f2eca6a 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -34,6 +34,7 @@ class MuWireSettings { boolean searchComments boolean searchCollections boolean browseFiles + boolean showPaths boolean allowTracking boolean fileFeed @@ -124,6 +125,7 @@ class MuWireSettings { searchComments = Boolean.valueOf(props.getProperty("searchComments","true")) searchCollections = Boolean.valueOf(props.getProperty("searchCollections","true")) browseFiles = Boolean.valueOf(props.getProperty("browseFiles","true")) + showPaths = Boolean.valueOf(props.getProperty("showPaths", "true")) allowTracking = Boolean.valueOf(props.getProperty("allowTracking","true")) // feed settings @@ -221,6 +223,7 @@ class MuWireSettings { props.setProperty("searchComments", String.valueOf(searchComments)) props.setProperty("searchCollections", String.valueOf(searchCollections)) props.setProperty("browseFiles", String.valueOf(browseFiles)) + props.setProperty("showPaths", String.valueOf(showPaths)) props.setProperty("allowTracking", String.valueOf(allowTracking)) // feed settings diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 2ba64eed..8086c683 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -402,6 +402,10 @@ class ConnectionAcceptor { browsed++ + boolean showPaths = settings.showPaths && + headers.containsKey('Path') && + Boolean.parseBoolean(headers['Path']) + os.write("200 OK\r\n".getBytes(StandardCharsets.US_ASCII)) def sharedFiles = fileManager.getSharedFiles().values() @@ -423,7 +427,7 @@ class ConnectionAcceptor { InfoHash ih = new InfoHash(it.getRoot()) int certificates = certificateManager.getByInfoHash(ih).size() Set collections = collectionManager.collectionsForFile(ih) - def obj = ResultsSender.sharedFileToObj(it, false, certificates, collections) + def obj = ResultsSender.sharedFileToObj(it, false, certificates, collections, showPaths) def json = jsonOutput.toJson(obj) dos.writeShort((short)json.length()) dos.write(json.getBytes(StandardCharsets.US_ASCII)) diff --git a/core/src/main/groovy/com/muwire/core/search/BrowseManager.groovy b/core/src/main/groovy/com/muwire/core/search/BrowseManager.groovy index f108e97e..e73a2223 100644 --- a/core/src/main/groovy/com/muwire/core/search/BrowseManager.groovy +++ b/core/src/main/groovy/com/muwire/core/search/BrowseManager.groovy @@ -42,6 +42,7 @@ class BrowseManager { OutputStream os = endpoint.getOutputStream() os.write("BROWSE\r\n".getBytes(StandardCharsets.US_ASCII)) os.write("Persona:${me.toBase64()}\r\n".getBytes(StandardCharsets.US_ASCII)) + os.write("Path:true\r\n".getBytes(StandardCharsets.US_ASCII)) os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) InputStream is = endpoint.getInputStream() diff --git a/core/src/main/groovy/com/muwire/core/search/ResultsParser.groovy b/core/src/main/groovy/com/muwire/core/search/ResultsParser.groovy index 7662cfc5..0e4b405b 100644 --- a/core/src/main/groovy/com/muwire/core/search/ResultsParser.groovy +++ b/core/src/main/groovy/com/muwire/core/search/ResultsParser.groovy @@ -114,6 +114,13 @@ class ResultsParser { collections = new HashSet<>() json.collections.collect(collections, { new InfoHash(Base64.decode(it)) }) } + + List path = new ArrayList<>() + if (json.path != null && json.path instanceof List) { + json.path.each { + path << DataUtil.readi18nString(Base64.decode(it)) + } + } log.fine("Received result from ${p.getHumanReadableName()} name \"$name\" infoHash:\"${json.infohash}\"") @@ -128,7 +135,8 @@ class ResultsParser { browseCollections : browseCollections, uuid: uuid, certificates : certificates, - collections : collections) + collections : collections, + path: path.toArray(new String[0])) } catch (Exception e) { throw new InvalidSearchResultException("parsing search result failed",e) } diff --git a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy index 183cb2d2..e41c0033 100644 --- a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy +++ b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy @@ -11,6 +11,7 @@ import com.muwire.core.util.DataUtil import com.muwire.core.Persona import java.nio.charset.StandardCharsets +import java.nio.file.Path import java.util.concurrent.Executor import java.util.concurrent.Executors import java.util.concurrent.ThreadFactory @@ -131,7 +132,7 @@ class ResultsSender { InfoHash ih = new InfoHash(it.getRoot()) int certificates = certificateManager.getByInfoHash(ih).size() Set collections = collectionManager.collectionsForFile(ih) - def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections) + def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, false) def json = jsonOutput.toJson(obj) os.writeShort((short)json.length()) os.write(json.getBytes(StandardCharsets.US_ASCII)) @@ -160,7 +161,7 @@ class ResultsSender { InfoHash ih = new InfoHash(it.getRoot()) int certificates = certificateManager.getByInfoHash(ih).size() Set collections = collectionManager.collectionsForFile(ih) - def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections) + def obj = sharedFileToObj(it, settings.browseFiles, certificates, collections, false) def json = jsonOutput.toJson(obj) dos.writeShort((short)json.length()) dos.write(json.getBytes(StandardCharsets.US_ASCII)) @@ -178,7 +179,8 @@ class ResultsSender { } } - public static def sharedFileToObj(SharedFile sf, boolean browseFiles, int certificates, Set collections) { + public static def sharedFileToObj(SharedFile sf, boolean browseFiles, int certificates, + Set collections, boolean showPaths) { byte [] name = sf.getFile().getName().getBytes(StandardCharsets.UTF_8) def baos = new ByteArrayOutputStream() def daos = new DataOutputStream(baos) @@ -204,6 +206,16 @@ class ResultsSender { obj.browseCollections = browseFiles obj.certificates = certificates obj.collections = collections.collect { Base64.encode(it.getRoot()) } + + if (showPaths) { + List path = new ArrayList<>() + if (sf.getPathToSharedParent() != null) { + for (Path element : sf.getPathToSharedParent()) + path << Base64.encode(DataUtil.encodei18nString(element.toString())) + } + obj.path = path + } + obj } } diff --git a/core/src/main/groovy/com/muwire/core/search/UIResultEvent.groovy b/core/src/main/groovy/com/muwire/core/search/UIResultEvent.groovy index 356418ae..dd4520cf 100644 --- a/core/src/main/groovy/com/muwire/core/search/UIResultEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/search/UIResultEvent.groovy @@ -22,6 +22,19 @@ class UIResultEvent extends Event { boolean feed boolean messages Set collections + String[] path + + + private String fullPath + String getFullPath() { + if (fullPath == null) { + if (path != null && path.length > 0) + fullPath = path.join(File.separator) + File.separator + name + else + fullPath = name + } + fullPath + } @Override public String toString() {