Adds flare.pub videos to the media tab on Amethyst

This commit is contained in:
Vitor Pamplona
2024-06-04 17:12:14 -04:00
parent 1bf8165641
commit f1e516662c
10 changed files with 124 additions and 24 deletions

View File

@@ -58,11 +58,7 @@ class FileHeaderEvent(
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL }
fun isImageOrVideo(): Boolean {
val mimeType = mimeType() ?: return false
return mimeType.startsWith("image/") || mimeType.startsWith("video/")
}
fun isOneOf(mimeTypes: Set<String>) = tags.any { it.size > 1 && it[0] == MIME_TYPE && mimeTypes.contains(it[1]) }
companion object {
const val KIND = 1063

View File

@@ -54,11 +54,7 @@ class FileStorageHeaderEvent(
fun blurhash() = tags.firstOrNull { it.size > 1 && it[0] == BLUR_HASH }?.get(1)
fun isImageOrVideo(): Boolean {
val mimeType = mimeType() ?: return false
return mimeType.startsWith("image/") || mimeType.startsWith("video/")
}
fun isOneOf(mimeTypes: Set<String>) = tags.any { it.size > 1 && it[0] == FileHeaderEvent.MIME_TYPE && mimeTypes.contains(it[1]) }
companion object {
const val KIND = 1065

View File

@@ -65,6 +65,8 @@ abstract class VideoEvent(
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL }
fun isOneOf(mimeTypes: Set<String>) = tags.any { it.size > 1 && it[0] == FileHeaderEvent.MIME_TYPE && mimeTypes.contains(it[1]) }
companion object {
private const val URL = "url"
private const val ENCRYPTION_KEY = "aes-256-gcm"
@@ -84,7 +86,7 @@ abstract class VideoEvent(
private const val IMAGE = "image"
private const val THUMB = "thumb"
fun create(
fun <T : VideoEvent> create(
kind: Int,
url: String,
magnetUri: String? = null,
@@ -102,7 +104,7 @@ abstract class VideoEvent(
altDescription: String,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileHeaderEvent) -> Unit,
onReady: (T) -> Unit,
) {
val tags =
listOfNotNull(
@@ -128,7 +130,7 @@ abstract class VideoEvent(
)
val content = alt ?: ""
signer.sign(createdAt, kind, tags.toTypedArray(), content, onReady)
signer.sign<T>(createdAt, kind, tags.toTypedArray(), content, onReady)
}
}
}

View File

@@ -54,7 +54,7 @@ class VideoHorizontalEvent(
sensitiveContent: Boolean? = null,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileHeaderEvent) -> Unit,
onReady: (VideoHorizontalEvent) -> Unit,
) {
create(
KIND,

View File

@@ -54,7 +54,7 @@ class VideoVerticalEvent(
sensitiveContent: Boolean? = null,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileHeaderEvent) -> Unit,
onReady: (VideoVerticalEvent) -> Unit,
) {
create(
KIND,