Skip to content

Commit

Permalink
GH-100 Consider optionality of some File fields
Browse files Browse the repository at this point in the history
In particular, there may be files without type ("FileType")
  • Loading branch information
Radiokot committed Oct 31, 2023
1 parent 7b6d73b commit 0a189fe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Not loading gallery content if there is a file without type (`FileType`)

## [1.20.3] - 2023-10-27

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ua.com.radiokot.photoprism.api.photos.model
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty

/**
* [photo_results.go](https://github.com/photoprism/photoprism/blob/47e9b20929e44bd63d32cb50a393371d24bcaff8/internal/search/photos_results.go#L15)
*/
data class PhotoPrismMergedPhoto
@JsonCreator
constructor(
Expand All @@ -28,11 +31,11 @@ constructor(
val mainFile: File?
// https://github.com/photoprism/photoprism/blob/2f9792e5411f6bb47a84b638dfc42d51b7790853/frontend/src/model/photo.js#L520
get() = files.find {
it.primary
it.primary == true
} ?: files.find {
it.fileType == "jpg" || it.fileType == "png"
} ?: files.find {
!it.sidecar
it.sidecar == false
}

val videoFile: File?
Expand All @@ -42,7 +45,7 @@ constructor(
} ?: files.find {
it.fileType == "mp4"
} ?: files.find {
it.video
it.video == true
} ?: animatedFile

private val animatedFile: File?
Expand All @@ -51,7 +54,11 @@ constructor(
it.fileType == "gif" || it.duration != null || it.frames != null
}

/**
* [file.go](https://github.com/photoprism/photoprism/blob/47e9b20929e44bd63d32cb50a393371d24bcaff8/internal/entity/file.go#L40)
*/
class File(
// TODO Clarify whether the hash is actually optional.
@JsonProperty("Hash")
val hash: String,
@JsonProperty("UID")
Expand All @@ -61,24 +68,24 @@ constructor(
@JsonProperty("Name")
val name: String,
@JsonProperty("Mime")
val mime: String,
val mime: String?,
@JsonProperty("FileType")
val fileType: String,
val fileType: String?,
@JsonProperty("Size")
val size: Long,
val size: Long?,
@JsonProperty("Duration")
val duration: Long?,
@JsonProperty("Frames")
val frames: Int?,
@JsonProperty("Primary")
val primary: Boolean,
val primary: Boolean?,
@JsonProperty("Root")
val root: String,
val root: String?,
@JsonProperty("Video")
val video: Boolean,
val video: Boolean?,
@JsonProperty("Codec")
val codec: String?,
@JsonProperty("Sidecar")
val sidecar: Boolean,
val sidecar: Boolean?,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class GalleryMedia(
*/
val mediaUid: String,
val mimeType: String,
val sizeBytes: Long,
val sizeBytes: Long?,
/**
* Direct URL to the small square static thumbnail.
*/
Expand All @@ -383,7 +383,7 @@ class GalleryMedia(
name = source.name,
uid = source.uid,
mediaUid = source.photoUid,
mimeType = source.mime,
mimeType = source.mime ?: "application/octet-stream",
sizeBytes = source.size,
smallThumbnailUrl = thumbnailUrlFactory.getSmallThumbnailUrl(source.hash),
downloadUrl = downloadUrlFactory.getDownloadUrl(source.hash),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ua.com.radiokot.photoprism.features.gallery.data.model.GalleryMedia
class MediaFileListItem(
val name: String,
val thumbnailUrl: String,
val size: String,
val size: String?,
val mimeType: String,
val source: GalleryMedia.File?,
) : AbstractItem<MediaFileListItem.ViewHolder>(), Parcelable {
Expand All @@ -33,7 +33,7 @@ class MediaFileListItem(
name = source.name,
thumbnailUrl = source.smallThumbnailUrl,
mimeType = source.mimeType,
size = Formatter.formatFileSize(context, source.sizeBytes),
size = source.sizeBytes?.let { Formatter.formatFileSize(context, it) },
source = source,
)

Expand Down

0 comments on commit 0a189fe

Please sign in to comment.