-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
188 additions
and
75 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -11,3 +11,5 @@ JWT_VALIDITY_IN_MIN= | |
|
||
BASIC_USERNAME= | ||
BASIC_PASSWORD= | ||
|
||
OLD_API_URL= |
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
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
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/app/revanced/api/configuration/routing/routes/OldApi.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,16 @@ | ||
package app.revanced.api.configuration.routing.routes | ||
|
||
import app.revanced.api.repository.OldApiService | ||
import io.ktor.server.application.* | ||
import io.ktor.server.routing.* | ||
import org.koin.ktor.ext.get | ||
|
||
internal fun Route.oldApiRoute() { | ||
val oldApiService = get<OldApiService>() | ||
|
||
route(Regex("(v2|tools|contributor).*")) { | ||
handle { | ||
oldApiService.proxy(call) | ||
} | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/app/revanced/api/repository/OldApiService.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,65 @@ | ||
package app.revanced.api.repository | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.http.* | ||
import io.ktor.http.content.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.request.* | ||
import io.ktor.server.response.* | ||
import io.ktor.util.* | ||
import io.ktor.utils.io.* | ||
|
||
internal class OldApiService(private val client: HttpClient) { | ||
@OptIn(InternalAPI::class) | ||
suspend fun proxy(call: ApplicationCall) { | ||
val channel = call.request.receiveChannel() | ||
val size = channel.availableForRead | ||
val byteArray = ByteArray(size) | ||
channel.readFully(byteArray) | ||
|
||
val response: HttpResponse = client.request(call.request.uri) { | ||
method = call.request.httpMethod | ||
|
||
headers { | ||
appendAll( | ||
call.request.headers.filter { key, _ -> | ||
!key.equals( | ||
HttpHeaders.ContentType, | ||
ignoreCase = true, | ||
) && !key.equals( | ||
HttpHeaders.ContentLength, | ||
ignoreCase = true, | ||
) && !key.equals(HttpHeaders.Host, ignoreCase = true) | ||
}, | ||
) | ||
} | ||
if (call.request.httpMethod == HttpMethod.Post) { | ||
body = ByteArrayContent(byteArray, call.request.contentType()) | ||
} | ||
} | ||
|
||
val headers = response.headers | ||
|
||
call.respond(object : OutgoingContent.WriteChannelContent() { | ||
override val contentLength: Long? = headers[HttpHeaders.ContentLength]?.toLong() | ||
override val contentType = headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) } | ||
override val headers: Headers = Headers.build { | ||
appendAll( | ||
headers.filter { key, _ -> | ||
!key.equals( | ||
HttpHeaders.ContentType, | ||
ignoreCase = true, | ||
) && !key.equals(HttpHeaders.ContentLength, ignoreCase = true) | ||
}, | ||
) | ||
} | ||
override val status = response.status | ||
|
||
override suspend fun writeTo(channel: ByteWriteChannel) { | ||
response.content.copyAndClose(channel) | ||
} | ||
}) | ||
} | ||
} |
7 changes: 2 additions & 5 deletions
7
src/main/kotlin/app/revanced/api/repository/backend/BackendRepository.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
Oops, something went wrong.