Misskeyの画像アップロード
This commit is contained in:
parent
c452b68259
commit
80e6242f58
|
@ -1600,9 +1600,18 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val multipart_body = MultipartBody.Builder()
|
|
||||||
.setType(MultipartBody.FORM)
|
|
||||||
.addFormDataPart(
|
if(account.isMisskey){
|
||||||
|
val multipart_builder = MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
|
||||||
|
val apiKey = account.token_info?.parseString(TootApiClient.KEY_API_KEY_MISSKEY)
|
||||||
|
if( apiKey?.isNotEmpty()== true){
|
||||||
|
multipart_builder.addFormDataPart("i",apiKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
multipart_builder.addFormDataPart(
|
||||||
"file", getDocumentName(uri), object : RequestBody() {
|
"file", getDocumentName(uri), object : RequestBody() {
|
||||||
override fun contentType() : MediaType? {
|
override fun contentType() : MediaType? {
|
||||||
return MediaType.parse(opener.mimeType)
|
return MediaType.parse(opener.mimeType)
|
||||||
|
@ -1626,26 +1635,72 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
|
val request_builder = Request.Builder().post(multipart_builder.build())
|
||||||
val request_builder = Request.Builder()
|
|
||||||
.post(multipart_body)
|
val result = client.request("/api/drive/files/create", request_builder)
|
||||||
|
|
||||||
val result = client.request("/api/v1/media", request_builder)
|
opener.deleteTempFile()
|
||||||
|
onUploadEnd()
|
||||||
opener.deleteTempFile()
|
|
||||||
onUploadEnd()
|
val jsonObject = result?.jsonObject
|
||||||
|
if(jsonObject != null) {
|
||||||
val jsonObject = result?.jsonObject
|
val a = parseItem(::TootAttachment, ServiceType.MISSKEY, jsonObject)
|
||||||
if(jsonObject != null) {
|
if(a == null) {
|
||||||
val a = parseItem(::TootAttachment, ServiceType.MASTODON, jsonObject)
|
result.error = "TootAttachment.parse failed"
|
||||||
if(a == null) {
|
} else {
|
||||||
result.error = "TootAttachment.parse failed"
|
pa.attachment = a
|
||||||
} else {
|
}
|
||||||
pa.attachment = a
|
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
|
}else{
|
||||||
|
val multipart_body = MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.addFormDataPart(
|
||||||
|
"file", getDocumentName(uri), object : RequestBody() {
|
||||||
|
override fun contentType() : MediaType? {
|
||||||
|
return MediaType.parse(opener.mimeType)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun contentLength() : Long {
|
||||||
|
return content_length
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun writeTo(sink : BufferedSink) {
|
||||||
|
opener.open().use { inData ->
|
||||||
|
val tmp = ByteArray(4096)
|
||||||
|
while(true) {
|
||||||
|
val r = inData.read(tmp, 0, tmp.size)
|
||||||
|
if(r <= 0) break
|
||||||
|
sink.write(tmp, 0, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val request_builder = Request.Builder()
|
||||||
|
.post(multipart_body)
|
||||||
|
|
||||||
|
val result = client.request("/api/v1/media", request_builder)
|
||||||
|
|
||||||
|
opener.deleteTempFile()
|
||||||
|
onUploadEnd()
|
||||||
|
|
||||||
|
val jsonObject = result?.jsonObject
|
||||||
|
if(jsonObject != null) {
|
||||||
|
val a = parseItem(::TootAttachment, ServiceType.MASTODON, jsonObject)
|
||||||
|
if(a == null) {
|
||||||
|
result.error = "TootAttachment.parse failed"
|
||||||
|
} else {
|
||||||
|
pa.attachment = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
|
||||||
} catch(ex : Throwable) {
|
} catch(ex : Throwable) {
|
||||||
return TootApiResult(ex.withCaption("read failed."))
|
return TootApiResult(ex.withCaption("read failed."))
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
//package jp.juggler.subwaytooter.api.entity
|
||||||
|
//
|
||||||
|
//enum class MisskeyReaction(val name:String,val drawableId:Int){
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Like("like"),
|
||||||
|
// Love("love"),
|
||||||
|
// Laugh("laugh"),
|
||||||
|
// Hmm("hmm"),
|
||||||
|
// Surprise("surprise"),
|
||||||
|
// Congrats("congrats"),
|
||||||
|
// Angry("angry"),
|
||||||
|
// Confused("confused"),
|
||||||
|
// Rip("rip"),
|
||||||
|
// Pudding("pudding") ;
|
||||||
|
//
|
||||||
|
// companion object {
|
||||||
|
// val map: HashMap<String,MisskeyReaction> by lazy {
|
||||||
|
// HashMap<String,MisskeyReaction>().apply {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -335,9 +335,6 @@ class PostHelper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Misskeyの場合、NSFWするにはアップロード済みの画像を drive/files/update で更新する
|
|
||||||
// json.put("sensitive", bNSFW)
|
|
||||||
|
|
||||||
if(spoiler_text?.isNotEmpty() == true ) {
|
if(spoiler_text?.isNotEmpty() == true ) {
|
||||||
json.put(
|
json.put(
|
||||||
"cw",
|
"cw",
|
||||||
|
@ -364,6 +361,15 @@ class PostHelper(
|
||||||
val a = pa.attachment ?: continue
|
val a = pa.attachment ?: continue
|
||||||
// Misskeyは画像の再利用に問題がないので redraftとバージョンのチェックは行わない
|
// Misskeyは画像の再利用に問題がないので redraftとバージョンのチェックは行わない
|
||||||
array.put(a.id.toString())
|
array.put(a.id.toString())
|
||||||
|
|
||||||
|
// Misskeyの場合、NSFWするにはアップロード済みの画像を drive/files/update で更新する
|
||||||
|
if( bNSFW){
|
||||||
|
val params = account.putMisskeyApiToken(JSONObject())
|
||||||
|
.put("fileId",a.id.toString())
|
||||||
|
.put("isSensitive",true)
|
||||||
|
val r = client.request("/api/drive/files/update",params.toPostRequestBuilder())
|
||||||
|
if(r==null|| r.error!=null ) return r
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( array.length() > 0) json.put("mediaIds", array)
|
if( array.length() > 0) json.put("mediaIds", array)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue