mirror of https://github.com/zlatinb/muwire
transfer path information in browse GitHub issue #65
parent
009af0ce0c
commit
f1e73daf5c
|
@ -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
|
||||
|
|
|
@ -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<InfoHash> 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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -114,6 +114,13 @@ class ResultsParser {
|
|||
collections = new HashSet<>()
|
||||
json.collections.collect(collections, { new InfoHash(Base64.decode(it)) })
|
||||
}
|
||||
|
||||
List<String> 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)
|
||||
}
|
||||
|
|
|
@ -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<InfoHash> 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<InfoHash> 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<InfoHash> collections) {
|
||||
public static def sharedFileToObj(SharedFile sf, boolean browseFiles, int certificates,
|
||||
Set<InfoHash> 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<String> path = new ArrayList<>()
|
||||
if (sf.getPathToSharedParent() != null) {
|
||||
for (Path element : sf.getPathToSharedParent())
|
||||
path << Base64.encode(DataUtil.encodei18nString(element.toString()))
|
||||
}
|
||||
obj.path = path
|
||||
}
|
||||
|
||||
obj
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,19 @@ class UIResultEvent extends Event {
|
|||
boolean feed
|
||||
boolean messages
|
||||
Set<InfoHash> 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() {
|
||||
|
|
Loading…
Reference in New Issue