plumbing for downloading attachments

pull/53/head
Zlatin Balevsky 2020-11-04 18:32:07 +00:00
parent 72a91c4489
commit dd336ea743
No known key found for this signature in database
GPG Key ID: A72832072D525E41
3 changed files with 23 additions and 0 deletions

View File

@ -81,6 +81,7 @@ import com.muwire.core.hostcache.SimpleHostCache
import com.muwire.core.mesh.MeshManager
import com.muwire.core.messenger.MessageReceivedEvent
import com.muwire.core.messenger.Messenger
import com.muwire.core.messenger.UIDownloadAttachmentEvent
import com.muwire.core.messenger.UIMessageEvent
import com.muwire.core.search.BrowseManager
import com.muwire.core.search.QueryEvent
@ -425,6 +426,7 @@ public class Core {
eventBus.register(UIDownloadResumedEvent.class, downloadManager)
eventBus.register(DownloadHopelessEvent.class, downloadManager)
eventBus.register(UIDownloadCollectionEvent.class, downloadManager)
eventBus.register(UIDownloadAttachmentEvent.class, downloadManager)
log.info("initializing upload manager")
uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager, persisterFolderService, props)

View File

@ -6,6 +6,7 @@ import com.muwire.core.files.FileDownloadedEvent
import com.muwire.core.files.FileHasher
import com.muwire.core.mesh.Mesh
import com.muwire.core.mesh.MeshManager
import com.muwire.core.messenger.UIDownloadAttachmentEvent
import com.muwire.core.trust.TrustLevel
import com.muwire.core.trust.TrustService
import com.muwire.core.util.DataUtil
@ -109,6 +110,16 @@ public class DownloadManager {
}
}
public void onUIDownloadAttachmentEvent(UIDownloadAttachmentEvent e) {
Set<Destination> sender = new HashSet<>()
sender.add(e.sender)
File target = muSettings.downloadLocation
target = new File(target, e.attachment.name)
doDownload(e.attachment.infoHash, target, e.attachment.length, e.attachment.pieceSizePow2, e.sequential, sender, null)
}
private Downloader doDownload(InfoHash infoHash, File target, long size, int pieceSize,
boolean sequential, Set<Destination> destinations, InfoHash collectionInfoHash) {
File incompletes = muSettings.incompleteLocation

View File

@ -0,0 +1,10 @@
package com.muwire.core.messenger
import com.muwire.core.Event
import com.muwire.core.Persona
class UIDownloadAttachmentEvent extends Event {
Persona sender
MWMessageAttachment attachment
boolean sequential
}