kopia lustrzana https://github.com/jortage/poolmgr
Drop Mastodon 202 hack, add B2 support
rodzic
034dc9ab6c
commit
282b10eede
|
@ -10,7 +10,7 @@ repositories {
|
|||
|
||||
base {
|
||||
archivesName = 'jortage-poolmgr'
|
||||
version = '1.5.3'
|
||||
version = '1.5.4'
|
||||
}
|
||||
|
||||
compileJava {
|
||||
|
@ -41,6 +41,7 @@ dependencies {
|
|||
|
||||
implementation 'org.apache.jclouds:jclouds-blobstore:2.5.0'
|
||||
implementation 'org.apache.jclouds.provider:aws-s3:2.5.0'
|
||||
implementation 'org.apache.jclouds.provider:b2:2.5.0'
|
||||
implementation 'org.apache.jclouds.api:filesystem:2.5.0'
|
||||
implementation 'org.apache.jclouds.driver:jclouds-slf4j:2.5.0'
|
||||
|
||||
|
@ -73,6 +74,7 @@ shadowJar {
|
|||
'Main-Class': 'com.jortage.poolmgr.Poolmgr'
|
||||
)
|
||||
archiveClassifier = ''
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
build.dependsOn shadowJar
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
useNewUrls: false
|
||||
readOnly: false
|
||||
backend: {
|
||||
protocol: "s3"
|
||||
endpoint: "https://sfo2.digitaloceanspaces.com"
|
||||
accessKeyId: "ACCESS_KEY_ID"
|
||||
secretAccessKey: "SECRET_ACCESS_KEY"
|
||||
|
@ -9,6 +10,7 @@
|
|||
publicHost: "https://sfo2.digitaloceanspaces.com/mybucket"
|
||||
}
|
||||
backupBackend: {
|
||||
protocol: "s3"
|
||||
endpoint: "https://s3.us-east-2.wasabisys.com"
|
||||
accessKeyId: "ACCESS_KEY_ID"
|
||||
secretAccessKey: "SECRET_ACCESS_KEY"
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.jclouds.blobstore.options.PutOptions;
|
|||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
|
||||
import com.jortage.poolmgr.http.MastodonHackHandler;
|
||||
import com.jortage.poolmgr.http.OuterHandler;
|
||||
import com.jortage.poolmgr.http.RedirHandler;
|
||||
import com.jortage.poolmgr.rivet.RivetHandler;
|
||||
|
@ -97,7 +96,7 @@ public class Poolmgr {
|
|||
Field serverField = S3Proxy.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
Server s3ProxyServer = (Server) serverField.get(s3Proxy);
|
||||
s3ProxyServer.setHandler(new OuterHandler(new MastodonHackHandler(s3ProxyServer.getHandler())));
|
||||
s3ProxyServer.setHandler(new OuterHandler(s3ProxyServer.getHandler()));
|
||||
QueuedThreadPool pool = (QueuedThreadPool)s3ProxyServer.getThreadPool();
|
||||
pool.setName("Jetty-Common");
|
||||
|
||||
|
@ -329,7 +328,9 @@ public class Poolmgr {
|
|||
}
|
||||
|
||||
private static BlobStore createBlobStore(JsonObject obj) {
|
||||
return ContextBuilder.newBuilder("aws-s3")
|
||||
String protocol = ((JsonPrimitive)obj.get("protocol")).asString();
|
||||
if ("s3".equals(protocol)) protocol = "aws-s3";
|
||||
return ContextBuilder.newBuilder(protocol)
|
||||
.credentials(((JsonPrimitive)obj.get("accessKeyId")).asString(), ((JsonPrimitive)obj.get("secretAccessKey")).asString())
|
||||
.modules(ImmutableList.of(new SLF4JLoggingModule()))
|
||||
.endpoint(((JsonPrimitive)obj.get("endpoint")).asString())
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
package com.jortage.poolmgr.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
|
||||
import com.jortage.poolmgr.Poolmgr;
|
||||
|
||||
public class MastodonHackHandler extends HandlerWrapper {
|
||||
|
||||
private static final ScheduledExecutorService sched = Executors.newScheduledThreadPool(2);
|
||||
|
||||
public MastodonHackHandler(Handler delegate) {
|
||||
setHandler(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
String ua = request.getHeader("User-Agent");
|
||||
ScheduledFuture<?> shortCircuit = null;
|
||||
if (!Poolmgr.readOnly && ua != null && ua.contains("aws-sdk-ruby") && request.getHeader("Jortage-Dont202") == null
|
||||
&& request.getQueryString() == null && request.getHeader("x-amz-copy-source") == null
|
||||
&& (request.getMethod().equals("POST") || request.getMethod().equals("PUT"))) {
|
||||
// Mastodon's uploader has a very short timeout.
|
||||
// Wait a short while, and if the response still hasn't been committed, send a 202 to avoid the timeout.
|
||||
shortCircuit = sched.schedule(() -> {
|
||||
try {
|
||||
while (!request.getInputStream().isFinished()) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
response.sendError(202);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}, 2000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
try {
|
||||
super.handle(target, baseRequest, request, response);
|
||||
} finally {
|
||||
if (shortCircuit != null) shortCircuit.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue