mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-01-19 02:48:37 +00:00
Merge branch 'minor-cleanup' into 'master'
Minor cleanup See merge request mangadex-pub/mangadex_at_home!93
This commit is contained in:
commit
ad392b30d8
13
build.gradle
13
build.gradle
|
@ -1,8 +1,8 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "jacoco"
|
id "jacoco"
|
||||||
id "java"
|
id "java"
|
||||||
id "org.jetbrains.kotlin.jvm" version "1.5.10"
|
id "org.jetbrains.kotlin.jvm" version "1.5.21"
|
||||||
id "org.jetbrains.kotlin.kapt" version "1.5.10"
|
id "org.jetbrains.kotlin.kapt" version "1.5.21"
|
||||||
id "application"
|
id "application"
|
||||||
id "com.github.johnrengelman.shadow" version "5.2.0"
|
id "com.github.johnrengelman.shadow" version "5.2.0"
|
||||||
id "com.diffplug.spotless" version "5.8.2"
|
id "com.diffplug.spotless" version "5.8.2"
|
||||||
|
@ -93,18 +93,12 @@ java {
|
||||||
|
|
||||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spotless {
|
spotless {
|
||||||
java {
|
|
||||||
targetExclude("build/generated/**/*")
|
|
||||||
eclipse()
|
|
||||||
removeUnusedImports()
|
|
||||||
trimTrailingWhitespace()
|
|
||||||
endWithNewline()
|
|
||||||
}
|
|
||||||
kotlin {
|
kotlin {
|
||||||
ktlint("0.40.0").userData(["disabled_rules": "no-wildcard-imports"])
|
ktlint("0.40.0").userData(["disabled_rules": "no-wildcard-imports"])
|
||||||
licenseHeaderFile "license_header"
|
licenseHeaderFile "license_header"
|
||||||
|
@ -120,7 +114,6 @@ tasks.register("generateVersion", Copy) {
|
||||||
into "$buildDir/generated/java"
|
into "$buildDir/generated/java"
|
||||||
expand templateContext
|
expand templateContext
|
||||||
}
|
}
|
||||||
//tasks.named(":kaptKotlin").dependsOn generateVersion
|
|
||||||
compileJava.dependsOn generateVersion
|
compileJava.dependsOn generateVersion
|
||||||
sourceSets.main.java.srcDir generateVersion
|
sourceSets.main.java.srcDir generateVersion
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1 @@
|
||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
gradlePluginPortal()
|
|
||||||
google()
|
|
||||||
}
|
|
||||||
resolutionStrategy {
|
|
||||||
eachPlugin {
|
|
||||||
if (requested.id.id == "com.squareup.sqldelight") {
|
|
||||||
useModule("com.squareup.sqldelight:gradle-plugin:${requested.version}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rootProject.name = 'mangadex_at_home'
|
rootProject.name = 'mangadex_at_home'
|
||||||
|
|
118
src/main/java/mdnet/cache/CachingInputStream.java
vendored
118
src/main/java/mdnet/cache/CachingInputStream.java
vendored
|
@ -1,118 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package mdnet.cache;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.io.input.ProxyInputStream;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
|
|
||||||
import static org.apache.commons.io.IOUtils.EOF;
|
|
||||||
|
|
||||||
public class CachingInputStream extends ProxyInputStream {
|
|
||||||
private final OutputStream cache;
|
|
||||||
private final ExecutorService executor;
|
|
||||||
private final Runnable onClose;
|
|
||||||
private boolean eofReached = false;
|
|
||||||
|
|
||||||
public CachingInputStream(InputStream response, ExecutorService executor, OutputStream cache, Runnable onClose) {
|
|
||||||
super(response);
|
|
||||||
this.executor = executor;
|
|
||||||
this.cache = cache;
|
|
||||||
this.onClose = onClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
if (eofReached) {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cache.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
onClose.run();
|
|
||||||
} else {
|
|
||||||
executor.submit(() -> {
|
|
||||||
try {
|
|
||||||
IOUtils.copy(in, cache);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cache.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
onClose.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read() throws IOException {
|
|
||||||
final int ch = super.read();
|
|
||||||
if (ch != EOF) {
|
|
||||||
try {
|
|
||||||
cache.write(ch);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
// don't let write failures affect the image loading
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eofReached = true;
|
|
||||||
}
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(final byte[] bts, final int st, final int end) throws IOException {
|
|
||||||
final int n = super.read(bts, st, end);
|
|
||||||
if (n != EOF) {
|
|
||||||
try {
|
|
||||||
cache.write(bts, st, n);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
// don't let write failures affect the image loading
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eofReached = true;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(final byte[] bts) throws IOException {
|
|
||||||
final int n = super.read(bts);
|
|
||||||
if (n != EOF) {
|
|
||||||
try {
|
|
||||||
cache.write(bts, 0, n);
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
// don't let write failures affect the image loading
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eofReached = true;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
114
src/main/kotlin/mdnet/cache/CachingInputStream.kt
vendored
Normal file
114
src/main/kotlin/mdnet/cache/CachingInputStream.kt
vendored
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
Mangadex@Home
|
||||||
|
Copyright (c) 2020, MangaDex Network
|
||||||
|
This file is part of MangaDex@Home.
|
||||||
|
|
||||||
|
MangaDex@Home 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.
|
||||||
|
|
||||||
|
MangaDex@Home 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 MangaDex@Home. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package mdnet.cache
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils
|
||||||
|
import org.apache.commons.io.input.ProxyInputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.lang.Runnable
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import kotlin.Throws
|
||||||
|
|
||||||
|
class CachingInputStream(
|
||||||
|
response: InputStream?,
|
||||||
|
private val executor: ExecutorService,
|
||||||
|
private val cache: OutputStream,
|
||||||
|
private val onClose: Runnable
|
||||||
|
) : ProxyInputStream(response) {
|
||||||
|
private var eofReached = false
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun close() {
|
||||||
|
if (eofReached) {
|
||||||
|
try {
|
||||||
|
`in`.close()
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cache.close()
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
}
|
||||||
|
onClose.run()
|
||||||
|
} else {
|
||||||
|
executor.submit {
|
||||||
|
try {
|
||||||
|
IOUtils.copy(`in`, cache)
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
`in`.close()
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cache.close()
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
}
|
||||||
|
onClose.run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun read(): Int {
|
||||||
|
val ch = super.read()
|
||||||
|
if (ch != IOUtils.EOF) {
|
||||||
|
try {
|
||||||
|
cache.write(ch)
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
// don't let write failures affect the image loading
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eofReached = true
|
||||||
|
}
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun read(bts: ByteArray, st: Int, end: Int): Int {
|
||||||
|
val n = super.read(bts, st, end)
|
||||||
|
if (n != IOUtils.EOF) {
|
||||||
|
try {
|
||||||
|
cache.write(bts, st, n)
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
// don't let write failures affect the image loading
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eofReached = true
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun read(bts: ByteArray): Int {
|
||||||
|
val n = super.read(bts)
|
||||||
|
if (n != IOUtils.EOF) {
|
||||||
|
try {
|
||||||
|
cache.write(bts, 0, n)
|
||||||
|
} catch (ignored: IOException) {
|
||||||
|
// don't let write failures affect the image loading
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eofReached = true
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
}
|
|
@ -174,7 +174,7 @@ class ImageServer(
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val LOGGER = LoggerFactory.getLogger(ImageServer::class.java)
|
private val LOGGER = LoggerFactory.getLogger(ImageServer::class.java)
|
||||||
private fun String.isImageMimetype() = this.toLowerCase().startsWith("image/")
|
private fun String.isImageMimetype() = this.lowercase().startsWith("image/")
|
||||||
|
|
||||||
private fun baseHandler(): Filter =
|
private fun baseHandler(): Filter =
|
||||||
CachingFilters.Response.MaxAge(Clock.systemUTC(), Constants.MAX_AGE_CACHE)
|
CachingFilters.Response.MaxAge(Clock.systemUTC(), Constants.MAX_AGE_CACHE)
|
||||||
|
|
|
@ -86,7 +86,7 @@ fun getServer(
|
||||||
|
|
||||||
val circuited = ResilienceFilters.CircuitBreak(
|
val circuited = ResilienceFilters.CircuitBreak(
|
||||||
circuitBreaker,
|
circuitBreaker,
|
||||||
isError = { r: Response -> !r.status.successful }
|
isError = { r: Response -> r.status.serverError }
|
||||||
)
|
)
|
||||||
|
|
||||||
val upstream = ClientFilters.MicrometerMetrics.RequestTimer(registry)
|
val upstream = ClientFilters.MicrometerMetrics.RequestTimer(registry)
|
||||||
|
@ -102,9 +102,9 @@ fun getServer(
|
||||||
|
|
||||||
FunctionCounter.builder(
|
FunctionCounter.builder(
|
||||||
"client.sent",
|
"client.sent",
|
||||||
statistics,
|
statistics
|
||||||
{ it.bytesSent.get().toDouble() }
|
) { it.bytesSent.get().toDouble() }
|
||||||
).baseUnit(BaseUnits.BYTES).register(registry)
|
.baseUnit(BaseUnits.BYTES).register(registry)
|
||||||
|
|
||||||
val verifier = TokenVerifier(
|
val verifier = TokenVerifier(
|
||||||
tokenKey = remoteSettings.tokenKey,
|
tokenKey = remoteSettings.tokenKey,
|
||||||
|
|
Loading…
Reference in a new issue