forked from AkkomaGang/akkoma
Flake: support integers in from_string/1
Some previously issued stateless tokens have integer ids in them.
This commit is contained in:
parent
6383fa3a5d
commit
d6015338c8
2 changed files with 5 additions and 0 deletions
|
@ -33,6 +33,10 @@ def to_string(flake = <<_::integer-size(64), _::integer-size(48), _::integer-siz
|
|||
|
||||
def to_string(s), do: s
|
||||
|
||||
def from_string(int) when is_integer(int) do
|
||||
from_string(Kernel.to_string(int))
|
||||
end
|
||||
|
||||
for i <- [-1, 0] do
|
||||
def from_string(unquote(i)), do: <<0::integer-size(128)>>
|
||||
def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>>
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.FlakeIdTest do
|
|||
test "from_string/1" do
|
||||
fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
|
||||
assert from_string("42") == fake_flake
|
||||
assert from_string(42) == fake_flake
|
||||
end
|
||||
|
||||
test "zero or -1 is a null flake" do
|
||||
|
|
Loading…
Reference in a new issue