Only download video, image and audio files in NIP-94
This commit is contained in:
@@ -40,6 +40,8 @@ object NostrVideoDataSource : NostrDataSource("VideoFeed") {
|
|||||||
|
|
||||||
var job: Job? = null
|
var job: Job? = null
|
||||||
|
|
||||||
|
val SUPPORTED_VIDEO_MIME_TYPES = listOf("image/jpeg", "image/gif", "image/png", "image/webp", "video/mp4", "video/mpeg", "video/webm", "audio/aac", "audio/mpeg", "audio/webm", "audio/wav")
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job =
|
job =
|
||||||
@@ -68,6 +70,7 @@ object NostrVideoDataSource : NostrDataSource("VideoFeed") {
|
|||||||
authors = follows,
|
authors = follows,
|
||||||
kinds = listOf(FileHeaderEvent.KIND, FileStorageHeaderEvent.KIND),
|
kinds = listOf(FileHeaderEvent.KIND, FileStorageHeaderEvent.KIND),
|
||||||
limit = 200,
|
limit = 200,
|
||||||
|
tags = mapOf("m" to SUPPORTED_VIDEO_MIME_TYPES),
|
||||||
since =
|
since =
|
||||||
latestEOSEs.users[account.userProfile()]
|
latestEOSEs.users[account.userProfile()]
|
||||||
?.followList
|
?.followList
|
||||||
@@ -93,6 +96,7 @@ object NostrVideoDataSource : NostrDataSource("VideoFeed") {
|
|||||||
hashToLoad
|
hashToLoad
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
||||||
.flatten(),
|
.flatten(),
|
||||||
|
"m" to SUPPORTED_VIDEO_MIME_TYPES,
|
||||||
),
|
),
|
||||||
limit = 100,
|
limit = 100,
|
||||||
since =
|
since =
|
||||||
@@ -120,6 +124,7 @@ object NostrVideoDataSource : NostrDataSource("VideoFeed") {
|
|||||||
hashToLoad
|
hashToLoad
|
||||||
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
.map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize()) }
|
||||||
.flatten(),
|
.flatten(),
|
||||||
|
"m" to SUPPORTED_VIDEO_MIME_TYPES,
|
||||||
),
|
),
|
||||||
limit = 100,
|
limit = 100,
|
||||||
since =
|
since =
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class VideoFeedFilter(val account: Account) : AdditiveFeedFilter<Note>() {
|
|||||||
): Boolean {
|
): Boolean {
|
||||||
val noteEvent = it.event
|
val noteEvent = it.event
|
||||||
|
|
||||||
return ((noteEvent is FileHeaderEvent && noteEvent.hasUrl()) || noteEvent is FileStorageHeaderEvent) &&
|
return ((noteEvent is FileHeaderEvent && noteEvent.hasUrl() && noteEvent.isImageOrVideo()) || (noteEvent is FileStorageHeaderEvent && noteEvent.isImageOrVideo())) &&
|
||||||
params.match(noteEvent) &&
|
params.match(noteEvent) &&
|
||||||
account.isAcceptable(it)
|
account.isAcceptable(it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ class FileHeaderEvent(
|
|||||||
|
|
||||||
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL }
|
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/")
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KIND = 1063
|
const val KIND = 1063
|
||||||
const val ALT_DESCRIPTION = "Verifiable file url"
|
const val ALT_DESCRIPTION = "Verifiable file url"
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ class FileStorageHeaderEvent(
|
|||||||
|
|
||||||
fun blurhash() = tags.firstOrNull { it.size > 1 && it[0] == BLUR_HASH }?.get(1)
|
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/")
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KIND = 1065
|
const val KIND = 1065
|
||||||
const val ALT_DESCRIPTION = "Descriptors for a binary file"
|
const val ALT_DESCRIPTION = "Descriptors for a binary file"
|
||||||
|
|||||||
Reference in New Issue
Block a user