Sv443 hace 1 año
padre
commit
7ab1418a29
Se han modificado 2 ficheros con 4 adiciones y 3 borrados
  1. 3 2
      src/routes/translations.ts
  2. 1 1
      src/utils.ts

+ 3 - 2
src/routes/translations.ts

@@ -11,11 +11,12 @@ export function initTranslationsRoutes(router: Router) {
   });
 
   router.get("/translations/:songId", async (req, res) => {
+    const { format: fmt, preferLang: prLang } = req.query;
+    const format: string = fmt ? String(fmt) : "json";
+
     try {
       const { songId } = req.params;
-      const { format: fmt, preferLang: prLang } = req.query;
 
-      const format: string = fmt ? String(fmt) : "json";
       const preferLang = paramValid(prLang) && langCodes.has(prLang.toLowerCase()) ? prLang.toLowerCase() : undefined;
 
       if(!paramValid(songId) || isNaN(Number(songId)))

+ 1 - 1
src/utils.ts

@@ -3,7 +3,7 @@ import { Stringifiable, byteLength } from "svcorelib";
 import { parse as jsonToXml } from "js2xmlparser";
 import { ResponseType } from "./types";
 
-/** Checks if the value of a passed URL parameter is valid */
+/** Checks if the value of a passed URL parameter is a string with length > 0 */
 export function paramValid(val: unknown): val is string {
   return typeof val === "string" && val.length > 0;
 }