data classes in repositories and content classes
This commit is contained in:
parent
9d4ac85a81
commit
f57e5b304e
9 changed files with 33 additions and 37 deletions
|
@ -15,6 +15,7 @@ import org.jupnp.UpnpServiceConfiguration
|
|||
import org.jupnp.UpnpServiceImpl
|
||||
import org.jupnp.model.message.StreamRequestMessage
|
||||
import org.jupnp.model.message.StreamResponseMessage
|
||||
import org.jupnp.model.message.UpnpResponse
|
||||
import org.jupnp.model.meta.LocalDevice
|
||||
import org.jupnp.protocol.ProtocolFactory
|
||||
import org.jupnp.protocol.ProtocolFactoryImpl
|
||||
|
@ -59,6 +60,9 @@ class DlnaService(
|
|||
return with(upnpService.protocolFactory.createReceivingSync(requestMsg)) {
|
||||
run()
|
||||
outputMessage
|
||||
?: StreamResponseMessage(UpnpResponse.Status.NOT_FOUND).also {
|
||||
logger.warn { "Could not get response for ${requestMsg.operation.method} ${requestMsg}" }
|
||||
}
|
||||
}.also {
|
||||
logger.debug { "Response: ${it.operation.statusCode} ${it.body}" }
|
||||
}
|
||||
|
|
|
@ -3,22 +3,22 @@ package net.schowek.nextclouddlna.controller
|
|||
import jakarta.servlet.http.HttpServletRequest
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
import net.schowek.nextclouddlna.dlna.StreamRequestMapper
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
import org.springframework.core.io.InputStreamResource
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpStatusCode
|
||||
import org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestMethod.*
|
||||
import org.springframework.web.bind.annotation.ResponseBody
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
class UpnpController(
|
||||
private val streamRequestMapper: StreamRequestMapper,
|
||||
private val dlnaService: DlnaService
|
||||
|
|
|
@ -28,12 +28,10 @@ class StreamRequestMapper {
|
|||
|
||||
private fun createHeaders(request: HttpServletRequest): UpnpHeaders {
|
||||
val headers = mutableMapOf<String, List<String>>()
|
||||
with(request.headerNames) {
|
||||
if (this != null) {
|
||||
while (hasMoreElements()) {
|
||||
with(nextElement()) {
|
||||
headers[this] = listOf(request.getHeader(this))
|
||||
}
|
||||
request.headerNames?.let {
|
||||
while (it.hasMoreElements()) {
|
||||
with(it.nextElement()) {
|
||||
headers[this] = listOf(request.getHeader(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,17 +41,13 @@ class StreamRequestMapper {
|
|||
inner class MyHttpServerConnection(
|
||||
private val request: HttpServletRequest
|
||||
) : Connection {
|
||||
override fun isOpen(): Boolean {
|
||||
return true
|
||||
}
|
||||
override fun isOpen() = true
|
||||
|
||||
override fun getRemoteAddress(): InetAddress? {
|
||||
return if (request.remoteAddr != null) InetAddress.getByName(request.remoteAddr) else null
|
||||
}
|
||||
override fun getRemoteAddress(): InetAddress? =
|
||||
request.remoteAddr?.let { InetAddress.getByName(request.remoteAddr) }
|
||||
|
||||
override fun getLocalAddress(): InetAddress? {
|
||||
return if (request.localAddr != null) InetAddress.getByName(request.localAddr) else null
|
||||
}
|
||||
override fun getLocalAddress(): InetAddress? =
|
||||
request.localAddr?.let { InetAddress.getByName(request.localAddr) }
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
|
|
|
@ -39,7 +39,7 @@ class NodeConverter(
|
|||
c.setId("${n.id}")
|
||||
c.setParentID("${n.parentId}")
|
||||
c.setTitle(n.name)
|
||||
c.childCount = n.getNodeAndItemCount()
|
||||
c.childCount = n.nodeAndItemCount
|
||||
c.setRestricted(true)
|
||||
c.setWriteStatus(NOT_WRITABLE)
|
||||
c.isSearchable = true
|
||||
|
@ -67,21 +67,19 @@ class NodeConverter(
|
|||
}
|
||||
|
||||
companion object {
|
||||
private val DLNA_THUMBNAIL_TYPES = unmodifiableList(listOf(JPEG_TN, PNG_TN))
|
||||
private val MIME_TYPE_TO_DLNA_THUMBNAIL_TYPE = DLNA_THUMBNAIL_TYPES.associateBy { it.contentFormat }
|
||||
|
||||
private fun makeProtocolInfo(artMimeType: MimeType): DLNAProtocolInfo {
|
||||
val attributes = EnumMap<DLNAAttribute.Type, DLNAAttribute<*>>(
|
||||
DLNAAttribute.Type::class.java
|
||||
)
|
||||
val dlnaThumbnailProfile = findDlnaThumbnailProfile(artMimeType)
|
||||
if (dlnaThumbnailProfile != null) {
|
||||
attributes[DLNAAttribute.Type.DLNA_ORG_PN] = DLNAProfileAttribute(dlnaThumbnailProfile)
|
||||
findDlnaThumbnailProfile(artMimeType)?.let {
|
||||
attributes[DLNAAttribute.Type.DLNA_ORG_PN] = DLNAProfileAttribute(it)
|
||||
}
|
||||
return DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, artMimeType.toString(), attributes)
|
||||
}
|
||||
|
||||
private val DLNA_THUMBNAIL_TYPES: Collection<DLNAProfiles> = unmodifiableList(listOf(JPEG_TN, PNG_TN))
|
||||
private val MIME_TYPE_TO_DLNA_THUMBNAIL_TYPE: Map<String, DLNAProfiles> =
|
||||
DLNA_THUMBNAIL_TYPES.associateBy { it.contentFormat }
|
||||
|
||||
private fun findDlnaThumbnailProfile(mimeType: MimeType): DLNAProfiles? {
|
||||
return MIME_TYPE_TO_DLNA_THUMBNAIL_TYPE[mimeType.toString()]
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ class ContentNode(
|
|||
private val nodes: MutableList<ContentNode> = ArrayList()
|
||||
private val items: MutableList<ContentItem> = ArrayList()
|
||||
|
||||
|
||||
private val nodeCount: Int get() = nodes.size
|
||||
private val itemCount: Int get() = items.size
|
||||
val nodeAndItemCount: Int get() = nodeCount + itemCount
|
||||
|
||||
fun addItem(item: ContentItem) {
|
||||
items.add(item)
|
||||
}
|
||||
|
@ -35,9 +40,4 @@ class ContentNode(
|
|||
return nodes
|
||||
}
|
||||
|
||||
fun getNodeCount(): Int = nodes.size
|
||||
|
||||
fun getItemCount(): Int = items.size
|
||||
|
||||
fun getNodeAndItemCount(): Int = getNodeCount() + getItemCount()
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ interface AppConfigRepository : JpaRepository<AppConfig, AppConfigId> {
|
|||
|
||||
@Entity
|
||||
@Table(name = "oc_appconfig")
|
||||
class AppConfig(
|
||||
data class AppConfig(
|
||||
@EmbeddedId
|
||||
val id: AppConfigId,
|
||||
@field:Column(name = "configvalue")
|
||||
|
@ -28,7 +28,7 @@ class AppConfig(
|
|||
)
|
||||
|
||||
@Embeddable
|
||||
class AppConfigId(
|
||||
data class AppConfigId(
|
||||
@Column(name = "appid")
|
||||
val appId: String,
|
||||
@Column(name = "configkey")
|
||||
|
|
|
@ -42,7 +42,7 @@ interface FilecacheRepository : JpaRepository<Filecache, String> {
|
|||
|
||||
@Entity
|
||||
@Table(name = "oc_filecache")
|
||||
class Filecache(
|
||||
data class Filecache(
|
||||
@Id
|
||||
@field:Column(name = "fileid")
|
||||
val id: Int,
|
||||
|
@ -62,7 +62,7 @@ class Filecache(
|
|||
|
||||
@Entity
|
||||
@Table(name = "oc_mounts")
|
||||
class Mount(
|
||||
data class Mount(
|
||||
@Id
|
||||
val id: Int,
|
||||
val storageId: Int,
|
||||
|
|
|
@ -13,7 +13,7 @@ interface GroupFolderRepository : JpaRepository<GroupFolder, Int>
|
|||
|
||||
@Entity
|
||||
@Table(name = "oc_group_folders")
|
||||
class GroupFolder(
|
||||
data class GroupFolder(
|
||||
@Id
|
||||
@Column(name = "folder_id")
|
||||
val id: Int,
|
||||
|
|
|
@ -12,7 +12,7 @@ interface MimetypeRepository : JpaRepository<Mimetype, Int>
|
|||
|
||||
@Entity
|
||||
@Table(name = "oc_mimetypes")
|
||||
class Mimetype(
|
||||
data class Mimetype(
|
||||
@Id
|
||||
val id: Int,
|
||||
val mimetype: String
|
||||
|
|
Loading…
Reference in a new issue