mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Портирован UpdateListRequest
This commit is contained in:
parent
b5d2f47cf8
commit
ec7e64fdf4
4 changed files with 33 additions and 13 deletions
|
@ -4,13 +4,17 @@
|
||||||
import ru.gravit.launcher.events.request.ErrorRequestEvent;
|
import ru.gravit.launcher.events.request.ErrorRequestEvent;
|
||||||
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
|
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class UpdateListResponse implements JsonResponseInterface {
|
public class UpdateListResponse implements JsonResponseInterface {
|
||||||
public String dir;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -23,8 +27,10 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
|
HashSet<String> set = new HashSet<>();
|
||||||
service.sendObject(ctx, new UpdateListRequestEvent(hdir));
|
for(Map.Entry<String, SignedObjectHolder<HashedDir>> entry : LaunchServer.server.updatesDirMap.entrySet())
|
||||||
|
set.add(entry.getKey());
|
||||||
|
service.sendObject(ctx, new UpdateListRequestEvent(set));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
|
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
import ru.gravit.launcher.request.RequestType;
|
||||||
|
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||||
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
@ -13,7 +16,7 @@
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public final class UpdateListRequest extends Request<Set<String>> {
|
public final class UpdateListRequest extends Request<UpdateListRequestEvent> implements RequestInterface {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public UpdateListRequest() {
|
public UpdateListRequest() {
|
||||||
this(null);
|
this(null);
|
||||||
|
@ -24,21 +27,32 @@ public UpdateListRequest(LauncherConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpdateListRequestEvent requestWebSockets() throws Exception
|
||||||
|
{
|
||||||
|
return (UpdateListRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getLegacyType() {
|
public Integer getLegacyType() {
|
||||||
return RequestType.UPDATE_LIST.getNumber();
|
return RequestType.UPDATE_LIST.getNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> requestDo(HInput input, HOutput output) throws IOException {
|
protected UpdateListRequestEvent requestDo(HInput input, HOutput output) throws IOException {
|
||||||
int count = input.readLength(0);
|
int count = input.readLength(0);
|
||||||
|
|
||||||
// Read all update dirs names
|
// Read all update dirs names
|
||||||
Set<String> result = new HashSet<>(count);
|
HashSet<String> result = new HashSet<>(count);
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
result.add(IOHelper.verifyFileName(input.readString(255)));
|
result.add(IOHelper.verifyFileName(input.readString(255)));
|
||||||
|
|
||||||
// We're done. Make it unmodifiable and return
|
// We're done. Make it unmodifiable and return
|
||||||
return Collections.unmodifiableSet(result);
|
return new UpdateListRequestEvent(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "updateList";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ public void registerResults() {
|
||||||
registerResult("profileByUUID", ProfileByUUIDRequestEvent.class);
|
registerResult("profileByUUID", ProfileByUUIDRequestEvent.class);
|
||||||
registerResult("batchProfileByUsername", BatchProfileByUsernameRequestEvent.class);
|
registerResult("batchProfileByUsername", BatchProfileByUsernameRequestEvent.class);
|
||||||
registerResult("profiles", ProfilesRequestEvent.class);
|
registerResult("profiles", ProfilesRequestEvent.class);
|
||||||
|
registerResult("setProfile", SetProfileRequestEvent.class);
|
||||||
registerResult("updateList", UpdateListRequestEvent.class);
|
registerResult("updateList", UpdateListRequestEvent.class);
|
||||||
registerResult("error", ErrorRequestEvent.class);
|
registerResult("error", ErrorRequestEvent.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,17 @@
|
||||||
import ru.gravit.launcher.request.ResultInterface;
|
import ru.gravit.launcher.request.ResultInterface;
|
||||||
import ru.gravit.utils.event.EventInterface;
|
import ru.gravit.utils.event.EventInterface;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UpdateListRequestEvent implements EventInterface, ResultInterface {
|
public class UpdateListRequestEvent implements EventInterface, ResultInterface {
|
||||||
private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
|
private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public final String type;
|
public final HashSet<String> dirs;
|
||||||
@LauncherNetworkAPI
|
|
||||||
public final HashedDir dir;
|
|
||||||
|
|
||||||
public UpdateListRequestEvent(HashedDir dir) {
|
public UpdateListRequestEvent(HashSet<String> dirs) {
|
||||||
this.dir = dir;
|
this.dirs = dirs;
|
||||||
type = "success";
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
|
|
Loading…
Reference in a new issue