Map fn:name scripts to stable script bundle from app.filebot.net and dev:name scripts directly to github resources

This commit is contained in:
Reinhard Pointner 2016-04-03 19:49:20 +00:00
parent 93181df73e
commit 36237cd906
2 changed files with 13 additions and 13 deletions

View File

@ -8,7 +8,7 @@ update.url: https://app.filebot.net/update.xml
donate.url: https://app.filebot.net/donate.php
# base URL for resolving script resources
github.stable: https://raw.githubusercontent.com/filebot/scripts/m2/
github.stable: https://app.filebot.net/scripts/m1.jar
github.master: https://raw.githubusercontent.com/filebot/scripts/master/
# native links

View File

@ -6,7 +6,6 @@ import static net.filebot.util.FileUtilities.*;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import net.filebot.Cache;
@ -23,7 +22,10 @@ public enum ScriptSource {
@Override
public ScriptProvider getScriptProvider(String input) throws Exception {
return getScriptBundle(this, "github.stable", Cache.ONE_WEEK);
URI bundle = new URI(getApplicationProperty("github.stable"));
byte[] bytes = getCache().bytes(bundle, URI::toURL).expire(Cache.ONE_WEEK).get();
return new ScriptBundle(bytes, getClass().getResourceAsStream("repository.cer"));
}
},
@ -37,7 +39,9 @@ public enum ScriptSource {
@Override
public ScriptProvider getScriptProvider(String input) throws Exception {
return getScriptBundle(this, "github.master", Cache.ONE_DAY);
URI parent = new URI(getApplicationProperty("github.master"));
return n -> getCache().text(n, s -> parent.resolve(s + ".groovy").toURL()).expire(Cache.ONE_DAY).get();
}
},
@ -72,10 +76,9 @@ public enum ScriptSource {
@Override
public ScriptProvider getScriptProvider(String input) throws Exception {
Cache cache = Cache.getCache(name(), CacheType.Persistent);
URI parent = new URI(input).resolve(".");
return f -> cache.text(f, s -> parent.resolve(s + ".groovy").toURL()).expire(Duration.ZERO).get();
return n -> getCache().text(n, s -> parent.resolve(s + ".groovy").toURL()).expire(Duration.ZERO).get();
}
},
@ -104,15 +107,12 @@ public enum ScriptSource {
public abstract ScriptProvider getScriptProvider(String input) throws Exception;
public Cache getCache() {
return Cache.getCache(name(), CacheType.Persistent);
}
public static ScriptSource findScriptProvider(String input) throws Exception {
return stream(values()).filter(s -> s.accept(input) != null).findFirst().get();
}
private static ScriptProvider getScriptBundle(ScriptSource source, String branch, Duration expirationTime) throws Exception {
Cache cache = Cache.getCache(source.name(), CacheType.Persistent);
byte[] bytes = cache.bytes("repository.jar", f -> new URL(getApplicationProperty(branch) + f)).expire(expirationTime).get();
return new ScriptBundle(bytes, source.getClass().getResourceAsStream("repository.cer"));
}
}