mirror of
https://github.com/kou029w/quot.git
synced 2025-01-19 00:18:09 +00:00
use 31bit random hex id
This commit is contained in:
parent
ae22560a87
commit
887eafef4d
4 changed files with 10 additions and 4 deletions
|
@ -38,7 +38,9 @@ export default () => {
|
||||||
<a href="/new">📄</a>
|
<a href="/new">📄</a>
|
||||||
</header>
|
</header>
|
||||||
{routes[pathname()] ?? (
|
{routes[pathname()] ?? (
|
||||||
<Page id={Number(pathname().slice(1)) || random()} />
|
<Page
|
||||||
|
id={parseInt(pathname().slice(1), 16) || random()}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function random(): number {
|
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;
|
export default random;
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default () => {
|
||||||
<Cards>
|
<Cards>
|
||||||
<For each={pages()}>
|
<For each={pages()}>
|
||||||
{(page) => (
|
{(page) => (
|
||||||
<a href={`/${page.id}`}>
|
<a href={`/${page.id.toString(16)}`}>
|
||||||
<Card {...page} />
|
<Card {...page} />
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -44,7 +44,11 @@ export default (props: { id: number }) => {
|
||||||
async (id: number, content: Pages.RequestContentPage) => {
|
async (id: number, content: Pages.RequestContentPage) => {
|
||||||
if (await (content.text ? updatePage(id, content) : deletePage(id))) {
|
if (await (content.text ? updatePage(id, content) : deletePage(id))) {
|
||||||
unblock();
|
unblock();
|
||||||
window.history.replaceState({}, "", `/${content.text ? id : "new"}`);
|
window.history.replaceState(
|
||||||
|
{},
|
||||||
|
"",
|
||||||
|
`/${content.text ? id.toString(16) : "new"}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
intervalMs
|
intervalMs
|
||||||
|
|
Loading…
Add table
Reference in a new issue