-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
547 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SPOTIFY_CLIENT_ID=XXX | ||
SPOTIFY_CLIENT_SECRET=XXX | ||
MONGODB_CONNECTION_STRING=XXX | ||
REDIS_CONNECTION_STRING=XXX | ||
MONGODB_URI=XXX | ||
REDIS_URI=XXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
import { | ||
SITE_TITLE, | ||
HOME_PAGE_VIEW_PATH, | ||
CARD_PAGE_VIEW_PATH | ||
} from '../utils/constant.util'; | ||
|
||
// server | ||
export const PORT = process.env.PORT || 8080; | ||
export const HBS_HELPERS = { | ||
siteTitle: () => SITE_TITLE, | ||
homePageView: () => HOME_PAGE_VIEW_PATH, | ||
cardPageView: () => CARD_PAGE_VIEW_PATH, | ||
areEqual: (a: any, b: any) => a === b | ||
}; | ||
|
||
// spotify | ||
export const CLIENT_ID = process.env.SPOTIFY_CLIENT_ID!; | ||
export const CLIENT_SECRET = process.env.SPOTIFY_CLIENT_SECRET!; | ||
export const MONGODB_URI = process.env.MONGODB_CONNECTION_STRING!; | ||
export const REDIS_URI = process.env.REDIS_CONNECTION_STRING!; | ||
|
||
// db | ||
export const MONGODB_URI = process.env.MONGODB_URI!; | ||
export const REDIS_URI = process.env.REDIS_URI!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* according to the dotenv docs and "The Twelve-Factor App" methodology, an app's config (stored in environment variables) is | ||
* unique to each environment and should be kept separate from code. therefore: | ||
* 1. there should only be 1 `.env` file per environement: https://github.com/motdotla/dotenv#should-i-have-multiple-env-files | ||
* 2. `.env` files should never be committed to version control: https://github.com/motdotla/dotenv#should-i-commit-my-env-file | ||
* `.env.example` files are an obvious exception. further reading: https://12factor.net/config | ||
*/ | ||
import 'dotenv/config'; | ||
import mongoose from 'mongoose'; | ||
import app from './app'; | ||
import Redis from './models/redis.model'; | ||
import { PORT, MONGODB_URI } from './config/index.config'; | ||
|
||
mongoose | ||
.connect(MONGODB_URI) | ||
.then(() => { | ||
return Redis.connect(); | ||
}) | ||
.then(() => { | ||
app.listen(PORT, () => | ||
console.log(`running server on http://localhost:${PORT}`) | ||
); | ||
}) | ||
.catch((error) => console.log(error)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Redis from './redis.model'; | ||
import { Item, isTrack } from '../interfaces/item.interface'; | ||
import StringMap from '../interfaces/map.interface'; | ||
import { getBase64DataFromImageUrl } from '../utils/image.util'; | ||
|
||
export default class Image { | ||
static async getImageDataMap(items: Item[]) { | ||
const map: StringMap = {}; | ||
for (const item of items) { | ||
if (!item) continue; | ||
const imageUrl = isTrack(item) ? item.albumImageUrl : item.imageUrl; | ||
const imageUrlArray = imageUrl.split('/'); | ||
const imageId = imageUrlArray[imageUrlArray.length - 1]; | ||
map[imageUrl] = await Redis.getImageDataFromOrSaveToCache(imageId, () => { | ||
return getBase64DataFromImageUrl(imageUrl); | ||
}); | ||
} | ||
return map; | ||
} | ||
} |
Oops, something went wrong.