mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-15 19:27:31 +00:00
Fix a variable name, add logging to upload video request and handle non json errors correctly.
This commit is contained in:
parent
5b10ecbd9d
commit
4b6ab15e26
@ -11,7 +11,7 @@ data class UploadVideoOptions(
|
|||||||
val height: Int = 0,
|
val height: Int = 0,
|
||||||
val isSideCar: Boolean = false,
|
val isSideCar: Boolean = false,
|
||||||
// Stories
|
// Stories
|
||||||
val isForAlbum: Boolean = false,
|
val forAlbum: Boolean = false,
|
||||||
val isDirect: Boolean = false,
|
val isDirect: Boolean = false,
|
||||||
val isDirectVoice: Boolean = false,
|
val isDirectVoice: Boolean = false,
|
||||||
val isForDirectStory: Boolean = false,
|
val isForDirectStory: Boolean = false,
|
||||||
|
@ -30,9 +30,7 @@ private fun createPhotoRuploadParams(options: UploadPhotoOptions): Map<String, S
|
|||||||
).toMap()
|
).toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> {
|
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> = listOfNotNull(
|
||||||
val retryContextString = retryContextString
|
|
||||||
return listOfNotNull(
|
|
||||||
"retry_context" to retryContextString,
|
"retry_context" to retryContextString,
|
||||||
"media_type" to "2",
|
"media_type" to "2",
|
||||||
"xsharing_user_ids" to "[]",
|
"xsharing_user_ids" to "[]",
|
||||||
@ -41,7 +39,7 @@ private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, S
|
|||||||
"upload_media_height" to options.height.toString(),
|
"upload_media_height" to options.height.toString(),
|
||||||
"upload_media_duration_ms" to options.duration.toString(),
|
"upload_media_duration_ms" to options.duration.toString(),
|
||||||
if (options.isSideCar) "is_sidecar" to "1" else null,
|
if (options.isSideCar) "is_sidecar" to "1" else null,
|
||||||
if (options.isForAlbum) "for_album" to "1" else null,
|
if (options.forAlbum) "for_album" to "1" else null,
|
||||||
if (options.isDirect) "direct_v2" to "1" else null,
|
if (options.isDirect) "direct_v2" to "1" else null,
|
||||||
*(if (options.isForDirectStory) arrayOf(
|
*(if (options.isForDirectStory) arrayOf(
|
||||||
"for_direct_story" to "1",
|
"for_direct_story" to "1",
|
||||||
@ -50,7 +48,6 @@ private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, S
|
|||||||
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
|
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
|
||||||
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
|
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
|
||||||
).toMap()
|
).toMap()
|
||||||
}
|
|
||||||
|
|
||||||
val retryContextString: String
|
val retryContextString: String
|
||||||
get() {
|
get() {
|
||||||
|
@ -110,6 +110,7 @@ public final class MediaUploader {
|
|||||||
@NonNull final OnMediaUploadCompleteListener listener) {
|
@NonNull final OnMediaUploadCompleteListener listener) {
|
||||||
try {
|
try {
|
||||||
final OkHttpClient client = new OkHttpClient.Builder()
|
final OkHttpClient client = new OkHttpClient.Builder()
|
||||||
|
// .addInterceptor(new LoggingInterceptor())
|
||||||
.addInterceptor(new AddCookiesInterceptor())
|
.addInterceptor(new AddCookiesInterceptor())
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.followSslRedirects(false)
|
.followSslRedirects(false)
|
||||||
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -70,8 +71,18 @@ public class IgErrorsInterceptor implements Interceptor {
|
|||||||
try {
|
try {
|
||||||
final String bodyString = body.string();
|
final String bodyString = body.string();
|
||||||
Log.d(TAG, "checkError: " + bodyString);
|
Log.d(TAG, "checkError: " + bodyString);
|
||||||
final JSONObject jsonObject = new JSONObject(bodyString);
|
JSONObject jsonObject = null;
|
||||||
String message = jsonObject.optString("message");
|
try {
|
||||||
|
jsonObject = new JSONObject(bodyString);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, "checkError: ", e);
|
||||||
|
}
|
||||||
|
String message;
|
||||||
|
if (jsonObject != null) {
|
||||||
|
message = jsonObject.optString("message");
|
||||||
|
} else {
|
||||||
|
message = bodyString;
|
||||||
|
}
|
||||||
if (!TextUtils.isEmpty(message)) {
|
if (!TextUtils.isEmpty(message)) {
|
||||||
message = message.toLowerCase();
|
message = message.toLowerCase();
|
||||||
switch (message) {
|
switch (message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user