mirror of
https://github.com/Wolvan/poll.horse.git
synced 2024-11-22 04:58:00 +01:00
Avoid ambigous characters in IDs
The issue with ambigous characters is that they are hard to write when only seeing them, as one could confuse 0 for O with certain typefaces for example. Ambiguity is lessened by removing `Oo0Iil1` from the possible charset. In order to keep a big enough pool of IDs the ID length changed from 6 to 8 characters instead, which seems like an OK tradeoff.
This commit is contained in:
parent
9d80a009ca
commit
584d0092d8
1 changed files with 2 additions and 2 deletions
|
@ -17,7 +17,7 @@ type Poll = {
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
};
|
};
|
||||||
|
|
||||||
function randomString(length = 10, charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
|
function randomString(length = 10, charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789") {
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
result += charset.charAt(Math.floor(Math.random() * charset.length));
|
result += charset.charAt(Math.floor(Math.random() * charset.length));
|
||||||
|
@ -76,7 +76,7 @@ export default async function init(router: Router): Promise<void> {
|
||||||
const options = req.body.options;
|
const options = req.body.options;
|
||||||
if (!Array.isArray(options) || options.filter(i => i).length < 2)
|
if (!Array.isArray(options) || options.filter(i => i).length < 2)
|
||||||
return res.status(400).json({ error: "Options must be an array and have at least 2 entries" });
|
return res.status(400).json({ error: "Options must be an array and have at least 2 entries" });
|
||||||
let id = randomString(6);
|
let id = randomString(8);
|
||||||
while (await polls.getItem(id)) id = randomString(6);
|
while (await polls.getItem(id)) id = randomString(6);
|
||||||
await polls.setItem(id, {});
|
await polls.setItem(id, {});
|
||||||
const dupeCheckMode = ["none", "ip", "cookie"].includes(req.body.dupeCheckMode) ? req.body.dupeCheckMode : "ip";
|
const dupeCheckMode = ["none", "ip", "cookie"].includes(req.body.dupeCheckMode) ? req.body.dupeCheckMode : "ip";
|
||||||
|
|
Loading…
Reference in a new issue