mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-05-07 21:19:08 -05:00
Update user w/ plex token and URL
This commit is contained in:
@@ -3,7 +3,7 @@ import plexService from '../services/plex';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/auth', plexService.getAuthToken);
|
||||
router.get('/token', plexService.getAuthToken);
|
||||
|
||||
router.get('/users', plexService.getUsers);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
plexServerUrl: {
|
||||
plexUrl: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
plexToken: {
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
lastName: DataTypes.STRING,
|
||||
googleId: DataTypes.STRING,
|
||||
email: {type: DataTypes.STRING, unique: true},
|
||||
plexServerUrl: DataTypes.STRING,
|
||||
plexUrl: DataTypes.STRING,
|
||||
plexToken: DataTypes.STRING,
|
||||
},
|
||||
{},
|
||||
|
||||
@@ -18,9 +18,13 @@ const encryptUserCreds = (username, password) => {
|
||||
};
|
||||
|
||||
const fetchToken = async (username, password) => {
|
||||
const res = await request.post(urlParams(username, password));
|
||||
const token = res.match(rxAuthToken)[1];
|
||||
return token;
|
||||
try {
|
||||
const res = await request.post(urlParams(username, password));
|
||||
const token = res.match(rxAuthToken)[1];
|
||||
return token;
|
||||
} catch (error) {
|
||||
return error.message;
|
||||
}
|
||||
};
|
||||
|
||||
export default fetchToken;
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
import plexApi from './plexApi';
|
||||
import importData from './importData';
|
||||
import auth from './auth';
|
||||
import models from '../../db/models';
|
||||
import helpers from '../helpers';
|
||||
|
||||
const getAuthToken = async (req, res) => {
|
||||
const {username} = req.query;
|
||||
const {password} = req.query;
|
||||
console.log('Mikes stuff', username, password);
|
||||
const token = await auth(username, password);
|
||||
// req.user.plexToken = token;
|
||||
// const user = await req.user.save();
|
||||
return res.json(token);
|
||||
try {
|
||||
const {email, password, plexUrl} = req.query;
|
||||
const plexToken = await auth(email, password);
|
||||
const [rowsUpdate, updatedUser] = await models.User.update(
|
||||
{plexUrl, plexToken},
|
||||
{returning: true, where: {googleId: req.user.googleId}},
|
||||
);
|
||||
console.log('updatedUser', updatedUser);
|
||||
console.log('token', plexToken);
|
||||
|
||||
return res.json(updatedUser);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
return res.status(201).json(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const getUsers = (req, res) => {
|
||||
|
||||
@@ -13,7 +13,7 @@ const getUsersUrlParams = function(token) {
|
||||
|
||||
const getSectionsUrlParams = function() {
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
host: config.plex.plexUrl,
|
||||
path: '/library/sections',
|
||||
queryParams: {
|
||||
'X-Plex-Token': config.plex.token,
|
||||
@@ -23,7 +23,7 @@ const getSectionsUrlParams = function() {
|
||||
|
||||
const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
host: config.plex.plexUrl,
|
||||
path: '/library/all/top',
|
||||
queryParams: {
|
||||
...(accountId && {accountId}),
|
||||
@@ -36,7 +36,7 @@ const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
|
||||
|
||||
const getLibraryDataBySectionUrlParams = function(sectionId) {
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
host: config.plex.plexUrl,
|
||||
path: `/library/sections/${sectionId}/all`,
|
||||
queryParams: {
|
||||
'X-Plex-Token': config.plex.token,
|
||||
|
||||
Reference in New Issue
Block a user