From 246cacd2f8250f25dc797881abe08b61da31058c Mon Sep 17 00:00:00 2001 From: Brett Slatkin Date: Wed, 1 Dec 2010 22:15:27 -0800 Subject: [PATCH] adds support for username and password in camliserver spec --- clients/chrome/clip-it-good/background.html | 14 +++++++++-- clients/chrome/clip-it-good/options.html | 28 ++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/clients/chrome/clip-it-good/background.html b/clients/chrome/clip-it-good/background.html index 5d78829c0..4affb431d 100644 --- a/clients/chrome/clip-it-good/background.html +++ b/clients/chrome/clip-it-good/background.html @@ -29,16 +29,23 @@ // Preferences var ALBUM_CONFIG = {}; // 'type' -> ('id' -> 'name') + var ALBUM_OPTIONS = {}; // 'type' -> ('id' -> optionsDict) function loadAlbumConfig() { var newAlbumConfig = localStorage.getItem('config:albums'); if (newAlbumConfig) { ALBUM_CONFIG = $.parseJSON(newAlbumConfig); } + + var newAlbumOptions = localStorage.getItem('config:albumOptions'); + if (newAlbumOptions) { + ALBUM_OPTIONS = $.parseJSON(newAlbumOptions); + } } function saveAlbumConfig() { localStorage.setItem('config:albums', JSON.stringify(ALBUM_CONFIG)); + localStorage.setItem('config:albumOptions', JSON.stringify(ALBUM_OPTIONS)); } // Sort albums by name. @@ -127,6 +134,7 @@ dataBuffer, uploadDone) { var hash = Crypto.SHA1(new Uint8Array(dataBuffer, 0)); var blobRef = 'sha1-' + hash; + var options = ALBUM_OPTIONS[CAMLISTORE][albumId]; function doUpload(uploadUrl) { // XXX Use real random boundary. @@ -147,7 +155,8 @@ var payload = builder.getBlob(contentType); var uploadXhr = new XMLHttpRequest(); - uploadXhr.open('POST', uploadUrl, true); + uploadXhr.open('POST', uploadUrl, true, + options.username, options.password); uploadXhr.onreadystatechange = function() { if (uploadXhr.readyState == XMLHttpRequest.DONE && uploadXhr.status == 200) { @@ -172,7 +181,8 @@ } var preUploadXhr = new XMLHttpRequest(); - preUploadXhr.open('POST', albumId + '/camli/preupload', true); + preUploadXhr.open('POST', albumId + '/camli/preupload', true, + options.username, options.password); preUploadXhr.onreadystatechange = function() { if (preUploadXhr.readyState == XMLHttpRequest.DONE && preUploadXhr.status == 200) { diff --git a/clients/chrome/clip-it-good/options.html b/clients/chrome/clip-it-good/options.html index 1d5fc0096..03dd916c0 100644 --- a/clients/chrome/clip-it-good/options.html +++ b/clients/chrome/clip-it-good/options.html @@ -208,7 +208,15 @@ if (!BG.ALBUM_CONFIG[BG.CAMLISTORE]) { BG.ALBUM_CONFIG[BG.CAMLISTORE] = {}; } - BG.ALBUM_CONFIG[BG.CAMLISTORE][urlInput.val()] = nameInput.val(); + if (!BG.ALBUM_OPTIONS[BG.CAMLISTORE]) { + BG.ALBUM_OPTIONS[BG.CAMLISTORE] = {}; + } + var albumId = urlInput.val(); + BG.ALBUM_CONFIG[BG.CAMLISTORE][albumId] = nameInput.val(); + BG.ALBUM_OPTIONS[BG.CAMLISTORE][albumId] = { + 'username': $('#camliserver-username').val(), + 'password': $('#camliserver-password').val() + }; BG.saveAlbumConfig(); populateAlbumList(); @@ -259,7 +267,7 @@ Connecting an album to Clip It Good will require giving this extension Extension and source licensed under the Apache License, Version 2.0. Uses jQuery UI (MIT/GPL), - json2 parser (free domain), + json2 parser (public domain), Fred Palmer's Base64 (BSD compat), and Jeff Mott's SHA1 (BSD compat). @@ -276,12 +284,20 @@ Connecting an album to Clip It Good will require giving this extension