Explorar o código

feat: finalize ts migration

Sv443 %!s(int64=2) %!d(string=hai) anos
pai
achega
97e2de28b6
Modificáronse 4 ficheiros con 9 adicións e 6 borrados
  1. 1 1
      src/error.ts
  2. 3 3
      src/server.ts
  3. 2 2
      src/songMeta.ts
  4. 3 0
      src/types.d.ts

+ 1 - 1
src/error.ts

@@ -1,4 +1,4 @@
-const k = require("kleur");
+import k from "kleur";
 
 /**
  * Handles an error

+ 3 - 3
src/server.ts

@@ -1,5 +1,5 @@
 import compression from "compression";
-import express, { ErrorRequestHandler, NextFunction, Request, Response } from "express";
+import express, { NextFunction, Request, Response } from "express";
 import { check as portUsed } from "tcp-port-used";
 import helmet from "helmet";
 import { RateLimiterMemory, RateLimiterRes } from "rate-limiter-flexible";
@@ -10,8 +10,8 @@ import jsonToXml from "js2xmlparser";
 import packageJson from "../package.json";
 import { error } from "./error";
 import { getMeta } from "./songMeta";
-import { ResponseType } from "./types";
-import { Errors, Stringifiable } from "svcorelib";
+import type { ResponseType } from "./types";
+import type { Stringifiable } from "svcorelib";
 
 const app = express();
 

+ 2 - 2
src/songMeta.ts

@@ -92,10 +92,10 @@ export async function getMeta({ q, artist, song }: Partial<Record<"q" | "artist"
             addScores(artistFuse.search(artist));
 
             const bestMatches = Object.entries(scoreMap)
-                .sort(([, valA], [, valB]) => valA > valB ? 1 : -1) // TODO: check
+                .sort(([, valA], [, valB]) => valA > valB ? 1 : -1)
                 .map(e => e[0]);
 
-            const oldHits = reserialize(hits as unknown as JSONCompatible) as unknown as SearchHit[];
+            const oldHits = [...hits];
 
             hits = bestMatches
                 .map(uuid => oldHits.find(h => h.uuid === uuid))

+ 3 - 0
src/types.d.ts

@@ -7,6 +7,7 @@ interface Artist {
     headerImage: string | null;
 }
 
+/** geniURL song meta object */
 export interface SongMeta {
     url: string | null;
     path: string | null;
@@ -38,12 +39,14 @@ export type ResponseFormat = "json" | "xml";
 
 //#SECTION API
 
+/** The entire object returned by the search endpoint of the genius API */
 export type ApiSearchResult = {
     response: {
         hits: SearchHit[];
     };
 };
 
+/** One search result returned by the genius API */
 export type SearchHit = {
     type: "song";
     result: {