added hoster nostrfiles.dev
This commit is contained in:
@@ -43,6 +43,8 @@ object ImageUploader {
|
|||||||
NostrImgServer()
|
NostrImgServer()
|
||||||
} else if (server == ServersAvailable.NOSTR_BUILD) {
|
} else if (server == ServersAvailable.NOSTR_BUILD) {
|
||||||
NostrBuildServer()
|
NostrBuildServer()
|
||||||
|
} else if (server == ServersAvailable.NOSTRFILES_DEV) {
|
||||||
|
NostrfilesDevServer()
|
||||||
} else {
|
} else {
|
||||||
ImgurServer()
|
ImgurServer()
|
||||||
}
|
}
|
||||||
@@ -62,7 +64,7 @@ object ImageUploader {
|
|||||||
onSuccess: (String, String?) -> Unit,
|
onSuccess: (String, String?) -> Unit,
|
||||||
onError: (Throwable) -> Unit
|
onError: (Throwable) -> Unit
|
||||||
) {
|
) {
|
||||||
val category = contentType?.toMediaType()?.toString()?.split("/")?.get(0) ?: "image"
|
var category = contentType?.toMediaType()?.toString()?.split("/")?.get(0) ?: "image"
|
||||||
|
|
||||||
val fileName = randomChars()
|
val fileName = randomChars()
|
||||||
val extension = contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
val extension = contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
||||||
@@ -71,12 +73,17 @@ object ImageUploader {
|
|||||||
val requestBody: RequestBody
|
val requestBody: RequestBody
|
||||||
val requestBuilder = Request.Builder()
|
val requestBuilder = Request.Builder()
|
||||||
|
|
||||||
if (serverType == ServersAvailable.NOSTR_BUILD) {
|
if (serverType == ServersAvailable.NOSTR_BUILD || serverType == ServersAvailable.NOSTRFILES_DEV) {
|
||||||
requestBuilder.addHeader("Content-Type", "multipart/form-data")
|
if (serverType == ServersAvailable.NOSTR_BUILD) {
|
||||||
|
requestBuilder.addHeader("Content-Type", "multipart/form-data")
|
||||||
|
category = "fileToUpload"
|
||||||
|
} else if (serverType == ServersAvailable.NOSTRFILES_DEV) {
|
||||||
|
category = "file"
|
||||||
|
}
|
||||||
requestBody = MultipartBody.Builder()
|
requestBody = MultipartBody.Builder()
|
||||||
.setType(MultipartBody.FORM)
|
.setType(MultipartBody.FORM)
|
||||||
.addFormDataPart(
|
.addFormDataPart(
|
||||||
"fileToUpload",
|
category,
|
||||||
"$fileName.$extension",
|
"$fileName.$extension",
|
||||||
file.asRequestBody(contentType?.toMediaType())
|
file.asRequestBody(contentType?.toMediaType())
|
||||||
|
|
||||||
@@ -212,3 +219,14 @@ class NostrBuildServer : FileServer() {
|
|||||||
|
|
||||||
override fun clientID() = null
|
override fun clientID() = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NostrfilesDevServer : FileServer() {
|
||||||
|
override fun postUrl(contentType: String?) = "https://nostrfiles.dev/upload_image"
|
||||||
|
override fun parseUrlFromSucess(body: String): String? {
|
||||||
|
val tree = jacksonObjectMapper().readTree(body)
|
||||||
|
val url = tree?.get("url")?.asText()
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clientID() = null
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ open class NewMediaModel : ViewModel() {
|
|||||||
selectedServer = ServersAvailable.NOSTRIMG_NIP_94
|
selectedServer = ServersAvailable.NOSTRIMG_NIP_94
|
||||||
} else if (selectedServer == ServersAvailable.NOSTR_BUILD) {
|
} else if (selectedServer == ServersAvailable.NOSTR_BUILD) {
|
||||||
selectedServer = ServersAvailable.NOSTR_BUILD_NIP_94
|
selectedServer = ServersAvailable.NOSTR_BUILD_NIP_94
|
||||||
|
} else if (selectedServer == ServersAvailable.NOSTRFILES_DEV) {
|
||||||
|
selectedServer = ServersAvailable.NOSTRFILES_DEV_NIP_94
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,14 @@ fun NewMediaView(uri: Uri, onClose: () -> Unit, postViewModel: NewMediaModel, ac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isNIP94Server(selectedServer: ServersAvailable?): Boolean {
|
||||||
|
return selectedServer == ServersAvailable.NOSTRIMG_NIP_94 ||
|
||||||
|
selectedServer == ServersAvailable.IMGUR_NIP_94 ||
|
||||||
|
selectedServer == ServersAvailable.NOSTR_BUILD_NIP_94 ||
|
||||||
|
selectedServer == ServersAvailable.NOSTRFILES_DEV_NIP_94
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
|
fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -191,9 +199,7 @@ fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postViewModel.selectedServer == ServersAvailable.NOSTRIMG_NIP_94 ||
|
if (isNIP94Server(postViewModel.selectedServer) ||
|
||||||
postViewModel.selectedServer == ServersAvailable.IMGUR_NIP_94 ||
|
|
||||||
postViewModel.selectedServer == ServersAvailable.NOSTR_BUILD_NIP_94 ||
|
|
||||||
postViewModel.selectedServer == ServersAvailable.NIP95
|
postViewModel.selectedServer == ServersAvailable.NIP95
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -588,9 +588,11 @@ enum class ServersAvailable {
|
|||||||
IMGUR,
|
IMGUR,
|
||||||
NOSTR_BUILD,
|
NOSTR_BUILD,
|
||||||
NOSTRIMG,
|
NOSTRIMG,
|
||||||
|
NOSTRFILES_DEV,
|
||||||
IMGUR_NIP_94,
|
IMGUR_NIP_94,
|
||||||
NOSTRIMG_NIP_94,
|
NOSTRIMG_NIP_94,
|
||||||
NOSTR_BUILD_NIP_94,
|
NOSTR_BUILD_NIP_94,
|
||||||
|
NOSTRFILES_DEV_NIP_94,
|
||||||
NIP95
|
NIP95
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,9 +614,11 @@ fun ImageVideoDescription(
|
|||||||
Triple(ServersAvailable.IMGUR, stringResource(id = R.string.upload_server_imgur), stringResource(id = R.string.upload_server_imgur_explainer)),
|
Triple(ServersAvailable.IMGUR, stringResource(id = R.string.upload_server_imgur), stringResource(id = R.string.upload_server_imgur_explainer)),
|
||||||
Triple(ServersAvailable.NOSTRIMG, stringResource(id = R.string.upload_server_nostrimg), stringResource(id = R.string.upload_server_nostrimg_explainer)),
|
Triple(ServersAvailable.NOSTRIMG, stringResource(id = R.string.upload_server_nostrimg), stringResource(id = R.string.upload_server_nostrimg_explainer)),
|
||||||
Triple(ServersAvailable.NOSTR_BUILD, stringResource(id = R.string.upload_server_nostrbuild), stringResource(id = R.string.upload_server_nostrbuild_explainer)),
|
Triple(ServersAvailable.NOSTR_BUILD, stringResource(id = R.string.upload_server_nostrbuild), stringResource(id = R.string.upload_server_nostrbuild_explainer)),
|
||||||
|
Triple(ServersAvailable.NOSTRFILES_DEV, stringResource(id = R.string.upload_server_nostrfilesdev), stringResource(id = R.string.upload_server_nostrfilesdev_explainer)),
|
||||||
Triple(ServersAvailable.IMGUR_NIP_94, stringResource(id = R.string.upload_server_imgur_nip94), stringResource(id = R.string.upload_server_imgur_nip94_explainer)),
|
Triple(ServersAvailable.IMGUR_NIP_94, stringResource(id = R.string.upload_server_imgur_nip94), stringResource(id = R.string.upload_server_imgur_nip94_explainer)),
|
||||||
Triple(ServersAvailable.NOSTRIMG_NIP_94, stringResource(id = R.string.upload_server_nostrimg_nip94), stringResource(id = R.string.upload_server_nostrimg_nip94_explainer)),
|
Triple(ServersAvailable.NOSTRIMG_NIP_94, stringResource(id = R.string.upload_server_nostrimg_nip94), stringResource(id = R.string.upload_server_nostrimg_nip94_explainer)),
|
||||||
Triple(ServersAvailable.NOSTR_BUILD_NIP_94, stringResource(id = R.string.upload_server_nostrbuild_nip94), stringResource(id = R.string.upload_server_nostrbuild_nip94_explainer)),
|
Triple(ServersAvailable.NOSTR_BUILD_NIP_94, stringResource(id = R.string.upload_server_nostrbuild_nip94), stringResource(id = R.string.upload_server_nostrbuild_nip94_explainer)),
|
||||||
|
Triple(ServersAvailable.NOSTRFILES_DEV_NIP_94, stringResource(id = R.string.upload_server_nostrfilesdev_nip94), stringResource(id = R.string.upload_server_nostrfilesdev_nip94_explainer)),
|
||||||
Triple(ServersAvailable.NIP95, stringResource(id = R.string.upload_server_relays_nip95), stringResource(id = R.string.upload_server_relays_nip95_explainer))
|
Triple(ServersAvailable.NIP95, stringResource(id = R.string.upload_server_relays_nip95), stringResource(id = R.string.upload_server_relays_nip95_explainer))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -742,9 +746,7 @@ fun ImageVideoDescription(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedServer == ServersAvailable.NOSTRIMG_NIP_94 ||
|
if (isNIP94Server(selectedServer) ||
|
||||||
selectedServer == ServersAvailable.IMGUR_NIP_94 ||
|
|
||||||
selectedServer == ServersAvailable.NOSTR_BUILD_NIP_94 ||
|
|
||||||
selectedServer == ServersAvailable.NIP95
|
selectedServer == ServersAvailable.NIP95
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
context = context,
|
context = context,
|
||||||
contentResolver = contentResolver,
|
contentResolver = contentResolver,
|
||||||
onSuccess = { imageUrl, mimeType ->
|
onSuccess = { imageUrl, mimeType ->
|
||||||
if (server == ServersAvailable.IMGUR_NIP_94 || server == ServersAvailable.NOSTRIMG_NIP_94 || server == ServersAvailable.NOSTR_BUILD_NIP_94) {
|
if (isNIP94Server(server)) {
|
||||||
createNIP94Record(imageUrl, mimeType, description)
|
createNIP94Record(imageUrl, mimeType, description)
|
||||||
} else {
|
} else {
|
||||||
isUploadingImage = false
|
isUploadingImage = false
|
||||||
|
|||||||
@@ -336,6 +336,10 @@
|
|||||||
<string name="upload_server_nostrbuild">nostr.build - trusted</string>
|
<string name="upload_server_nostrbuild">nostr.build - trusted</string>
|
||||||
<string name="upload_server_nostrbuild_explainer">Nostr.build can modify the file</string>
|
<string name="upload_server_nostrbuild_explainer">Nostr.build can modify the file</string>
|
||||||
|
|
||||||
|
<string name="upload_server_nostrfilesdev">nostrfiles.dev - trusted</string>
|
||||||
|
<string name="upload_server_nostrfilesdev_explainer">Nostrfiles.dev can modify the file</string>
|
||||||
|
|
||||||
|
|
||||||
<string name="upload_server_imgur_nip94">Verifiable Imgur (NIP-94)</string>
|
<string name="upload_server_imgur_nip94">Verifiable Imgur (NIP-94)</string>
|
||||||
<string name="upload_server_imgur_nip94_explainer">Checks if Imgur modified the file. New NIP: other clients might not see it</string>
|
<string name="upload_server_imgur_nip94_explainer">Checks if Imgur modified the file. New NIP: other clients might not see it</string>
|
||||||
|
|
||||||
@@ -345,6 +349,10 @@
|
|||||||
<string name="upload_server_nostrbuild_nip94">Verifiable Nostr.build (NIP-94)</string>
|
<string name="upload_server_nostrbuild_nip94">Verifiable Nostr.build (NIP-94)</string>
|
||||||
<string name="upload_server_nostrbuild_nip94_explainer">Checks if Nostr.build modified the file. New NIP: other clients might not see it</string>
|
<string name="upload_server_nostrbuild_nip94_explainer">Checks if Nostr.build modified the file. New NIP: other clients might not see it</string>
|
||||||
|
|
||||||
|
<string name="upload_server_nostrfilesdev_nip94">Verifiable Nostrfiles.dev (NIP-94)</string>
|
||||||
|
<string name="upload_server_nostrfilesdev_nip94_explainer">Checks if Nostrfiles.dev modified the file. New NIP: other clients might not see it</string>
|
||||||
|
|
||||||
|
|
||||||
<string name="upload_server_relays_nip95">Your relays (NIP-95)</string>
|
<string name="upload_server_relays_nip95">Your relays (NIP-95)</string>
|
||||||
<string name="upload_server_relays_nip95_explainer">Files are hosted by your relays. New NIP: check if they support</string>
|
<string name="upload_server_relays_nip95_explainer">Files are hosted by your relays. New NIP: check if they support</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user