From f00ffb32a585837b556d27f548447c3315472a7f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 19 Dec 2020 09:22:50 +0100 Subject: [PATCH 1/2] Update links and timestamp on multiple link accesses --- .../src/de/steamwar/sql/DownloadSchematic.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java index 567aad6..a656902 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java @@ -23,8 +23,6 @@ import com.google.common.io.BaseEncoding; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.sql.ResultSet; -import java.sql.SQLException; import java.time.Instant; public class DownloadSchematic { @@ -33,14 +31,6 @@ public class DownloadSchematic { private static final String BASE = "https://steamwar.de/download.php?schem="; public static String getLink(Schematic schem){ - ResultSet rs = SQL.select("SELECT * FROM SchemDownload WHERE SchemID = ?", schem.getSchemID()); - try { - if(rs.next()) - return BASE + rs.getString("Link"); - } catch (SQLException e) { - throw new SecurityException("Could not check schematic for existance", e); - } - MessageDigest cript; try { cript = MessageDigest.getInstance("SHA-1"); @@ -50,7 +40,7 @@ public class DownloadSchematic { cript.reset(); cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes()); String hash = BaseEncoding.base16().encode(cript.digest()); - SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?)", schem.getSchemID(), hash); + SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)", schem.getSchemID(), hash); return BASE + hash; } } From dba63ffa901e6ff42d882bfb58ac4c66174eb899 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 19 Dec 2020 12:19:01 +0100 Subject: [PATCH 2/2] Fix naming --- .../src/de/steamwar/sql/DownloadSchematic.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java index a656902..4f55754 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java @@ -31,15 +31,15 @@ public class DownloadSchematic { private static final String BASE = "https://steamwar.de/download.php?schem="; public static String getLink(Schematic schem){ - MessageDigest cript; + MessageDigest digest; try { - cript = MessageDigest.getInstance("SHA-1"); + digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new SecurityException(e); } - cript.reset(); - cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes()); - String hash = BaseEncoding.base16().encode(cript.digest()); + digest.reset(); + digest.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes()); + String hash = BaseEncoding.base16().encode(digest.digest()); SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)", schem.getSchemID(), hash); return BASE + hash; }