1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

Fix a variable name, add logging to upload video request and handle non json errors correctly.

This commit is contained in:
Ammar Githam 2021-05-24 22:49:32 +09:00
parent 5b10ecbd9d
commit 4b6ab15e26
4 changed files with 33 additions and 24 deletions

View File

@ -11,7 +11,7 @@ data class UploadVideoOptions(
val height: Int = 0,
val isSideCar: Boolean = false,
// Stories
val isForAlbum: Boolean = false,
val forAlbum: Boolean = false,
val isDirect: Boolean = false,
val isDirectVoice: Boolean = false,
val isForDirectStory: Boolean = false,

View File

@ -30,27 +30,24 @@ private fun createPhotoRuploadParams(options: UploadPhotoOptions): Map<String, S
).toMap()
}
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> {
val retryContextString = retryContextString
return listOfNotNull(
"retry_context" to retryContextString,
"media_type" to "2",
"xsharing_user_ids" to "[]",
"upload_id" to options.uploadId,
"upload_media_width" to options.width.toString(),
"upload_media_height" to options.height.toString(),
"upload_media_duration_ms" to options.duration.toString(),
if (options.isSideCar) "is_sidecar" to "1" else null,
if (options.isForAlbum) "for_album" to "1" else null,
if (options.isDirect) "direct_v2" to "1" else null,
*(if (options.isForDirectStory) arrayOf(
"for_direct_story" to "1",
"content_tags" to ""
) else emptyArray()),
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
).toMap()
}
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> = listOfNotNull(
"retry_context" to retryContextString,
"media_type" to "2",
"xsharing_user_ids" to "[]",
"upload_id" to options.uploadId,
"upload_media_width" to options.width.toString(),
"upload_media_height" to options.height.toString(),
"upload_media_duration_ms" to options.duration.toString(),
if (options.isSideCar) "is_sidecar" to "1" else null,
if (options.forAlbum) "for_album" to "1" else null,
if (options.isDirect) "direct_v2" to "1" else null,
*(if (options.isForDirectStory) arrayOf(
"for_direct_story" to "1",
"content_tags" to ""
) else emptyArray()),
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
).toMap()
val retryContextString: String
get() {

View File

@ -110,6 +110,7 @@ public final class MediaUploader {
@NonNull final OnMediaUploadCompleteListener listener) {
try {
final OkHttpClient client = new OkHttpClient.Builder()
// .addInterceptor(new LoggingInterceptor())
.addInterceptor(new AddCookiesInterceptor())
.followRedirects(false)
.followSslRedirects(false)

View File

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
@ -70,8 +71,18 @@ public class IgErrorsInterceptor implements Interceptor {
try {
final String bodyString = body.string();
Log.d(TAG, "checkError: " + bodyString);
final JSONObject jsonObject = new JSONObject(bodyString);
String message = jsonObject.optString("message");
JSONObject jsonObject = null;
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)) {
message = message.toLowerCase();
switch (message) {