data classes in repositories and content classes

This commit is contained in:
xis 2023-10-13 16:21:24 +02:00
parent 9d4ac85a81
commit f57e5b304e
9 changed files with 33 additions and 37 deletions

View file

@ -15,6 +15,7 @@ import org.jupnp.UpnpServiceConfiguration
import org.jupnp.UpnpServiceImpl import org.jupnp.UpnpServiceImpl
import org.jupnp.model.message.StreamRequestMessage import org.jupnp.model.message.StreamRequestMessage
import org.jupnp.model.message.StreamResponseMessage import org.jupnp.model.message.StreamResponseMessage
import org.jupnp.model.message.UpnpResponse
import org.jupnp.model.meta.LocalDevice import org.jupnp.model.meta.LocalDevice
import org.jupnp.protocol.ProtocolFactory import org.jupnp.protocol.ProtocolFactory
import org.jupnp.protocol.ProtocolFactoryImpl import org.jupnp.protocol.ProtocolFactoryImpl
@ -59,6 +60,9 @@ class DlnaService(
return with(upnpService.protocolFactory.createReceivingSync(requestMsg)) { return with(upnpService.protocolFactory.createReceivingSync(requestMsg)) {
run() run()
outputMessage outputMessage
?: StreamResponseMessage(UpnpResponse.Status.NOT_FOUND).also {
logger.warn { "Could not get response for ${requestMsg.operation.method} ${requestMsg}" }
}
}.also { }.also {
logger.debug { "Response: ${it.operation.statusCode} ${it.body}" } logger.debug { "Response: ${it.operation.statusCode} ${it.body}" }
} }

View file

@ -3,22 +3,22 @@ package net.schowek.nextclouddlna.controller
import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletRequest
import mu.KLogging import mu.KLogging
import net.schowek.nextclouddlna.DlnaService import net.schowek.nextclouddlna.DlnaService
import net.schowek.nextclouddlna.dlna.media.MediaServer
import net.schowek.nextclouddlna.dlna.StreamRequestMapper import net.schowek.nextclouddlna.dlna.StreamRequestMapper
import net.schowek.nextclouddlna.dlna.media.MediaServer
import org.springframework.core.io.InputStreamResource import org.springframework.core.io.InputStreamResource
import org.springframework.core.io.Resource import org.springframework.core.io.Resource
import org.springframework.http.HttpHeaders import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatusCode import org.springframework.http.HttpStatusCode
import org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE import org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod.* import org.springframework.web.bind.annotation.RequestMethod.*
import org.springframework.web.bind.annotation.ResponseBody import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
@Controller @RestController
class UpnpController( class UpnpController(
private val streamRequestMapper: StreamRequestMapper, private val streamRequestMapper: StreamRequestMapper,
private val dlnaService: DlnaService private val dlnaService: DlnaService

View file

@ -28,12 +28,10 @@ class StreamRequestMapper {
private fun createHeaders(request: HttpServletRequest): UpnpHeaders { private fun createHeaders(request: HttpServletRequest): UpnpHeaders {
val headers = mutableMapOf<String, List<String>>() val headers = mutableMapOf<String, List<String>>()
with(request.headerNames) { request.headerNames?.let {
if (this != null) { while (it.hasMoreElements()) {
while (hasMoreElements()) { with(it.nextElement()) {
with(nextElement()) { headers[this] = listOf(request.getHeader(this))
headers[this] = listOf(request.getHeader(this))
}
} }
} }
} }
@ -43,17 +41,13 @@ class StreamRequestMapper {
inner class MyHttpServerConnection( inner class MyHttpServerConnection(
private val request: HttpServletRequest private val request: HttpServletRequest
) : Connection { ) : Connection {
override fun isOpen(): Boolean { override fun isOpen() = true
return true
}
override fun getRemoteAddress(): InetAddress? { override fun getRemoteAddress(): InetAddress? =
return if (request.remoteAddr != null) InetAddress.getByName(request.remoteAddr) else null request.remoteAddr?.let { InetAddress.getByName(request.remoteAddr) }
}
override fun getLocalAddress(): InetAddress? { override fun getLocalAddress(): InetAddress? =
return if (request.localAddr != null) InetAddress.getByName(request.localAddr) else null request.localAddr?.let { InetAddress.getByName(request.localAddr) }
}
} }
companion object : KLogging() companion object : KLogging()

View file

@ -39,7 +39,7 @@ class NodeConverter(
c.setId("${n.id}") c.setId("${n.id}")
c.setParentID("${n.parentId}") c.setParentID("${n.parentId}")
c.setTitle(n.name) c.setTitle(n.name)
c.childCount = n.getNodeAndItemCount() c.childCount = n.nodeAndItemCount
c.setRestricted(true) c.setRestricted(true)
c.setWriteStatus(NOT_WRITABLE) c.setWriteStatus(NOT_WRITABLE)
c.isSearchable = true c.isSearchable = true
@ -67,21 +67,19 @@ class NodeConverter(
} }
companion object { 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 { private fun makeProtocolInfo(artMimeType: MimeType): DLNAProtocolInfo {
val attributes = EnumMap<DLNAAttribute.Type, DLNAAttribute<*>>( val attributes = EnumMap<DLNAAttribute.Type, DLNAAttribute<*>>(
DLNAAttribute.Type::class.java DLNAAttribute.Type::class.java
) )
val dlnaThumbnailProfile = findDlnaThumbnailProfile(artMimeType) findDlnaThumbnailProfile(artMimeType)?.let {
if (dlnaThumbnailProfile != null) { attributes[DLNAAttribute.Type.DLNA_ORG_PN] = DLNAProfileAttribute(it)
attributes[DLNAAttribute.Type.DLNA_ORG_PN] = DLNAProfileAttribute(dlnaThumbnailProfile)
} }
return DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, artMimeType.toString(), attributes) 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? { private fun findDlnaThumbnailProfile(mimeType: MimeType): DLNAProfiles? {
return MIME_TYPE_TO_DLNA_THUMBNAIL_TYPE[mimeType.toString()] return MIME_TYPE_TO_DLNA_THUMBNAIL_TYPE[mimeType.toString()]
} }

View file

@ -19,6 +19,11 @@ class ContentNode(
private val nodes: MutableList<ContentNode> = ArrayList() private val nodes: MutableList<ContentNode> = ArrayList()
private val items: MutableList<ContentItem> = 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) { fun addItem(item: ContentItem) {
items.add(item) items.add(item)
} }
@ -35,9 +40,4 @@ class ContentNode(
return nodes return nodes
} }
fun getNodeCount(): Int = nodes.size
fun getItemCount(): Int = items.size
fun getNodeAndItemCount(): Int = getNodeCount() + getItemCount()
} }

View file

@ -20,7 +20,7 @@ interface AppConfigRepository : JpaRepository<AppConfig, AppConfigId> {
@Entity @Entity
@Table(name = "oc_appconfig") @Table(name = "oc_appconfig")
class AppConfig( data class AppConfig(
@EmbeddedId @EmbeddedId
val id: AppConfigId, val id: AppConfigId,
@field:Column(name = "configvalue") @field:Column(name = "configvalue")
@ -28,7 +28,7 @@ class AppConfig(
) )
@Embeddable @Embeddable
class AppConfigId( data class AppConfigId(
@Column(name = "appid") @Column(name = "appid")
val appId: String, val appId: String,
@Column(name = "configkey") @Column(name = "configkey")

View file

@ -42,7 +42,7 @@ interface FilecacheRepository : JpaRepository<Filecache, String> {
@Entity @Entity
@Table(name = "oc_filecache") @Table(name = "oc_filecache")
class Filecache( data class Filecache(
@Id @Id
@field:Column(name = "fileid") @field:Column(name = "fileid")
val id: Int, val id: Int,
@ -62,7 +62,7 @@ class Filecache(
@Entity @Entity
@Table(name = "oc_mounts") @Table(name = "oc_mounts")
class Mount( data class Mount(
@Id @Id
val id: Int, val id: Int,
val storageId: Int, val storageId: Int,

View file

@ -13,7 +13,7 @@ interface GroupFolderRepository : JpaRepository<GroupFolder, Int>
@Entity @Entity
@Table(name = "oc_group_folders") @Table(name = "oc_group_folders")
class GroupFolder( data class GroupFolder(
@Id @Id
@Column(name = "folder_id") @Column(name = "folder_id")
val id: Int, val id: Int,

View file

@ -12,7 +12,7 @@ interface MimetypeRepository : JpaRepository<Mimetype, Int>
@Entity @Entity
@Table(name = "oc_mimetypes") @Table(name = "oc_mimetypes")
class Mimetype( data class Mimetype(
@Id @Id
val id: Int, val id: Int,
val mimetype: String val mimetype: String