Shorter URLs that include file extensions and short "filenames"

trunk
Una Thompson 2023-09-24 19:00:11 -07:00
rodzic b81ef3300a
commit 5bdf2a7c2e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: CD9D524194BE98F5
4 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ repositories {
base {
archivesName = 'jortage-poolmgr'
version = '1.5.1'
version = '1.5.2'
}
compileJava {

Wyświetl plik

@ -1,4 +1,6 @@
{
useNewUrls: false
readOnly: false
backend: {
endpoint: "https://sfo2.digitaloceanspaces.com"
accessKeyId: "ACCESS_KEY_ID"

Wyświetl plik

@ -64,6 +64,7 @@ public class Poolmgr {
private static boolean backingUp = false;
private static boolean rivetEnabled;
private static boolean rivetState;
public static boolean useNewUrls;
public static final Table<String, String, Object> provisionalMaps = HashBasedTable.create();
@ -225,6 +226,7 @@ public class Poolmgr {
String publicHostTmp = ((JsonPrimitive)configTmp.getObject("backend").get("publicHost")).asString();
boolean rivetEnabledTmp = configTmp.recursiveGet(boolean.class, "rivet.enabled");
boolean readOnlyTmp = MoreObjects.firstNonNull(configTmp.get(boolean.class, "readOnly"), false);
boolean useNewUrlsTmp = MoreObjects.firstNonNull(configTmp.get(boolean.class, "useNewUrls"), false);
System.err.print(prelude+"Constructing blob stores...");
System.err.flush();
BlobStore backingBlobStoreTmp = createBlobStore(configTmp.getObject("backend"));
@ -306,6 +308,7 @@ public class Poolmgr {
backingBackupBlobStore = backingBackupBlobStoreTmp;
dataSource = dataSourceTmp;
rivetEnabled = rivetEnabledTmp;
useNewUrls = useNewUrlsTmp;
if (rivetState != rivetEnabled && reloading) {
System.err.println("WARNING: Cannot hot-"+(rivetEnabled ? "enable" : "disable")+" Rivet. jortage-proxy must be restarted for this change to take effect.");
}

Wyświetl plik

@ -14,9 +14,12 @@ import com.jortage.poolmgr.Poolmgr;
import com.jortage.poolmgr.Queries;
import com.google.common.base.Splitter;
import com.google.common.hash.HashCode;
import com.google.common.io.BaseEncoding;
import com.google.common.io.ByteStreams;
public final class RedirHandler extends AbstractHandler {
private static final BaseEncoding B64URLNP = BaseEncoding.base64Url().omitPadding();
private static final Splitter REDIR_SPLITTER = Splitter.on('/').limit(2).omitEmptyStrings();
private final BlobStore dumpsStore;
@ -71,9 +74,19 @@ public final class RedirHandler extends AbstractHandler {
if (waited) {
response.setHeader("Jortage-Waited", "true");
}
String hash = Queries.getMap(Poolmgr.dataSource, identity, name).toString();
HashCode hash = Queries.getMap(Poolmgr.dataSource, identity, name);
response.setHeader("Cache-Control", "public");
response.setHeader("Location", Poolmgr.publicHost+"/"+Poolmgr.hashToPath(hash));
if (Poolmgr.useNewUrls) {
int dotIdx = name.indexOf('.', name.lastIndexOf('/')+1);
String extension = "";
if (dotIdx != -1) {
extension = "."+name.substring(dotIdx+1);
}
String b64 = B64URLNP.encode(hash.asBytes());
response.setHeader("Location", Poolmgr.publicHost+"/blob2/"+b64.substring(0, 16)+"/"+b64.substring(16, b64.length()-8)+"/"+b64.substring(b64.length()-8)+extension);
} else {
response.setHeader("Location", Poolmgr.publicHost+"/"+Poolmgr.hashToPath(hash.toString()));
}
response.setStatus(301);
} catch (IllegalArgumentException e) {
response.sendError(404);