mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +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,27 +30,24 @@ 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
|
"retry_context" to retryContextString,
|
||||||
return listOfNotNull(
|
"media_type" to "2",
|
||||||
"retry_context" to retryContextString,
|
"xsharing_user_ids" to "[]",
|
||||||
"media_type" to "2",
|
"upload_id" to options.uploadId,
|
||||||
"xsharing_user_ids" to "[]",
|
"upload_media_width" to options.width.toString(),
|
||||||
"upload_id" to options.uploadId,
|
"upload_media_height" to options.height.toString(),
|
||||||
"upload_media_width" to options.width.toString(),
|
"upload_media_duration_ms" to options.duration.toString(),
|
||||||
"upload_media_height" to options.height.toString(),
|
if (options.isSideCar) "is_sidecar" to "1" else null,
|
||||||
"upload_media_duration_ms" to options.duration.toString(),
|
if (options.forAlbum) "for_album" to "1" else null,
|
||||||
if (options.isSideCar) "is_sidecar" to "1" else null,
|
if (options.isDirect) "direct_v2" to "1" else null,
|
||||||
if (options.isForAlbum) "for_album" to "1" else null,
|
*(if (options.isForDirectStory) arrayOf(
|
||||||
if (options.isDirect) "direct_v2" to "1" else null,
|
"for_direct_story" to "1",
|
||||||
*(if (options.isForDirectStory) arrayOf(
|
"content_tags" to ""
|
||||||
"for_direct_story" to "1",
|
) else emptyArray()),
|
||||||
"content_tags" to ""
|
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
|
||||||
) else emptyArray()),
|
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
|
||||||
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
|
).toMap()
|
||||||
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
|
|
||||||
).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