Merge pull request 'Update links and timestamp on multiple link accesses' (#77) from updateLinks into master
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
c69abf4470
@ -23,8 +23,6 @@ import com.google.common.io.BaseEncoding;
|
|||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
public class DownloadSchematic {
|
public class DownloadSchematic {
|
||||||
@ -33,24 +31,16 @@ public class DownloadSchematic {
|
|||||||
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
||||||
|
|
||||||
public static String getLink(Schematic schem){
|
public static String getLink(Schematic schem){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM SchemDownload WHERE SchemID = ?", schem.getSchemID());
|
MessageDigest digest;
|
||||||
try {
|
try {
|
||||||
if(rs.next())
|
digest = MessageDigest.getInstance("SHA-1");
|
||||||
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");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new SecurityException(e);
|
throw new SecurityException(e);
|
||||||
}
|
}
|
||||||
cript.reset();
|
digest.reset();
|
||||||
cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes());
|
digest.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes());
|
||||||
String hash = BaseEncoding.base16().encode(cript.digest());
|
String hash = BaseEncoding.base16().encode(digest.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;
|
return BASE + hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren