From 0dd62f446b0f10963cf3400f263fd91b55d47262 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 5 Nov 2021 22:24:58 +0100 Subject: [PATCH] Refractor Signed-off-by: Chaoscaot --- .../src/de/steamwar/sql/CheckedSchematic.java | 79 +++++++++++++++++++ .../de/steamwar/sql/DownloadSchematic.java | 29 +------ .../src/de/steamwar/sql/NodeDownload.java | 49 ++++++++++++ 3 files changed, 129 insertions(+), 28 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java create mode 100644 SpigotCore_Main/src/de/steamwar/sql/NodeDownload.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java new file mode 100644 index 0000000..b3ff430 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java @@ -0,0 +1,79 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.sql; + +import java.sql.Timestamp; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Deprecated +public class CheckedSchematic { + + private final CheckedNode node; + + private CheckedSchematic(CheckedNode node){ + this.node = node; + } + + @Deprecated + public CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason){ + this(new CheckedNode(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID(), validator ,startTime, endTime, declineReason)); + } + + @Deprecated + public CheckedSchematic(String schemName, UUID schemOwner, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){ + this(new CheckedNode(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID(), validator ,startTime, endTime, declineReason)); + } + + public static List getLastDeclined(UUID schemOwner){ + return getLastDelined(SteamwarUser.get(schemOwner).getId()); + } + + public static List getLastDelined(int schemOwner){ + return CheckedNode.getLastDelined(schemOwner).stream().map(node1 -> new CheckedSchematic(node1)).collect(Collectors.toList()); + } + + @Deprecated + public void remove() { + node.remove(); + } + + public String getSchemName() { + return node.getSchemName(); + } + + public int getSchemOwner() { + return node.getSchemOwner(); + } + + public int getValidator() { + return node.getValidator(); + } + + public Timestamp getStartTime() { + return node.getStartTime(); + } + + public Timestamp getEndTime() { + return node.getEndTime(); + } + + public String getDeclineReason() { + return node.getDeclineReason(); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java index 7f4dc2b..64812f9 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java @@ -19,38 +19,11 @@ package de.steamwar.sql; -import com.google.common.io.BaseEncoding; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.time.Instant; - public class DownloadSchematic { private DownloadSchematic(){} - private static final SQL.Statement createLink = new SQL.Statement("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)"); - - - private static final String BASE = "https://steamwar.de/download.php?schem="; - - public static String getLink(SchematicNode schem){ - if(schem.isDir()) - throw new SecurityException("Can not Download Directorys"); - MessageDigest digest; - try { - digest = MessageDigest.getInstance("SHA-1"); - } catch (NoSuchAlgorithmException e) { - throw new SecurityException(e); - } - digest.reset(); - digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes()); - String hash = BaseEncoding.base16().encode(digest.digest()); - createLink.update(schem.getId(), hash); - return BASE + hash; - } - @Deprecated public static String getLink(Schematic schem){ - return getLink(schem.getNode()); + return NodeDownload.getLink(schem.getNode()); } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/NodeDownload.java b/SpigotCore_Main/src/de/steamwar/sql/NodeDownload.java new file mode 100644 index 0000000..acc7a11 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/NodeDownload.java @@ -0,0 +1,49 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import com.google.common.io.BaseEncoding; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.time.Instant; + +public class NodeDownload { + + private static final SQL.Statement createLink = new SQL.Statement("INSERT INTO NodeDownload (NodeId, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)"); + + private static final String BASE = "https://steamwar.de/download.php?schem="; + + public static String getLink(SchematicNode schem){ + if(schem.isDir()) + throw new SecurityException("Can not Download Directorys"); + MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + throw new SecurityException(e); + } + digest.reset(); + digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes()); + String hash = BaseEncoding.base16().encode(digest.digest()); + createLink.update(schem.getId(), hash); + return BASE + hash; + } +}