|
@@ -17,7 +17,6 @@ import org.cobbzilla.util.http.HttpMeta; |
|
|
import org.cobbzilla.util.http.HttpRequestBean; |
|
|
import org.cobbzilla.util.http.HttpRequestBean; |
|
|
import org.cobbzilla.util.http.HttpUtil; |
|
|
import org.cobbzilla.util.http.HttpUtil; |
|
|
import org.cobbzilla.util.io.Decompressors; |
|
|
import org.cobbzilla.util.io.Decompressors; |
|
|
import org.cobbzilla.util.io.FileUtil; |
|
|
|
|
|
import org.cobbzilla.util.io.TempDir; |
|
|
import org.cobbzilla.util.io.TempDir; |
|
|
import org.cobbzilla.wizard.cache.redis.RedisService; |
|
|
import org.cobbzilla.wizard.cache.redis.RedisService; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
@@ -78,19 +77,18 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa |
|
|
|
|
|
|
|
|
protected abstract GeoLocation _geolocate (String ip); |
|
|
protected abstract GeoLocation _geolocate (String ip); |
|
|
|
|
|
|
|
|
public File initFile(String url, String pathMatch, List<NameAndValue> headers) { |
|
|
|
|
|
|
|
|
public File initFile(String url, String pathMatch, List<NameAndValue> headers, String extension) { |
|
|
final File archive; |
|
|
final File archive; |
|
|
final File dbFile; |
|
|
final File dbFile; |
|
|
String ext; |
|
|
|
|
|
try { |
|
|
try { |
|
|
final boolean isFile = url.startsWith(SCHEME_FILE); |
|
|
final boolean isFile = url.startsWith(SCHEME_FILE); |
|
|
if (isFile) { |
|
|
if (isFile) { |
|
|
archive = new File(url.substring(SCHEME_FILE.length())); |
|
|
archive = new File(url.substring(SCHEME_FILE.length())); |
|
|
ext = FileUtil.extension(archive); |
|
|
|
|
|
dbFile = new File(archive.getParentFile(), archive.getName()+".database"); |
|
|
dbFile = new File(archive.getParentFile(), archive.getName()+".database"); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
final String urlWithLicense = HandlebarsUtil.apply(getHandlebars(), url, getCredentials().newContext(), '[', ']'); |
|
|
|
|
|
|
|
|
final String urlWithLicense = HandlebarsUtil.apply(getHandlebars(), url, getCredentials().newContext(), '[', ']') |
|
|
|
|
|
.replace("&", "&"); |
|
|
final HttpRequestBean request = new HttpRequestBean(urlWithLicense).setHeaders(headers); |
|
|
final HttpRequestBean request = new HttpRequestBean(urlWithLicense).setHeaders(headers); |
|
|
final HttpMeta meta = HttpUtil.getHeadMetadata(request); |
|
|
final HttpMeta meta = HttpUtil.getHeadMetadata(request); |
|
|
|
|
|
|
|
@@ -104,20 +102,18 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa |
|
|
if (meta.shouldRefresh(archive)) { |
|
|
if (meta.shouldRefresh(archive)) { |
|
|
downloadDbFile(request, archive); |
|
|
downloadDbFile(request, archive); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// create a symlink with the proper extension, so "unroll" can detect the archive type |
|
|
|
|
|
ext = getExtension(url); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (ext.startsWith(".")) ext = ext.substring(1); |
|
|
|
|
|
switch (ext) { |
|
|
|
|
|
|
|
|
if (extension.startsWith(".")) extension = extension.substring(1); |
|
|
|
|
|
switch (extension) { |
|
|
case "zip": case "tgz": case "gz": case "tar.gz": case "tar.bz2": break; |
|
|
case "zip": case "tgz": case "gz": case "tar.gz": case "tar.bz2": break; |
|
|
default: return die("initFile: unrecognized archive extension: "+ext+", from URL="+url); |
|
|
|
|
|
|
|
|
default: return die("initFile: unrecognized archive extension: "+extension+", from URL="+url); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// create a symlink with the proper extension, so "unroll" can detect the archive type |
|
|
final File link; |
|
|
final File link; |
|
|
if (!isFile) { |
|
|
if (!isFile) { |
|
|
link = new File(abs(archive) + "." + ext); |
|
|
|
|
|
|
|
|
link = new File(abs(archive) + "." + extension); |
|
|
if (link.exists() && !link.delete()) return die("initFile: error removing link: " + abs(link)); |
|
|
if (link.exists() && !link.delete()) return die("initFile: error removing link: " + abs(link)); |
|
|
symlink(link, archive); |
|
|
symlink(link, archive); |
|
|
} else { |
|
|
} else { |
|
@@ -160,6 +156,4 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa |
|
|
throw new IllegalStateException(msg, lastEx); |
|
|
throw new IllegalStateException(msg, lastEx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public String getExtension(String url) { return FileUtil.extension(url); } |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |