-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: Add Jodel support (#462) * chore: Use alphabetic imports ordering * chore: use KotlinX Serialization --------- Co-authored-by: xyrolaith <18216850+xyrolaith@users.noreply.github.com> Co-authored-by: Sven Jacobs <github@svenjacobs.com>
- Loading branch information
1 parent
3ba1901
commit 42f2ca2
Showing
7 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ android { | |
|
||
dependencies { | ||
api(libs.kotlinx.collections.immutable) | ||
api(libs.kotlinx.serialization.json) | ||
} |
34 changes: 34 additions & 0 deletions
34
...ain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/jodel/JodelSanitizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.svenjacobs.app.leon.core.domain.sanitizer.jodel | ||
|
||
import android.content.Context | ||
import com.svenjacobs.app.leon.core.common.url.decodeUrl | ||
import com.svenjacobs.app.leon.core.domain.R | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId | ||
import kotlin.io.encoding.Base64 | ||
import kotlin.io.encoding.ExperimentalEncodingApi | ||
import kotlinx.serialization.json.Json | ||
|
||
class JodelSanitizer : Sanitizer { | ||
override val id = SanitizerId("jodel") | ||
|
||
override fun getMetadata(context: Context) = Sanitizer.Metadata( | ||
name = context.getString(R.string.sanitizer_jodel_name), | ||
) | ||
|
||
@OptIn(ExperimentalEncodingApi::class) | ||
override fun invoke(input: String): String { | ||
val encoded = URL_REGEX.find(input)?.groupValues?.getOrNull(1) ?: return input | ||
val base64Data = decodeUrl(encoded) | ||
val jsonString = Base64.Default.decode(base64Data) | ||
val jsonMap = Json.decodeFromString<Map<String, String>>(jsonString.decodeToString()) | ||
|
||
return jsonMap["\$android_url"] ?: input | ||
} | ||
|
||
override fun matchesDomain(input: String) = URL_REGEX.containsMatchIn(input) | ||
|
||
private companion object { | ||
private val URL_REGEX = Regex("^https?://shared\\.jodel\\.com/a/key_live_.*&data=([^?&]*)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/jodel/JodelSanitizerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Léon - The URL Cleaner | ||
* Copyright (C) 2023 Sven Jacobs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.svenjacobs.app.leon.core.domain.sanitizer.jodel | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class JodelSanitizerTest : | ||
WordSpec( | ||
{ | ||
|
||
"invoke" should { | ||
|
||
"extract Jodel sharing URL" { | ||
val sanitizer = JodelSanitizer() | ||
val result = sanitizer( | ||
"http://shared.jodel.com/a/key_live_abZZZZgPxyz82xxxxAAAAdefghi4YYY1" + | ||
"?%24identity_id=123456789012345678&feature=shared_post&campaign=image" + | ||
"_DE_FrontPage&type=0&duration=0&source=android&data=eyIkY2Fub25pY2FsX" + | ||
"2lkZW50aWZpZXIiOiJzYWpcL2JhZGMwZmZlZWJhZGMwZmZlZTAxMjM0NSIsIiRwdWJsaW" + | ||
"NseV9pbmRleGFibGUiOiJ0cnVlIiwicG9zdElkIjoiYmFkYzBmZmVlYmFkYzBmZmVlMDE" + | ||
"yMzQ1IiwiJGRlc2t0b3BfdXJsIjoiaHR0cHM6XC9cL3NoYXJlLmpvZGVsLmNvbVwvcG9z" + | ||
"dD9wb3N0SWQ9YmFkYzBmZmVlYmFkYzBmZmVlMDEyMzQ1IiwicmVmZXJyZXJfaWQiOiJhY" + | ||
"mNkZWYwMTIzNDU2Nzg5ZGVhZGMwZGUiLCIkYW5kcm9pZF91cmwiOiJodHRwczpcL1wvc2" + | ||
"hhcmUuam9kZWwuY29tXC9wb3N0P3Bvc3RJZD1iYWRjMGZmZWViYWRjMGZmZWUwMTIzNDU" + | ||
"iLCIkaW9zX3VybCI6Imh0dHBzOlwvXC9zaGFyZS5qb2RlbC5jb21cL3Bvc3Q%2FcG9zdE" + | ||
"lkPWJhZGMwZmZlZWJhZGMwZmZlZTAxMjM0NSJ9?channel=copy", | ||
) | ||
|
||
result shouldBe "https://share.jodel.com/post?postId=badc0ffeebadc0ffee012345" | ||
} | ||
} | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters