Fixed hash lookup and improved ID generation.
This commit is contained in:
parent
3df891921c
commit
0005813d4b
1 changed files with 5 additions and 7 deletions
|
@ -193,13 +193,11 @@ final class Upload implements JsonSerializable {
|
|||
}
|
||||
|
||||
public static function generateId(int $length = 32): string {
|
||||
$token = random_bytes($length);
|
||||
$bytes = str_repeat("\0", $length);
|
||||
$chars = strlen(self::ID_CHARS);
|
||||
|
||||
for($i = 0; $i < $length; $i++)
|
||||
$token[$i] = self::ID_CHARS[ord($token[$i]) % $chars];
|
||||
|
||||
return $token;
|
||||
for($i = 0; $i < $length; ++$i)
|
||||
$bytes[$i] = self::ID_CHARS[random_int(0, $chars - 1)];
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
public static function create(
|
||||
|
@ -293,7 +291,7 @@ final class Upload implements JsonSerializable {
|
|||
. ' UNIX_TIMESTAMP(`upload_dmca`) AS `upload_dmca`,'
|
||||
. ' INET6_NTOA(`upload_ip`) AS `upload_ip`,'
|
||||
. ' LOWER(HEX(`upload_hash`)) AS `upload_hash`'
|
||||
. ' FROM `prm_uploads` WHERE `upload_id` = `upload_hash` = UNHEX(?)'
|
||||
. ' FROM `prm_uploads` WHERE `upload_hash` = UNHEX(?)'
|
||||
);
|
||||
$get->addParameter(1, $hash, DbType::STRING);
|
||||
$get->execute();
|
||||
|
|
Loading…
Reference in a new issue