Skip to content

Commit

Permalink
Add resourcepack.host auto-upload preset
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Jun 27, 2023
1 parent 3c9749c commit 44c63b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import xyz.xenondevs.nova.data.config.configReloadable
import xyz.xenondevs.nova.data.resources.ResourceGeneration
import xyz.xenondevs.nova.data.resources.builder.ResourcePackBuilder
import xyz.xenondevs.nova.data.resources.upload.service.CustomMultiPart
import xyz.xenondevs.nova.data.resources.upload.service.ResourcePackDotHost
import xyz.xenondevs.nova.data.resources.upload.service.S3
import xyz.xenondevs.nova.data.resources.upload.service.SelfHost
import xyz.xenondevs.nova.data.resources.upload.service.Xenondevs
Expand All @@ -29,7 +30,7 @@ import java.util.logging.Level
)
internal object AutoUploadManager {

internal val services = arrayListOf(Xenondevs, SelfHost, CustomMultiPart, S3)
internal val services = arrayListOf(Xenondevs, SelfHost, CustomMultiPart, S3, ResourcePackDotHost)

private val resourcePackCfg by configReloadable { DEFAULT_CONFIG.getConfigurationSection("resource_pack")!! }
private val autoUploadCfg by configReloadable { DEFAULT_CONFIG.getConfigurationSection("resource_pack.auto_upload")!! }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@ import xyz.xenondevs.nova.HTTP_CLIENT
import xyz.xenondevs.nova.data.resources.upload.UploadService
import java.io.File

internal object CustomMultiPart : UploadService {
internal abstract class MultiPart : UploadService {

override val name = "CustomMultiPart"

private lateinit var url: String
private lateinit var filePartName: String
var urlRegex: Regex? = null
private val extraParams = HashMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) {
url = cfg.getString("url")
?: throw IllegalArgumentException("No url specified for CustomMultiPart")
filePartName = cfg.getString("filePartName")
?: throw IllegalArgumentException("No filePartName specified for CustomMultiPart")
urlRegex = cfg.getString("urlRegex")?.let(::Regex)
val extraParams = cfg.getConfigurationSection("extraParams")
?: return
extraParams.getValues(false).forEach { (key, value) ->
this.extraParams[key] = value.toString()
}
}
protected abstract val url: String
protected abstract val filePartName: String
protected abstract val urlRegex: Regex?
protected abstract val extraParams: Map<String, String>

override suspend fun upload(file: File): String {
val response = HTTP_CLIENT.submitFormWithBinaryData(url, formData {
Expand All @@ -46,4 +31,40 @@ internal object CustomMultiPart : UploadService {

override fun disable() = Unit

}

internal object CustomMultiPart : MultiPart() {

override val names = listOf("custom_multi_part", "custommultipart")

override lateinit var url: String
override lateinit var filePartName: String
public override var urlRegex: Regex? = null
override val extraParams = HashMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) {
url = cfg.getString("url")
?: throw IllegalArgumentException("No url specified for CustomMultiPart")
filePartName = cfg.getString("filePartName")
?: throw IllegalArgumentException("No filePartName specified for CustomMultiPart")
urlRegex = cfg.getString("urlRegex")?.let(::Regex)
val extraParams = cfg.getConfigurationSection("extraParams")
?: return
extraParams.getValues(false).forEach { (key, value) ->
this.extraParams[key] = value.toString()
}
}

}

internal object ResourcePackDotHost : MultiPart() {

override val names = listOf("resourcepack.host")
override val url = "https://resourcepack.host/index.php"
override var filePartName = "pack"
override var urlRegex = Regex("""(http://resourcepack\.host/dl/[^"]+)""")
override val extraParams = emptyMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) = Unit

}

0 comments on commit 44c63b3

Please sign in to comment.