forked from amir1376/ab-download-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rest api to add silent downloads
- Loading branch information
Talha Ahmed
committed
Oct 8, 2024
1 parent
34801da
commit cf1e9b9
Showing
8 changed files
with
144 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
To lazy to do it in openapi v3. | ||
Default port is `15151` | ||
|
||
## Endpoints | ||
|
||
- `POST /add` | ||
- ```ts | ||
interface Request{ | ||
body: { | ||
link: string; | ||
headers?: Record<string,string> | ||
downloadPage?: string | ||
} | ||
} | ||
``` | ||
- `GET /queues` | ||
- Returns list of queues | ||
- ```ts | ||
interface Queue{ | ||
id: number | ||
name: string | ||
} | ||
type Response = { | ||
body: Queue[] | ||
} | ||
``` | ||
- `POST /add-download-task` | ||
- ```ts | ||
interface Request{ | ||
body: { | ||
downloadSource: { | ||
link: string; | ||
headers?: Record<string,string>; | ||
downloadPage?: string; | ||
} | ||
folder?: string; //unix style path separator | ||
name?: string; | ||
folder?: string; | ||
queueId?: number; | ||
} | ||
} | ||
``` |
63 changes: 52 additions & 11 deletions
63
...op/app/src/main/kotlin/com/abdownloadmanager/desktop/integration/IntegrationHandlerImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,62 @@ | ||
package com.abdownloadmanager.desktop.integration | ||
|
||
import com.abdownloadmanager.integration.IntegrationHandler | ||
import com.abdownloadmanager.desktop.AppComponent | ||
import ir.amirab.downloader.downloaditem.DownloadCredentials | ||
import com.abdownloadmanager.desktop.repository.AppRepository | ||
import com.abdownloadmanager.desktop.utils.DownloadSystem | ||
import com.abdownloadmanager.integration.IntegrationHandler | ||
import com.abdownloadmanager.integration.NewDownloadInfoFromIntegration | ||
import com.abdownloadmanager.integration.NewDownloadTask | ||
import com.abdownloadmanager.integration.QueueModel | ||
import ir.amirab.downloader.downloaditem.DownloadCredentials | ||
import ir.amirab.downloader.downloaditem.DownloadItem | ||
import ir.amirab.downloader.queue.QueueManager | ||
import ir.amirab.downloader.utils.OnDuplicateStrategy | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class IntegrationHandlerImp: IntegrationHandler,KoinComponent{ | ||
class IntegrationHandlerImp : IntegrationHandler, KoinComponent { | ||
val appComponent by inject<AppComponent>() | ||
val downloadSystem by inject<DownloadSystem>() | ||
val queueManager by inject<QueueManager>() | ||
val appSettings by inject<AppRepository>() | ||
override suspend fun addDownload(list: List<NewDownloadInfoFromIntegration>) { | ||
appComponent.openAddDownloadDialog(list.map { | ||
DownloadCredentials( | ||
link = it.link, | ||
headers = it.headers, | ||
downloadPage = it.downloadPage, | ||
) | ||
}) | ||
appComponent.openAddDownloadDialog( | ||
list.map { | ||
DownloadCredentials( | ||
link = it.link, | ||
headers = it.headers, | ||
downloadPage = it.downloadPage, | ||
) | ||
} | ||
) | ||
} | ||
override fun listQueues(): List<QueueModel> { | ||
return queueManager.getAll().map { downloadQueue -> | ||
val queueModel = downloadQueue.getQueueModel() | ||
QueueModel(id = queueModel.id, name = queueModel.name) | ||
} | ||
} | ||
override suspend fun addDownloadTask(task: NewDownloadTask) { | ||
val downloadItem = | ||
DownloadItem( | ||
link = task.downloadSource.link, | ||
headers = task.downloadSource.headers, | ||
downloadPage = task.downloadSource.downloadPage, | ||
folder = task.folder ?: appSettings.saveLocation.value, | ||
id = -1, | ||
name = task.name ?: task.downloadSource.link.substringAfterLast("/"), | ||
) | ||
val id = | ||
downloadSystem.addDownload( | ||
downloadItem, | ||
OnDuplicateStrategy.default(), | ||
task.queueId | ||
) | ||
if (task.queueId != null) { | ||
val queue = queueManager.getQueue(task.queueId!!) | ||
queue.start() | ||
} else { | ||
downloadSystem.manualResume(id) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
integration/server/src/main/kotlin/com/abdownloadmanager/integration/IntegrationHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.abdownloadmanager.integration | ||
|
||
interface IntegrationHandler{ | ||
suspend fun addDownload( | ||
list: List<NewDownloadInfoFromIntegration> | ||
) | ||
} | ||
interface IntegrationHandler { | ||
suspend fun addDownload(list: List<NewDownloadInfoFromIntegration>) | ||
fun listQueues(): List<QueueModel> | ||
suspend fun addDownloadTask(task: NewDownloadTask) | ||
} |
11 changes: 11 additions & 0 deletions
11
integration/server/src/main/kotlin/com/abdownloadmanager/integration/NewDownloadTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.abdownloadmanager.integration | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class NewDownloadTask( | ||
val downloadSource: NewDownloadInfoFromIntegration, | ||
var folder: String? = null, | ||
var name: String? = null, | ||
var queueId: Long? = null, | ||
) |
9 changes: 9 additions & 0 deletions
9
integration/server/src/main/kotlin/com/abdownloadmanager/integration/QueueModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.abdownloadmanager.integration | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class QueueModel( | ||
val id: Long, | ||
val name: String, | ||
) |