Secondary Google account (part2)
This commit is contained in:
parent
4b0d5306e9
commit
31fea5be52
@ -43,8 +43,7 @@ define([], function() {
|
|||||||
constants.GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
constants.GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
||||||
constants.TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
constants.TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
||||||
}
|
}
|
||||||
|
else if(location.hostname.indexOf("benweet.github.io") === 0) {
|
||||||
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
|
||||||
constants.BASE_URL = 'http://benweet.github.io/stackedit/';
|
constants.BASE_URL = 'http://benweet.github.io/stackedit/';
|
||||||
constants.GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
||||||
constants.GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
constants.GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
||||||
@ -53,8 +52,7 @@ define([], function() {
|
|||||||
constants.WORDPRESS_CLIENT_ID = '3185';
|
constants.WORDPRESS_CLIENT_ID = '3185';
|
||||||
constants.WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
constants.WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
||||||
}
|
}
|
||||||
|
else if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
||||||
if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
|
||||||
constants.BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
constants.BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
||||||
constants.GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
||||||
constants.GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
constants.GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
||||||
|
@ -13,7 +13,7 @@ define([
|
|||||||
|
|
||||||
var fileDesc;
|
var fileDesc;
|
||||||
var $fileTitleNavbar;
|
var $fileTitleNavbar;
|
||||||
var updateTitle = function(fileDescParameter) {
|
var updateTitle = _.debounce(function(fileDescParameter) {
|
||||||
if(fileDescParameter !== fileDesc) {
|
if(fileDescParameter !== fileDesc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -24,11 +24,8 @@ define([
|
|||||||
$(".file-title").text(title);
|
$(".file-title").text(title);
|
||||||
$(".input-file-title").val(title);
|
$(".input-file-title").val(title);
|
||||||
|
|
||||||
if(layout !== undefined) {
|
layout && layout.resizeAll();
|
||||||
// Use defer to make sure UI has been updated
|
}, 50);
|
||||||
_.defer(layout.resizeAll);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
documentTitle.onFileSelected = function(fileDescParameter) {
|
documentTitle.onFileSelected = function(fileDescParameter) {
|
||||||
fileDesc = fileDescParameter;
|
fileDesc = fileDescParameter;
|
||||||
@ -40,6 +37,7 @@ define([
|
|||||||
documentTitle.onSyncRemoved = updateTitle;
|
documentTitle.onSyncRemoved = updateTitle;
|
||||||
documentTitle.onNewPublishSuccess = updateTitle;
|
documentTitle.onNewPublishSuccess = updateTitle;
|
||||||
documentTitle.onPublishRemoved = updateTitle;
|
documentTitle.onPublishRemoved = updateTitle;
|
||||||
|
documentTitle.onReady = updateTitle;
|
||||||
|
|
||||||
documentTitle.onReady = function() {
|
documentTitle.onReady = function() {
|
||||||
$fileTitleNavbar = $(".file-title-navbar");
|
$fileTitleNavbar = $(".file-title-navbar");
|
||||||
|
@ -16,20 +16,20 @@ define([
|
|||||||
var authorizationMgrMap = {};
|
var authorizationMgrMap = {};
|
||||||
function AuthorizationMgr(accountId) {
|
function AuthorizationMgr(accountId) {
|
||||||
var permissionList = {};
|
var permissionList = {};
|
||||||
var isAuthorized = false;
|
var refreshFlag = true;
|
||||||
_.each((storage[accountId + '.permissions'] || '').split(';'), function(permission) {
|
_.each((storage[accountId + '.permissions'] || '').split(';'), function(permission) {
|
||||||
permission && (permissionList[permission] = true);
|
permission && (permissionList[permission] = true);
|
||||||
});
|
});
|
||||||
this.reset = function() {
|
this.setRefreshFlag = function() {
|
||||||
isAuthorized = false;
|
refreshFlag = true;
|
||||||
};
|
};
|
||||||
this.isAuthorized = function(permission) {
|
this.isAuthorized = function(permission) {
|
||||||
return isAuthorized && _.has(permissionList, permission);
|
return refreshFlag === false && _.has(permissionList, permission);
|
||||||
};
|
};
|
||||||
this.add = function(permission) {
|
this.add = function(permission) {
|
||||||
permissionList[permission] = true;
|
permissionList[permission] = true;
|
||||||
storage[accountId + '.permissions'] = _.keys(permissionList).join(';');
|
storage[accountId + '.permissions'] = _.keys(permissionList).join(';');
|
||||||
isAuthorized = true;
|
refreshFlag = false;
|
||||||
};
|
};
|
||||||
this.getListWithNew = function(permission) {
|
this.getListWithNew = function(permission) {
|
||||||
var result = _.keys(permissionList);
|
var result = _.keys(permissionList);
|
||||||
@ -103,7 +103,7 @@ define([
|
|||||||
'https://picasaweb.google.com/data/'
|
'https://picasaweb.google.com/data/'
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
function authenticate(task, permission, accountId, refresh) {
|
function authenticate(task, permission, accountId) {
|
||||||
accountId = accountId || 'google.0';
|
accountId = accountId || 'google.0';
|
||||||
var authorizationMgr = authorizationMgrMap[accountId];
|
var authorizationMgr = authorizationMgrMap[accountId];
|
||||||
if(!authorizationMgr) {
|
if(!authorizationMgr) {
|
||||||
@ -116,7 +116,7 @@ define([
|
|||||||
if(token.access_token) {
|
if(token.access_token) {
|
||||||
immediate = true;
|
immediate = true;
|
||||||
gapi.auth.setToken(token);
|
gapi.auth.setToken(token);
|
||||||
if(!refresh && authorizationMgr.isAuthorized(permission)) {
|
if(authorizationMgr.isAuthorized(permission)) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -138,9 +138,10 @@ define([
|
|||||||
}
|
}
|
||||||
var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value();
|
var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value();
|
||||||
gapi.auth.authorize({
|
gapi.auth.authorize({
|
||||||
'client_id': constants.GOOGLE_CLIENT_ID,
|
client_id: constants.GOOGLE_CLIENT_ID,
|
||||||
'scope': scopeList,
|
scope: scopeList,
|
||||||
'immediate': immediate
|
immediate: immediate,
|
||||||
|
authuser: immediate ? undefined : ''
|
||||||
}, function(authResult) {
|
}, function(authResult) {
|
||||||
gapi.client.load('drive', 'v2', function() {
|
gapi.client.load('drive', 'v2', function() {
|
||||||
if(!authResult || authResult.error) {
|
if(!authResult || authResult.error) {
|
||||||
@ -157,7 +158,7 @@ define([
|
|||||||
}
|
}
|
||||||
// Success
|
// Success
|
||||||
authorizationMgr.add(permission);
|
authorizationMgr.add(permission);
|
||||||
authorizationMgr.saveToken();
|
immediate === false && authorizationMgr.saveToken();
|
||||||
task.chain();
|
task.chain();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -168,7 +169,9 @@ define([
|
|||||||
googleHelper.refreshGdriveToken = function(accountId) {
|
googleHelper.refreshGdriveToken = function(accountId) {
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive', accountId, true);
|
var authorizationMgr = authorizationMgrMap[accountId];
|
||||||
|
authorizationMgr && authorizationMgr.setRefreshFlag();
|
||||||
|
authenticate(task, 'gdrive', accountId);
|
||||||
task.enqueue();
|
task.enqueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -626,7 +629,7 @@ define([
|
|||||||
}
|
}
|
||||||
else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") {
|
else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") {
|
||||||
_.each(authorizationMgrMap, function(authorizationMgr) {
|
_.each(authorizationMgrMap, function(authorizationMgr) {
|
||||||
authorizationMgr.reset();
|
authorizationMgr.setRefreshFlag();
|
||||||
});
|
});
|
||||||
errorMsg = "Access to Google account is not authorized.";
|
errorMsg = "Access to Google account is not authorized.";
|
||||||
task.retry(new Error(errorMsg), 1);
|
task.retry(new Error(errorMsg), 1);
|
||||||
@ -635,7 +638,7 @@ define([
|
|||||||
else if(error.code === 0 || error.code === -1) {
|
else if(error.code === 0 || error.code === -1) {
|
||||||
connected = false;
|
connected = false;
|
||||||
_.each(authorizationMgrMap, function(authorizationMgr) {
|
_.each(authorizationMgrMap, function(authorizationMgr) {
|
||||||
authorizationMgr.reset();
|
authorizationMgr.setRefreshFlag();
|
||||||
});
|
});
|
||||||
core.setOffline();
|
core.setOffline();
|
||||||
errorMsg = "|stopPublish";
|
errorMsg = "|stopPublish";
|
||||||
@ -709,7 +712,7 @@ define([
|
|||||||
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
||||||
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
||||||
pickerBuilder.addView(view);
|
pickerBuilder.addView(view);
|
||||||
pickerBuilder.setOAuthToken(gapi.auth.getToken());
|
pickerBuilder.setOAuthToken(gapi.auth.getToken().access_token);
|
||||||
}
|
}
|
||||||
else if(pickerType == 'folder') {
|
else if(pickerType == 'folder') {
|
||||||
view = new google.picker.DocsView(google.picker.ViewId.FOLDERS);
|
view = new google.picker.DocsView(google.picker.ViewId.FOLDERS);
|
||||||
@ -718,7 +721,7 @@ define([
|
|||||||
view.setMimeTypes('application/vnd.google-apps.folder');
|
view.setMimeTypes('application/vnd.google-apps.folder');
|
||||||
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
||||||
pickerBuilder.addView(view);
|
pickerBuilder.addView(view);
|
||||||
pickerBuilder.setOAuthToken(gapi.auth.getToken());
|
pickerBuilder.setOAuthToken(gapi.auth.getToken().access_token);
|
||||||
}
|
}
|
||||||
else if(pickerType == 'img') {
|
else if(pickerType == 'img') {
|
||||||
view = new google.picker.PhotosView();
|
view = new google.picker.PhotosView();
|
||||||
|
@ -117,6 +117,11 @@
|
|||||||
Google Drive</a></li>
|
Google Drive</a></li>
|
||||||
<li><a href="#" class="action-sync-export-dialog-gdrive">Export
|
<li><a href="#" class="action-sync-export-dialog-gdrive">Export
|
||||||
to Google Drive</a></li>
|
to Google Drive</a></li>
|
||||||
|
<li><a href="#" class="action-sync-import-gdrivesec"
|
||||||
|
data-toggle="collapse" data-target=".menu-panel">Import from
|
||||||
|
Google Drive (secondary)</a></li>
|
||||||
|
<li><a href="#" class="action-sync-export-dialog-gdrivesec">Export
|
||||||
|
to Google Drive (secondary)</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" data-toggle="collapse"
|
<a href="#" data-toggle="collapse"
|
||||||
@ -459,76 +464,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="modal modal-upload-gdrive">
|
<div class="modal modal-upload-gdrive">
|
||||||
<div class="modal-dialog">
|
</div>
|
||||||
<div class="modal-content">
|
<div class="modal modal-upload-gdrivesec">
|
||||||
|
|
||||||
<div class="modal-header">
|
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
|
||||||
aria-hidden="true">×</button>
|
|
||||||
<h3 class="modal-title">Export to Google Drive</h3>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<p>
|
|
||||||
This will save "<span class="file-title"></span>" to your <i
|
|
||||||
class="icon-provider-gdrive"></i>
|
|
||||||
<code>Google Drive</code>
|
|
||||||
account and keep it synchronized.
|
|
||||||
</p>
|
|
||||||
<div class="collapse form-horizontal sync-export-gdrive-options-collapse">
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-3 control-label"
|
|
||||||
for="input-sync-export-gdrive-parentid">Folder ID
|
|
||||||
(optional)</label>
|
|
||||||
<div class="col-lg-8">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" id="input-sync-export-gdrive-parentid"
|
|
||||||
placeholder="FolderID" class="form-control">
|
|
||||||
<div class="input-group-btn">
|
|
||||||
<a class="btn btn-link export-gdrive-choose-folder"
|
|
||||||
title="Choose folder" data-dismiss="modal"><i
|
|
||||||
class="icon-folder-open"></i></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<span class="help-block"> If no folder ID is supplied, the
|
|
||||||
file will be created in your root folder. </span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-lg-3 control-label"></div>
|
|
||||||
<div class="col-lg-8">
|
|
||||||
<label> <input id="input-sync-export-gdrive-realtime"
|
|
||||||
type="checkbox"> Create a real time collaborative
|
|
||||||
document
|
|
||||||
</label>
|
|
||||||
<span class="help-block"> Collaborative documents cannot be open outside
|
|
||||||
StackEdit nor have multiple synchronized locations. </span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-3 control-label"
|
|
||||||
for="input-sync-export-gdrive-fileid">Existing file ID
|
|
||||||
(optional)</label>
|
|
||||||
<div class="col-lg-8">
|
|
||||||
<input type="text" id="input-sync-export-gdrive-fileid"
|
|
||||||
placeholder="FileID" class="form-control"> <span
|
|
||||||
class="help-block"> This will overwrite the existing file
|
|
||||||
on the server. </span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="align-right"><a href="#" data-toggle="collapse" data-target=".sync-export-gdrive-options-collapse">Options...</a></p>
|
|
||||||
<blockquote>
|
|
||||||
<b>Tip:</b> You can move or rename the file afterwards within Google
|
|
||||||
Drive.
|
|
||||||
</blockquote>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
|
|
||||||
<a href="#" data-dismiss="modal"
|
|
||||||
class="btn btn-primary action-sync-export-gdrive">OK</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ define([
|
|||||||
"providers/gistProvider",
|
"providers/gistProvider",
|
||||||
"providers/githubProvider",
|
"providers/githubProvider",
|
||||||
"providers/gdriveProvider",
|
"providers/gdriveProvider",
|
||||||
|
"providers/gdrivesecProvider",
|
||||||
"providers/sshProvider",
|
"providers/sshProvider",
|
||||||
"providers/tumblrProvider",
|
"providers/tumblrProvider",
|
||||||
"providers/wordpressProvider"
|
"providers/wordpressProvider"
|
||||||
|
@ -325,7 +325,7 @@ kbd {
|
|||||||
background-position: 0 0;
|
background-position: 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-provider-gdrive {
|
.icon-provider-gdrive, .icon-provider-gdrivesec {
|
||||||
background-position: -18px 0;
|
background-position: -18px 0;
|
||||||
&.realtime {
|
&.realtime {
|
||||||
background-position: -162px 0;
|
background-position: -162px 0;
|
||||||
|
@ -8,7 +8,8 @@ define([
|
|||||||
"fileMgr",
|
"fileMgr",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"providers/dropboxProvider",
|
"providers/dropboxProvider",
|
||||||
"providers/gdriveProvider"
|
"providers/gdriveProvider",
|
||||||
|
"providers/gdrivesecProvider"
|
||||||
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) {
|
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) {
|
||||||
|
|
||||||
var synchronizer = {};
|
var synchronizer = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user