1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-18 16:08:03 +00:00

use 31bit random hex id

This commit is contained in:
Nebel 2022-08-29 10:39:16 +09:00
parent ae22560a87
commit 887eafef4d
4 changed files with 10 additions and 4 deletions

View file

@ -38,7 +38,9 @@ export default () => {
<a href="/new">📄</a>
</header>
{routes[pathname()] ?? (
<Page id={Number(pathname().slice(1)) || random()} />
<Page
id={parseInt(pathname().slice(1), 16) || random()}
/>
)}
</>
);

View file

@ -1,5 +1,5 @@
function random(): number {
return window.crypto.getRandomValues(new Uint16Array(1))[0]!;
return 0x7f_ff_ff_ff & window.crypto.getRandomValues(new Uint32Array(1))[0]!;
}
export default random;

View file

@ -20,7 +20,7 @@ export default () => {
<Cards>
<For each={pages()}>
{(page) => (
<a href={`/${page.id}`}>
<a href={`/${page.id.toString(16)}`}>
<Card {...page} />
</a>
)}

View file

@ -44,7 +44,11 @@ export default (props: { id: number }) => {
async (id: number, content: Pages.RequestContentPage) => {
if (await (content.text ? updatePage(id, content) : deletePage(id))) {
unblock();
window.history.replaceState({}, "", `/${content.text ? id : "new"}`);
window.history.replaceState(
{},
"",
`/${content.text ? id.toString(16) : "new"}`
);
}
},
intervalMs