From 003918b8d812d46d982f3033e252e958122651a2 Mon Sep 17 00:00:00 2001 From: Pelotfr Date: Thu, 9 Nov 2023 09:22:33 +0100 Subject: [PATCH] Symbol Code parameter verification against dynamic enum --- src/fetch/aggregate.ts | 13 +++++++++++-- src/fetch/sales.ts | 11 ++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/fetch/aggregate.ts b/src/fetch/aggregate.ts index c3bb49e..2cb9f67 100644 --- a/src/fetch/aggregate.ts +++ b/src/fetch/aggregate.ts @@ -1,7 +1,7 @@ import { makeQuery } from "../clickhouse/makeQuery.js"; import { logger } from "../logger.js"; import { store } from "../clickhouse/stores.js"; -import { parseCollectionName } from "../utils.js"; +import { parseCollectionName, parseListingPriceSymcode } from "../utils.js"; import { getAggregate } from "../queries.js"; import * as prometheus from "../prometheus.js"; import { BadRequest, toJSON, toText } from "./cors.js"; @@ -28,10 +28,19 @@ export default async function (req: Request) { async function verifyParameters(req: Request) { const url = new URL(req.url); const collection_name = url.searchParams.get("collection_name"); + const symbol_code = url.searchParams.get("listing_price_symcode"); + if (collection_name && (parseCollectionName(collection_name) == undefined)) { return toText("Invalid EOSIO name type: collection_name=" + collection_name, 400); } else if (collection_name && !(await store.collection_names).includes(collection_name)) { return toText("Collection not found: " + collection_name, 404); } -} + + if (symbol_code && (parseListingPriceSymcode(symbol_code) == undefined)) { + return toText("Invalid EOSIO Symbol code: listing_price_symcode=" + symbol_code, 400); + } + else if (symbol_code && !(await store.symbol_codes).includes(symbol_code)) { + return toText("Symbol code not found: " + symbol_code, 404); + } +} \ No newline at end of file diff --git a/src/fetch/sales.ts b/src/fetch/sales.ts index 966308c..9365aea 100644 --- a/src/fetch/sales.ts +++ b/src/fetch/sales.ts @@ -4,7 +4,7 @@ import { store } from "../clickhouse/stores.js"; import { Sale, getSale } from "../queries.js"; import * as prometheus from "../prometheus.js"; import { BadRequest, toJSON, toText } from "./cors.js"; -import { parseCollectionName } from "../utils.js"; +import { parseCollectionName, parseListingPriceSymcode } from "../utils.js"; export default async function (req: Request) { const parametersResult = await verifyParameters(req); @@ -27,10 +27,19 @@ export default async function (req: Request) { async function verifyParameters(req: Request) { const url = new URL(req.url); const collection_name = url.searchParams.get("collection_name"); + const symbol_code = url.searchParams.get("listing_price_symcode"); + if (collection_name && (parseCollectionName(collection_name) == undefined)) { return toText("Invalid EOSIO name type: collection_name=" + collection_name, 400); } else if (collection_name && !(await store.collection_names).includes(collection_name)) { return toText("Collection not found: " + collection_name, 404); } + + if (symbol_code && (parseListingPriceSymcode(symbol_code) == undefined)) { + return toText("Invalid EOSIO Symbol code: listing_price_symcode=" + symbol_code, 400); + } + else if (symbol_code && !(await store.symbol_codes).includes(symbol_code)) { + return toText("Symbol code not found: " + symbol_code, 404); + } }