mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
fetch repository
This commit is contained in:
parent
e878f43b32
commit
3ccd67b1c4
@ -1,4 +1,48 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository;
|
package gearth.services.internal_extensions.extensionstore.repository;
|
||||||
|
|
||||||
|
import gearth.services.internal_extensions.extensionstore.repository.models.StoreConfig;
|
||||||
|
import gearth.services.internal_extensions.extensionstore.repository.models.StoreData;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class StoreFetch {
|
public class StoreFetch {
|
||||||
|
|
||||||
|
public interface StoreFetchListener {
|
||||||
|
|
||||||
|
void success(StoreRepository storeRepository);
|
||||||
|
void fail(String reason);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fetch(String version, StoreFetchListener storeFetchListener) {
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
JSONObject config = new JSONObject(IOUtils.toString(
|
||||||
|
new URL(String.format("https://raw.githubusercontent.com/sirjonasxx/G-ExtensionStore/repo/%s/store/config.json", version))
|
||||||
|
.openStream(), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
JSONArray exensions = new JSONArray(IOUtils.toString(
|
||||||
|
new URL(String.format("https://raw.githubusercontent.com/sirjonasxx/G-ExtensionStore/repo/%s/.auto-generated/extensions.json", version))
|
||||||
|
.openStream(), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
storeFetchListener.success(new StoreRepository(new StoreData(config, exensions), version));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
storeFetchListener.fail(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// get("1.4.1");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository;
|
package gearth.services.internal_extensions.extensionstore.repository;
|
||||||
|
|
||||||
import gearth.services.internal_extensions.extensionstore.repository.models.ExtCategory;
|
import gearth.services.internal_extensions.extensionstore.repository.models.*;
|
||||||
import gearth.services.internal_extensions.extensionstore.repository.models.ExtFramework;
|
|
||||||
import gearth.services.internal_extensions.extensionstore.repository.models.StoreData;
|
|
||||||
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
|
|
||||||
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
|
import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -11,18 +8,22 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class StoreRepository {
|
public class StoreRepository {
|
||||||
|
|
||||||
|
public static StoreRepository EMPTY = new StoreRepository(new StoreData(new StoreConfig(new ArrayList<>(), new ArrayList<>()), new ArrayList<>()), "0.0");
|
||||||
|
|
||||||
|
private final String repoVersion;
|
||||||
private final StoreData storeData;
|
private final StoreData storeData;
|
||||||
|
|
||||||
public StoreRepository(StoreData storeData) {
|
public StoreRepository(StoreData storeData, String repoVersion) {
|
||||||
|
this.repoVersion = repoVersion;
|
||||||
this.storeData = storeData;
|
this.storeData = storeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExtCategory> getCategories() {
|
public List<ExtCategory> getCategories() {
|
||||||
return storeData.getCategories();
|
return storeData.getConfig().getCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExtFramework> getFrameworks() {
|
public List<ExtFramework> getFrameworks() {
|
||||||
return storeData.getFrameworks();
|
return storeData.getConfig().getFrameworks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StoreExtension> getExtensions() {
|
public List<StoreExtension> getExtensions() {
|
||||||
@ -72,7 +73,7 @@ public class StoreRepository {
|
|||||||
|
|
||||||
public List<String> getLanguages() {
|
public List<String> getLanguages() {
|
||||||
Set<String> languages = new HashSet<>();
|
Set<String> languages = new HashSet<>();
|
||||||
storeData.getFrameworks().forEach(extFramework -> languages.addAll(extFramework.getLanguages()));
|
getFrameworks().forEach(extFramework -> languages.addAll(extFramework.getLanguages()));
|
||||||
return new ArrayList<>(languages);
|
return new ArrayList<>(languages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +100,10 @@ public class StoreRepository {
|
|||||||
public List<ExtensionOrdering> getOrderings() {
|
public List<ExtensionOrdering> getOrderings() {
|
||||||
return Arrays.asList(ExtensionOrdering.values());
|
return Arrays.asList(ExtensionOrdering.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRepoVersion() {
|
||||||
|
return repoVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository.models;
|
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class ExtCategory {
|
public class ExtCategory {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -12,6 +14,12 @@ public class ExtCategory {
|
|||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExtCategory(JSONObject object) {
|
||||||
|
this.name = object.getString("name");
|
||||||
|
this.description = object.getString("description");
|
||||||
|
this.icon = object.getString("icon");
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository.models;
|
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ExtFramework {
|
public class ExtFramework {
|
||||||
|
|
||||||
@ -21,6 +24,16 @@ public class ExtFramework {
|
|||||||
this.installationInstructions = installationInstructions;
|
this.installationInstructions = installationInstructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExtFramework(JSONObject object) {
|
||||||
|
this.name = object.getString("name");
|
||||||
|
this.developers = object.getJSONArray("developers").toList().stream().map(s -> (String)s).collect(Collectors.toList());
|
||||||
|
this.languages = object.getJSONArray("languages").toList().stream().map(s -> (String)s).collect(Collectors.toList());
|
||||||
|
this.source = object.getString("source");
|
||||||
|
this.installationRequired = object.getJSONObject("installation").getBoolean("required");
|
||||||
|
this.installationInstructions = object.getJSONObject("installation").has("instructions") ?
|
||||||
|
object.getJSONObject("installation").getString("instructions") : null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class StoreConfig {
|
||||||
|
|
||||||
|
private final List<ExtCategory> categories;
|
||||||
|
private final List<ExtFramework> frameworks;
|
||||||
|
|
||||||
|
public StoreConfig(List<ExtCategory> categories, List<ExtFramework> frameworks) {
|
||||||
|
this.categories = categories;
|
||||||
|
this.frameworks = frameworks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoreConfig(JSONObject object) {
|
||||||
|
this.categories = object.getJSONArray("categories").toList().stream().map(o -> new ExtCategory(new JSONObject((Map)o))).collect(Collectors.toList());
|
||||||
|
this.frameworks = object.getJSONArray("frameworks").toList().stream().map(o -> new ExtFramework(new JSONObject((Map)o))).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ExtCategory> getCategories() {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ExtFramework> getFrameworks() {
|
||||||
|
return frameworks;
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +1,32 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository.models;
|
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StoreData {
|
public class StoreData {
|
||||||
|
|
||||||
private final List<ExtCategory> categories;
|
private final StoreConfig config;
|
||||||
private final List<ExtFramework> frameworks;
|
|
||||||
|
|
||||||
private final List<StoreExtension> extensions;
|
private final List<StoreExtension> extensions;
|
||||||
|
|
||||||
public StoreData(List<ExtCategory> categories, List<ExtFramework> frameworks, List<StoreExtension> extensions) {
|
public StoreData(StoreConfig config, List<StoreExtension> extensions) {
|
||||||
this.categories = categories;
|
this.config = config;
|
||||||
this.frameworks = frameworks;
|
|
||||||
this.extensions = extensions;
|
this.extensions = extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExtCategory> getCategories() {
|
public StoreData(JSONObject config, JSONArray extensions) {
|
||||||
return categories;
|
this.config = new StoreConfig(config);
|
||||||
}
|
this.extensions = extensions.toList().stream().map(o -> new StoreExtension(new JSONObject((Map)o), this.config)).collect(Collectors.toList());
|
||||||
|
|
||||||
public List<ExtFramework> getFrameworks() {
|
|
||||||
return frameworks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StoreExtension> getExtensions() {
|
public List<StoreExtension> getExtensions() {
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StoreConfig getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package gearth.services.internal_extensions.extensionstore.repository.models;
|
package gearth.services.internal_extensions.extensionstore.repository.models;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StoreExtension {
|
public class StoreExtension {
|
||||||
|
|
||||||
@ -24,6 +29,26 @@ public class StoreExtension {
|
|||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StoreExtension(JSONObject object, StoreConfig storeConfig) {
|
||||||
|
this.title = object.getString("title");
|
||||||
|
this.description = object.getString("title");
|
||||||
|
this.authors = object.getJSONArray("authors").toList().stream().map(o -> new Author(new JSONObject((Map)o))).collect(Collectors.toList());
|
||||||
|
this.version = object.getString("version");
|
||||||
|
this.categories = storeConfig.getCategories().stream().filter(c -> object.getJSONArray("categories")
|
||||||
|
.toList().stream().anyMatch(j -> j.equals(c.getName()))).collect(Collectors.toList());
|
||||||
|
this.source = object.getString("source");
|
||||||
|
this.readme = object.has("readme") ? object.getString("readme") : null;
|
||||||
|
this.stable = object.getBoolean("stable");
|
||||||
|
this.framework = new Framework(object.getJSONObject("framework"), storeConfig);
|
||||||
|
this.language = object.getString("language");
|
||||||
|
this.commands = new Commands(object.getJSONObject("commands"));
|
||||||
|
this.compatibility = new Compatibility(object.getJSONObject("compatibility"));
|
||||||
|
this.submissionDate = LocalDateTime.parse(object.getString("submissionDate"), DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"));
|
||||||
|
this.updateDate = LocalDateTime.parse(object.getString("updateDate"), DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"));
|
||||||
|
this.isOutdated = object.getBoolean("isOutdated");
|
||||||
|
this.rating = object.getInt("rating");
|
||||||
|
}
|
||||||
|
|
||||||
public static class Author {
|
public static class Author {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -43,6 +68,15 @@ public class StoreExtension {
|
|||||||
this.reputation = reputation;
|
this.reputation = reputation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Author(JSONObject object) {
|
||||||
|
this.name = object.getString("name");
|
||||||
|
this.discord = object.has("discord") ? object.getString("discord") : null;
|
||||||
|
this.hotel = object.has("hotel") ? object.getString("hotel") : null;
|
||||||
|
this.username = object.has("username") ? object.getString("username") : null;
|
||||||
|
this.extensionsCount = object.getInt("extensionsCount");
|
||||||
|
this.reputation = object.getInt("reputation");
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -78,6 +112,11 @@ public class StoreExtension {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Framework(JSONObject object, StoreConfig storeConfig) {
|
||||||
|
this.framework = storeConfig.getFrameworks().stream().filter(e -> e.getName().equals(object.getString("name"))).findFirst().get();
|
||||||
|
this.version = object.getString("version");
|
||||||
|
}
|
||||||
|
|
||||||
public ExtFramework getFramework() {
|
public ExtFramework getFramework() {
|
||||||
return framework;
|
return framework;
|
||||||
}
|
}
|
||||||
@ -100,6 +139,13 @@ public class StoreExtension {
|
|||||||
this.mac = mac;
|
this.mac = mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Commands(JSONObject object) {
|
||||||
|
this.defaultCommand = object.getString("default");
|
||||||
|
this.linux = object.has("linux") ? object.getString("linux") : null;
|
||||||
|
this.windows = object.has("windows") ? object.getString("windows") : null;
|
||||||
|
this.mac = object.has("mac") ? object.getString("mac") : null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDefault() {
|
public String getDefault() {
|
||||||
return defaultCommand;
|
return defaultCommand;
|
||||||
}
|
}
|
||||||
@ -126,6 +172,11 @@ public class StoreExtension {
|
|||||||
this.clients = clients;
|
this.clients = clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Compatibility(JSONObject object) {
|
||||||
|
this.systems = object.getJSONArray("systems").toList().stream().map(s -> (String)s).collect(Collectors.toList());
|
||||||
|
this.clients = object.getJSONArray("clients").toList().stream().map(s -> (String)s).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getSystems() {
|
public List<String> getSystems() {
|
||||||
return systems;
|
return systems;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,108 @@
|
|||||||
|
package gearth.services.internal_extensions.extensionstore.tools;
|
||||||
|
|
||||||
|
import gearth.services.extension_handler.extensions.implementations.network.executer.ExecutionInfo;
|
||||||
|
import gearth.services.extension_handler.extensions.implementations.network.executer.NormalExtensionRunner;
|
||||||
|
import gearth.services.internal_extensions.extensionstore.repository.StoreRepository;
|
||||||
|
import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
public class StoreExtensionTools {
|
||||||
|
|
||||||
|
public interface InstallExtListener {
|
||||||
|
|
||||||
|
void success(String installationFolder);
|
||||||
|
void fail(String reason);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void executeExtension(String folderName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unzipInto(InputStream inputStream, File directory) throws IOException {
|
||||||
|
inputStream = new BufferedInputStream(inputStream);
|
||||||
|
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
|
||||||
|
|
||||||
|
for (ZipEntry entry = null; (entry = zipInputStream.getNextEntry()) != null;) {
|
||||||
|
|
||||||
|
File file = new File(Paths.get(directory.getPath(), entry.getName()).toString());
|
||||||
|
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FileUtils.copyInputStreamToFile(inputStream, file);
|
||||||
|
// StreamUtil.write(pathBuilder, inputStream, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void installExtension(String name, StoreRepository storeRepository, InstallExtListener listener) {
|
||||||
|
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
|
||||||
|
String downloadUrl = String.format("https://github.com/sirjonasxx/G-ExtensionStore/raw/repo/%s/store/extensions/%s/extension.zip", storeRepository.getRepoVersion(), name);
|
||||||
|
Optional<StoreExtension> maybeExt = storeRepository.getExtensions().stream().filter(e -> e.getTitle().equals(name)).findFirst();
|
||||||
|
if (maybeExt.isPresent()) {
|
||||||
|
StoreExtension ext = maybeExt.get();
|
||||||
|
String version = ext.getVersion();
|
||||||
|
|
||||||
|
String folderName = name + "_" + version;
|
||||||
|
String path = Paths.get(NormalExtensionRunner.JARPATH, ExecutionInfo.EXTENSIONSDIRECTORY, folderName).toString();
|
||||||
|
|
||||||
|
File dir = new File(path);
|
||||||
|
File extensionPath = new File(Paths.get(path, "extension").toString());
|
||||||
|
|
||||||
|
if (extensionPath.mkdirs()) {
|
||||||
|
try {
|
||||||
|
URL url = new URL(downloadUrl);
|
||||||
|
InputStream inputStream = url.openStream();
|
||||||
|
unzipInto(inputStream, extensionPath);
|
||||||
|
// todo command file
|
||||||
|
|
||||||
|
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
listener.fail("Invalid extension URL");
|
||||||
|
} catch (IOException e) {
|
||||||
|
listener.fail("Extension not available in repository");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
listener.fail("Something went wrong creating the extension directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
listener.fail("Extension wasn't found");
|
||||||
|
}
|
||||||
|
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeExtension(String folderName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void updateExtension() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user