@@ -7,6 +7,8 @@
|
|||||||
"prefer-destructuring": 0,
|
"prefer-destructuring": 0,
|
||||||
"camelcase": 0,
|
"camelcase": 0,
|
||||||
"import/no-unresolved": 0,
|
"import/no-unresolved": 0,
|
||||||
"import/no-extraneous-dependencies": 0
|
"import/no-extraneous-dependencies": 0,
|
||||||
|
"object-shorthand": 0,
|
||||||
|
"comma-dangle": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class PlexRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search(query) {
|
search(query) {
|
||||||
|
console.log('searching:', query)
|
||||||
const options = {
|
const options = {
|
||||||
uri: `http://10.0.0.44:32400/search?query=${query}`,
|
uri: `http://10.0.0.44:32400/search?query=${query}`,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -39,7 +40,8 @@ class PlexRepository {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plexResult.results.map((plexItem) => {
|
plexResult.results.map((plexItem) => {
|
||||||
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year) { tmdb.matchedInPlex = true; }
|
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year)
|
||||||
|
tmdb.matchedInPlex = true;
|
||||||
return tmdb;
|
return tmdb;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -50,6 +52,7 @@ class PlexRepository {
|
|||||||
mapResults(response) {
|
mapResults(response) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
console.log('plexResponse:', response)
|
||||||
if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0];
|
if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0];
|
||||||
|
|
||||||
const mappedResults = response.MediaContainer.Metadata.filter((element) => {
|
const mappedResults = response.MediaContainer.Metadata.filter((element) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const TMDB_METHODS = {
|
|||||||
nowplaying: { movie: 'miscNowPlayingMovies', show: 'tvOnTheAir' },
|
nowplaying: { movie: 'miscNowPlayingMovies', show: 'tvOnTheAir' },
|
||||||
similar: { movie: 'movieSimilar', show: 'tvSimilar' },
|
similar: { movie: 'movieSimilar', show: 'tvSimilar' },
|
||||||
search: { movie: 'searchMovie', show: 'searchTv', multi: 'searchMulti' },
|
search: { movie: 'searchMovie', show: 'searchTv', multi: 'searchMulti' },
|
||||||
info: { movie: 'movieInfo', show: 'tvInfo' },
|
info: { movie: 'movieInfo', show: 'tvInfo' }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TMDB {
|
class TMDB {
|
||||||
@@ -65,7 +65,7 @@ class TMDB {
|
|||||||
.catch(() => this.tmdb(TMDB_METHODS['search'][type], query))
|
.catch(() => this.tmdb(TMDB_METHODS['search'][type], query))
|
||||||
.catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); })
|
.catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); })
|
||||||
.then(response => this.cache.set(cacheKey, response))
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
.then(response => this.mapResults(response))
|
.then(response => this.mapResults(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,15 +76,15 @@ class TMDB {
|
|||||||
* @returns {Promise} dict with query results, current page and total_pages
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
listSearch(listName, type = 'movie', page = '1') {
|
listSearch(listName, type = 'movie', page = '1') {
|
||||||
const query = { page: page }
|
const query = { page: page };
|
||||||
console.log(query)
|
console.log(query);
|
||||||
const cacheKey = `${this.cacheTags[listName]}:${type}:${page}`;
|
const cacheKey = `${this.cacheTags[listName]}:${type}:${page}`;
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.cache.get(cacheKey))
|
.then(() => this.cache.get(cacheKey))
|
||||||
.catch(() => this.tmdb(TMDB_METHODS[listName][type], query))
|
.catch(() => this.tmdb(TMDB_METHODS[listName][type], query))
|
||||||
.catch(() => { throw new Error('Error fetching list from tmdb.')})
|
.catch(() => { throw new Error('Error fetching list from tmdb.'); })
|
||||||
.then(response => this.cache.set(cacheKey, response))
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
.then(response => this.mapResults(response, type))
|
.then(response => this.mapResults(response, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,13 +94,18 @@ class TMDB {
|
|||||||
* @returns {Promise} dict with tmdb results, mapped as movie/show objects.
|
* @returns {Promise} dict with tmdb results, mapped as movie/show objects.
|
||||||
*/
|
*/
|
||||||
mapResults(response, type) {
|
mapResults(response, type) {
|
||||||
console.log(response.page)
|
console.log(response.page);
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const mappedResults = response.results.filter((element) => {
|
const mappedResults = response.results.filter((element) => {
|
||||||
return (element.media_type === 'movie' || element.media_type === 'tv' || element.media_type === undefined);
|
return (element.media_type === 'movie' || element.media_type === 'tv' || element.media_type === undefined);
|
||||||
}).map((element) => convertTmdbToSeasoned(element, type));
|
}).map((element) => convertTmdbToSeasoned(element, type));
|
||||||
return {results: mappedResults, page: response.page, total_pages: response.total_pages, total_results: response.total_results}
|
return {
|
||||||
|
results: mappedResults,
|
||||||
|
page: response.page,
|
||||||
|
total_pages: response.total_pages,
|
||||||
|
total_results: response.total_results
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => { throw new Error(error); });
|
.catch((error) => { throw new Error(error); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class UserRepository {
|
|||||||
assert(row, 'The user does not exist.');
|
assert(row, 'The user does not exist.');
|
||||||
return row.password;
|
return row.password;
|
||||||
})
|
})
|
||||||
.catch((err) => console.log('there was a error when getting hash', err));
|
.catch((err) => { console.log(error); throw new Error('Unable to find your user.'); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +57,7 @@ class UserRepository {
|
|||||||
checkAdmin(user) {
|
checkAdmin(user) {
|
||||||
return this.database.get(this.queries.getAdminStateByUser, user.username).then((row) => {
|
return this.database.get(this.queries.getAdminStateByUser, user.username).then((row) => {
|
||||||
return row.admin;
|
return row.admin;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ app.use(bodyParser.json());
|
|||||||
// router.use(bodyParser.urlencoded({ extended: true }));
|
// router.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
|
||||||
/* Decode the Authorization header if provided */
|
|
||||||
// router.use(tokenToUser);
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
||||||
|
|
||||||
@@ -27,9 +24,7 @@ const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
|||||||
// router.use(bodyParser.json());
|
// router.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
/* Decode the Authorization header if provided */
|
||||||
// This is probably a correct middleware/router setup
|
|
||||||
/* Translate the user token to a user name */
|
|
||||||
router.use(tokenToUser);
|
router.use(tokenToUser);
|
||||||
|
|
||||||
// TODO: Should have a separate middleware/router for handling headers.
|
// TODO: Should have a separate middleware/router for handling headers.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -10,7 +10,7 @@ const searchHistory = new SearchHistory();
|
|||||||
function searchRequestController(req, res) {
|
function searchRequestController(req, res) {
|
||||||
const user = req.loggedInUser;
|
const user = req.loggedInUser;
|
||||||
const { query, page, type } = req.query;
|
const { query, page, type } = req.query;
|
||||||
const username = user == undefined ? undefined : user.username;
|
const username = user === undefined ? undefined : user.username;
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => searchHistory.create(username, query))
|
.then(() => searchHistory.create(username, query))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const searchHistory = new SearchHistory();
|
|||||||
*/
|
*/
|
||||||
function historyController(req, res) {
|
function historyController(req, res) {
|
||||||
const user = req.loggedInUser;
|
const user = req.loggedInUser;
|
||||||
const username = user == undefined ? undefined : user.username;
|
const username = user === undefined ? undefined : user.username;
|
||||||
|
|
||||||
searchHistory.read(username)
|
searchHistory.read(username)
|
||||||
.then((searchQueries) => {
|
.then((searchQueries) => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function loginController(req, res) {
|
|||||||
.then(() => userRepository.checkAdmin(user))
|
.then(() => userRepository.checkAdmin(user))
|
||||||
.then((checkAdmin) => {
|
.then((checkAdmin) => {
|
||||||
const token = new Token(user).toString(secret);
|
const token = new Token(user).toString(secret);
|
||||||
const admin_state = checkAdmin == 1 ? true : false;
|
const admin_state = checkAdmin === 1 ? true : false;
|
||||||
res.send({ success: true, token, admin: admin_state });
|
res.send({ success: true, token, admin: admin_state });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ function registerController(req, res) {
|
|||||||
.then(() => userRepository.checkAdmin(user))
|
.then(() => userRepository.checkAdmin(user))
|
||||||
.then((checkAdmin) => {
|
.then((checkAdmin) => {
|
||||||
const token = new Token(user).toString(secret);
|
const token = new Token(user).toString(secret);
|
||||||
const admin_state = checkAdmin == 1 ? true : false;
|
const admin_state = checkAdmin === 1 ? true : false;
|
||||||
res.send({ success: true, message: 'Welcome to Seasoned!', token, admin: admin_state });
|
res.send({
|
||||||
|
success: true, message: 'Welcome to Seasoned!', token, admin: admin_state,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(401).send({ success: false, error: error.message });
|
res.status(401).send({ success: false, error: error.message });
|
||||||
|
|||||||
Reference in New Issue
Block a user