Skip to content

Commit

Permalink
feat: add missing debugging logs in search service
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdonado committed Oct 19, 2023
1 parent 2be5797 commit 3af9156
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ export const app = new Elysia()
.use(html())
.use(staticPlugin({ prefix: '' }))
.on('beforeHandle', ({ request }) => {
logger.info({
url: request.url,
method: request.method,
headers: {
host: request.headers.get('host'),
'user-agent': request.headers.get('user-agent'),
},
body: request.body,
});
logger.info(
`${request.method} ${request.url} - ${request.headers.get('user-agent')} - ${
request.body ? JSON.stringify(request.body) : 'no body'
}`
);
})
.use(apiRouter)
.use(pageRouter);
2 changes: 1 addition & 1 deletion src/services/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getSpotifySearchFromCache = async (id: string) => {
};

export const cacheSpotifySearch = async (spotifyContent: SpotifyContent) => {
await setWithKey(
return setWithKey(
`${config.redis.cacheKey}:${spotifyContent.id}`,
JSON.stringify(spotifyContent),
true
Expand Down
13 changes: 13 additions & 0 deletions src/services/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getYouTubeLink } from '~/adapters/youtube';
import { getDeezerLink } from '~/adapters/deezer';
import { getSoundCloudLink } from '~/adapters/soundcloud';
import { getTidalLink } from '~/adapters/tidal';
import { logger } from '~/utils/logger';

export enum SpotifyContentLinkType {
YouTube = 'youTube',
Expand Down Expand Up @@ -41,9 +42,14 @@ export const spotifySearch = async (spotifyLink: string): Promise<SpotifyContent

const id = (spotifyLink.match(SPOTIFY_ID_REGEX) ?? [])[0]!;

logger.info(`Searching for: ${id}`);

const cache = await getSpotifySearchFromCache(id);
if (cache) {
await incrementSearchCount();

logger.info(`Found in cache: ${id}`);

return cache;
}

Expand All @@ -53,6 +59,13 @@ export const spotifySearch = async (spotifyLink: string): Promise<SpotifyContent
getDeezerLink(metadata),
]);

logger.info(
`Search results:
appleMusic: ${appleMusicLink !== undefined},
youtube: ${youtubeLink !== undefined},
deezer: ${deezerLink! !== undefined}`
);

const soundcloudLink = getSoundCloudLink(metadata);
const tidalLink = getTidalLink(metadata);

Expand Down

0 comments on commit 3af9156

Please sign in to comment.