소스 검색

fixed format param

Sv443 3 년 전
부모
커밋
1d6fb221f8
2개의 변경된 파일13개의 추가작업 그리고 17개의 파일을 삭제
  1. 7 11
      README.md
  2. 6 6
      src/server.js

+ 7 - 11
README.md

@@ -1,7 +1,7 @@
 # geniURL
 
-Simple JSON "REST proxy" to search for lyrics metadata on [genius](https://genius.com/).  
-Obtaining actual lyrics sadly isn't possible.
+Simple JSON and XML "REST proxy" to search for song and lyrics metadata on [genius.](https://genius.com/)  
+Obtaining actual lyrics sadly isn't possible yet.
 
 <br><br>
 
@@ -13,7 +13,10 @@ I host a public instance on this URL:
 https://api.sv443.net/geniurl/
 ```
 
-<br>
+Note that this instance is rate limited to 8 requests in 10 seconds.  
+If you want to host your own and increase the values, look at the top of `src/server.js`
+
+<br><br>
 
 ## Routes:
 
@@ -145,14 +148,7 @@ All routes support gzip and deflate compression.
 >
 > </details><br>
 
-<br>
-
-## Rate Limiting
-
-My public API instance is rate limited to 8 requests in 10 seconds.  
-If you want to host your own instance and increase the values, look at the top of `src/server.js`
-
-<br><br><br>
+<br><br>
 
 <div align="center" style="text-align:center;">
 

+ 6 - 6
src/server.js

@@ -39,7 +39,7 @@ async function init()
     // on error
     app.use((err, req, res, next) => {
         if(typeof err === "string" || err instanceof Error)
-            return respond(res, "serverError", `General error in HTTP server: ${err.toString()}`, req?.params?.format);
+            return respond(res, "serverError", `General error in HTTP server: ${err.toString()}`, req?.query?.format);
         else
             return next();
     });
@@ -56,7 +56,7 @@ async function init()
             catch(rlRejected)
             {
                 res.set("Retry-After", rlRejected?.msBeforeNext ? String(Math.round(rlRejected.msBeforeNext / 1000)) || 1 : 1);
-                return respond(res, 429, { message: "You are being rate limited" }, req?.params?.format);
+                return respond(res, 429, { message: "You are being rate limited" }, req?.query?.format);
             }
 
             return next();
@@ -82,25 +82,25 @@ function registerEndpoints()
             const { q, format } = req.query;
 
             if(typeof q !== "string" || q.length === 0)
-                return respond(res, "clientError", "No query parameter (?q=...) provided or it is invalid", req?.params?.format);
+                return respond(res, "clientError", "No query parameter (?q=...) provided or it is invalid", req?.query?.format);
 
             const meta = await getMeta(q);
 
             // js2xmlparser needs special treatment when using arrays to produce a good XML structure
             const response = format === "xml" ? { top: meta.top, all: { "result": meta.all } } : meta;
 
-            return respond(res, "success", response, req?.params?.format);
+            return respond(res, "success", response, req?.query?.format);
         });
 
         app.get("/search/top", async (req, res) => {
             const { q } = req.query;
 
             if(typeof q !== "string" || q.length === 0)
-                return respond(res, "clientError", "No query parameter (?q=...) provided or it is invalid", req?.params?.format);
+                return respond(res, "clientError", "No query parameter (?q=...) provided or it is invalid", req?.query?.format);
 
             const meta = await getMeta(q);
 
-            return respond(res, "success", meta.top, req?.params?.format);
+            return respond(res, "success", meta.top, req?.query?.format);
         });
     }
     catch(err)