Filter plex servers based on most recently updated

This commit is contained in:
Mike Rode
2019-09-01 15:32:59 -05:00
parent 9f1296d30a
commit dec2005eed
7 changed files with 23 additions and 17 deletions

View File

@@ -10,7 +10,7 @@
"scripts": {
"test": "cross-env NODE_ENV=test PLEX_API_TOKEN=testPlexApiToken TDAW_API_TOKEN=testTdawToken nyc --reporter=html --reporter=text mocha --require babel-core/register 'test/**/*.test.js' --exit",
"db:clean": "npm run db:drop && npm run db:create && npm run db:migrate",
"db:create": "babel-node ./scripts/db/create",
"db:create:test": "NODE_ENV=test npx sequelize db:create",
"db:create-migration": "babel-node ./scripts/db/createMigration",
"db:drop": "babel-node ./scripts/db/drop",
"db:migrate": "babel-node ./scripts/db/migrate",

View File

@@ -1,9 +1,18 @@
export default {
User: [
{
firstName: 'Mike',
id: 1,
firstName: 'Michael',
lastName: 'Rode',
email: 'mike@email.com',
googleId: '101111197386111111151',
email: 'michaelrode44@gmail.com',
plexUrl: 'http://99.99.99.993:32400',
plexPinId: '5425341',
plexToken: 'MkaxxxxxxxJBGJxxxcV2',
sonarrUrl: null,
sonarrApiKey: null,
createdAt: '2019-09-01 14:36:57.418-05',
updatedAt: '2019-09-01 14:37:09.415-05',
},
],
};

View File

@@ -81,15 +81,16 @@ const getPlexUrl = async (plexToken, user) => {
const res = await request.get(plexUrlParams(plexToken, user));
let formattedResponse = JSON.parse(parser.toJson(res)).MediaContainer
.Server;
if (!Array.isArray(formattedResponse)) {
formattedResponse = [formattedResponse];
}
formattedResponse.filter(server => {
server.accessToken === plexToken;
});
console.log('formatted response', formattedResponse);
formattedResponse.reduce((acc, other) =>
acc.createdAt > other.createdAt ? acc : other,
);
const server = formattedResponse.slice(-1)[0];
console.log('server', server);
await models.User.update(
{
plexToken: plexToken.trim(),

View File

@@ -18,11 +18,8 @@ const importTvPosters = async user => {
where: {UserId: user.id, type: 'show', views: {[Op.gt]: 0}},
});
console.log('TCL: mostWatched', mostWatched);
console.log('TCL: mostWatched', mostWatched);
const imageUrls = await mostWatched.map(async show => {
const res = await mdb.searchTv({query: show.title});
console.log('TCL: res', res);
return models.PlexLibrary.update(
{
poster_path: res.results[0].poster_path,

View File

@@ -78,9 +78,7 @@ const getSections = async function(user) {
try {
const urlParams = getSectionsUrlParams(user);
const getSectionsUrl = helpers.buildUrl(urlParams);
console.log('sec -url', getSectionsUrl);
const response = await helpers.request(getSectionsUrl);
console.log('mike-', response);
return response.MediaContainer.Directory;
} catch (error) {
return {
@@ -97,6 +95,7 @@ const getLibraryDataBySection = async function({sectionKey}, user) {
const urlParams = getLibraryDataBySectionUrlParams(sectionKey, user);
const getLibraryDataBySectionUrl = helpers.buildUrl(urlParams);
const response = await helpers.request(getLibraryDataBySectionUrl);
console.log('library-data-by-section---', response.MediaContainer.Metadata);
return response.MediaContainer.Metadata;
} catch (error) {
console.log('caught error', error);

View File

@@ -4,7 +4,7 @@ import app from '../../../../index';
describe('Users', () => {
describe('GET /api/plex/auth', async () => {
it.only('should get plex auth token', done => {
it('should get plex auth token', done => {
nocks.auth();
chai

View File

@@ -18,7 +18,7 @@ describe('ImportData', () => {
});
describe('GET /plex/import/sections', () => {
it('should find and store sections in the database', async () => {
it.only('should find and store sections in the database', async () => {
nocks.plexSections();
await importData.importSections();
const sections = await models.PlexSection.findAll();
@@ -41,7 +41,7 @@ describe('ImportData', () => {
});
describe('GET /plex/import/libraries', () => {
it('should find and store libraries in the database', async () => {
it.only('should find and store libraries in the database', async () => {
nocks.plexSections();
nocks.plexLibrary();
await importData.importLibraries();
@@ -57,7 +57,7 @@ describe('ImportData', () => {
});
describe('GET /plex/import/most-watched', () => {
it('should find and store libraries in the database', async () => {
it.only('should find and store libraries in the database', async () => {
nocks.plexSections();
nocks.plexLibrary();
await importData.importLibraries();