Skip to content

Commit

Permalink
Update HasRandomIDAndLegacyTimeBasedID.php - Album ID Generation (#2554)
Browse files Browse the repository at this point in the history
* Update HasRandomIDAndLegacyTimeBasedID.php

Modification of ID generation based on recommendation by associate who is a PHP developer. This will avoid having a hyphen at the end of URLs which seems to cause issues with certain apps/devices that do URL parsing.

---------

Co-authored-by: ildyria <[email protected]>
  • Loading branch information
jessienab and ildyria authored Oct 4, 2024
1 parent b71138f commit a50c04e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ private function generateKey(): void
// As the number of bytes is divisible by 3, no trailing `=` occurs.
try {
$id = strtr(base64_encode(random_bytes(3 * RandomID::ID_LENGTH / 4)), '+/', '-_');
// Last character whould not be a - for some version of android.
// this will reduce the entropy and induce a slight bias but we are still
// above the birthday bounds.
if ($id[23] === '-') {
$id[23] = '0';
}
} catch (\Exception $e) {
throw new InsufficientEntropyException($e);
}
Expand Down

0 comments on commit a50c04e

Please sign in to comment.