[imgur] Simplify logic, update wiki URL to main repo
This commit is contained in:
parent
a97f335579
commit
5f1dc5d30d
@ -123,7 +123,7 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="row no-gutter">
|
<div class="row no-gutter">
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<label class="control-label" for="iAlb">Imgur Album hash<a target="_blank" href="https://github.com/Jaekr/glowing-bear/wiki/Getting-a-token-&-Album-Hash"><i class="glyphicon glyphicon-info-sign"></i></a></label>
|
<label class="control-label" for="iAlb">Imgur Album hash<a target="_blank" href="https://github.com/glowing-bear/glowing-bear/wiki/Getting-an-imgur-token-&-album-hash"><i class="glyphicon glyphicon-info-sign"></i></a></label>
|
||||||
<input type="text" class="form-control favorite-font" id="iAlb" ng-model="settings.iAlb" placeholder="Album hash" autocapitalize="off">
|
<input type="text" class="form-control favorite-font" id="iAlb" ng-model="settings.iAlb" placeholder="Album hash" autocapitalize="off">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
25
js/imgur.js
25
js/imgur.js
@ -27,26 +27,18 @@ weechat.factory('imgur', 'settings', ['$rootScope', function($rootScope) {
|
|||||||
// Upload image to imgur from base64
|
// Upload image to imgur from base64
|
||||||
var upload = function( base64img, callback ) {
|
var upload = function( base64img, callback ) {
|
||||||
|
|
||||||
// Declaring variables used later
|
// API authorization, either via Client ID (anonymous) or access token
|
||||||
|
// (add to user's imgur account), see also:
|
||||||
|
// https://github.com/glowing-bear/glowing-bear/wiki/Getting-an-imgur-token-&-album-hash
|
||||||
var accessToken = "164efef8979cd4b";
|
var accessToken = "164efef8979cd4b";
|
||||||
var albumHash = "";
|
|
||||||
var albEnabled = false;
|
|
||||||
var isClientID = true;
|
var isClientID = true;
|
||||||
|
|
||||||
// Set client ID
|
// Check whether the user has provided an access token
|
||||||
if(settings.iToken.length > 37){
|
if (settings.iToken.length > 37){
|
||||||
accessToken = settings.iToken;
|
accessToken = settings.iToken;
|
||||||
isClientID = false;
|
isClientID = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for a album hash
|
|
||||||
if(settings.iAlb.length < 6) {
|
|
||||||
albEnabled = false;
|
|
||||||
} else {
|
|
||||||
albEnabled = true;
|
|
||||||
albumHash = settings.iAlb;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progress bars container
|
// Progress bars container
|
||||||
var progressBars = document.getElementById("imgur-upload-progress"),
|
var progressBars = document.getElementById("imgur-upload-progress"),
|
||||||
currentProgressBar = document.createElement("div");
|
currentProgressBar = document.createElement("div");
|
||||||
@ -63,8 +55,9 @@ weechat.factory('imgur', 'settings', ['$rootScope', function($rootScope) {
|
|||||||
fd.append("image", base64img); // Append the file
|
fd.append("image", base64img); // Append the file
|
||||||
fd.append("type", "base64"); // Set image type to base64
|
fd.append("type", "base64"); // Set image type to base64
|
||||||
|
|
||||||
if(albEnabled) {
|
// Add the image to the provided album if configured to do so
|
||||||
fd.append("album", albumHash); // If the user provided an album hash
|
if (!isClientID && settings.iAlb.length >= 6) {
|
||||||
|
fd.append("album", settings.iAlb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new XMLHttpRequest
|
// Create new XMLHttpRequest
|
||||||
@ -74,7 +67,7 @@ weechat.factory('imgur', 'settings', ['$rootScope', function($rootScope) {
|
|||||||
xhttp.open("POST", "https://api.imgur.com/3/image", true);
|
xhttp.open("POST", "https://api.imgur.com/3/image", true);
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
if(isClientID) {
|
if (isClientID) {
|
||||||
xhttp.setRequestHeader("Authorization", "Client-ID " + accessToken);
|
xhttp.setRequestHeader("Authorization", "Client-ID " + accessToken);
|
||||||
} else {
|
} else {
|
||||||
xhttp.setRequestHeader("Authorization", "Bearer " + accessToken);
|
xhttp.setRequestHeader("Authorization", "Bearer " + accessToken);
|
||||||
|
Loading…
Reference in New Issue
Block a user