Skip to content

Commit

Permalink
Fix couchpotato when basic auth is used
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceK33z committed Dec 12, 2016
1 parent 013192a commit 4dbab16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let plexToken = '';
let plexMachineId;
let couchpotatoUrlRoot = '';
let couchpotatoToken = '';
let couchpotatoBasicAuth = null;

function isMoviePage() {
const path = window.location.pathname;
Expand Down Expand Up @@ -52,6 +53,12 @@ chrome.storage.sync.get(null, function(items) {
plexMachineId = items.plexMachineId;
couchpotatoUrlRoot = items.couchpotatoUrlRoot;
couchpotatoToken = items.couchpotatoToken;
if (items.couchpotatoBasicAuthUsername) {
couchpotatoBasicAuth = {
username: items.couchpotatoBasicAuthUsername,
password: items.couchpotatoBasicAuthPassword,
};
}

if (!plexToken || !plexMachineId || !items.plexLibraryId || !items.plexUrlRoot) {
showNotification('warning', 'Not all options for the Movieo to Plex extension are filled in.');
Expand Down Expand Up @@ -170,8 +177,7 @@ function addToCouchpotato(action) {
}
axios.get(viewUrl, {
params: { id: imdbId },
headers: {
},
auth: couchpotatoBasicAuth,
})
.then((res) => {
const movieExists = res.data.success;
Expand All @@ -191,9 +197,7 @@ function addToCouchpotato(action) {
function addToCouchPotatoRequest(url, imdbId) {
axios.get(url, {
params: { identifier: imdbId },
headers: {
Authorization: 'Basic a2Vlczpib25rZXJzdGVpbg==',
},
auth: couchpotatoBasicAuth,
})
.then((res) => {
showNotification('info', 'Added movie on CouchPotato.');
Expand Down
12 changes: 12 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
<strong>Example:</strong> aa756d33242f6g8ffbca2b3963586f21
</p>

<p>
CouchPotato basic auth username <em>(optional)</em>:
<input type="text" id="couchpotato_basic_auth_username"><br>
If you password-protected your CouchPotato install, enter the username here.
</p>

<p>
CouchPotato basic auth password <em>(optional)</em>:
<input type="text" id="couchpotato_basic_auth_password"><br>
If you password-protected your CouchPotato install, enter the password here.
</p>

<div id="status"></div>
<button id="save">Save</button>

Expand Down
6 changes: 6 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ function saveOptions() {
var plexLibraryId = document.getElementById('plex_library_id').value;
var couchpotatoUrlRoot = document.getElementById('couchpotato_url_root').value;
var couchpotatoToken = document.getElementById('couchpotato_token').value;
var couchpotatoBasicAuthUsername = document.getElementById('couchpotato_basic_auth_username').value;
var couchpotatoBasicAuthPassword = document.getElementById('couchpotato_basic_auth_password').value;
chrome.storage.sync.set({
plexToken,
plexMachineId,
plexUrlRoot,
plexLibraryId,
couchpotatoUrlRoot,
couchpotatoToken,
couchpotatoBasicAuthUsername,
couchpotatoBasicAuthPassword,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
Expand All @@ -34,6 +38,8 @@ function restoreOptions() {
document.getElementById('plex_library_id').value = items.plexLibraryId || '';
document.getElementById('couchpotato_url_root').value = items.couchpotatoUrlRoot || '';
document.getElementById('couchpotato_token').value = items.couchpotatoToken || '';
document.getElementById('couchpotato_basic_auth_username').value = items.couchpotatoBasicAuthUsername || '';
document.getElementById('couchpotato_basic_auth_password').value = items.couchpotatoBasicAuthPassword || '';
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
Expand Down

0 comments on commit 4dbab16

Please sign in to comment.