mirror of
https://github.com/journey-ad/Moe-Counter.git
synced 2024-11-27 17:00:51 +01:00
feat: Strictly limit parameter types
This commit is contained in:
parent
5ae1921530
commit
09fb0186d0
6
index.js
6
index.js
@ -35,8 +35,8 @@ app.get(["/@:name", "/get/@:name"],
|
||||
}),
|
||||
query: z.object({
|
||||
theme: z.string().default("moebooru"),
|
||||
num: z.coerce.number().min(0).max(1000000000000000).default(0), // a carry-safe integer, less than `2^53-1`, and aesthetically pleasing in decimal.
|
||||
padding: z.coerce.number().min(0).max(16).default(7),
|
||||
num: z.coerce.number().int().min(0).max(1e15).default(0), // a carry-safe integer, less than `2^53-1`, and aesthetically pleasing in decimal.
|
||||
padding: z.coerce.number().int().min(0).max(16).default(7),
|
||||
offset: z.coerce.number().min(-500).max(500).default(0),
|
||||
align: z.enum(["top", "center", "bottom"]).default("top"),
|
||||
scale: z.coerce.number().min(0.1).max(2).default(1),
|
||||
@ -54,7 +54,7 @@ app.get(["/@:name", "/get/@:name"],
|
||||
"cache-control": "max-age=0, no-cache, no-store, must-revalidate",
|
||||
});
|
||||
|
||||
const data = await getCountByName(name, num);
|
||||
const data = await getCountByName(String(name), Number(num));
|
||||
|
||||
if (name === "demo") {
|
||||
res.set("cache-control", "max-age=31536000");
|
||||
|
@ -45,8 +45,9 @@ function getCountImage(params) {
|
||||
let { count, theme = 'moebooru', padding = 7, offset = 0, align = 'top', scale = 1, pixelated = '1', darkmode = 'auto' } = params
|
||||
|
||||
if (!(theme in themeList)) theme = 'moebooru'
|
||||
padding = parseInt(padding, 10)
|
||||
offset = parseInt(offset, 10)
|
||||
padding = parseInt(Number(padding), 10)
|
||||
offset = parseFloat(Number(offset), 10)
|
||||
scale = parseFloat(Number(scale), 10)
|
||||
|
||||
// This is not the greatest way for generating an SVG but it'll do for now
|
||||
const countArray = count.toString().padStart(padding, '0').split('')
|
||||
|
@ -135,7 +135,7 @@ html
|
||||
td: code num
|
||||
td Set counter display number, 0 for disable, default is
|
||||
code 0
|
||||
td: input#num(type='number', value='0', min='0', max='1000000000000000', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")')
|
||||
td: input#num(type='number', value='0', min='0', max='1e15', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")')
|
||||
|
||||
button#get(onclick='_evt_push("click", "normal", "get_counter")') Generate
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user