Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
remove unused drive scope
Browse files Browse the repository at this point in the history
  • Loading branch information
vcoppe committed Apr 2, 2024
1 parent 0a1f403 commit 8abdef3
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions js/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export default class Google {
this.clientId = "666808960580-0vssfd67o4l2oeirhnapdv2ej575pks7.apps.googleusercontent.com";
this.appId = "666808960580";
this.scope = ['https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.install',
'https://www.googleapis.com/auth/drive.readonly'];
'https://www.googleapis.com/auth/drive.install'];
this.scope2 = this.scope.join(' ');
this.buttons = buttons;

Expand All @@ -16,7 +15,7 @@ export default class Google {
const urlParams = new URLSearchParams(queryString);

gapi.load('client', {
callback: function() {
callback: function () {
gapi.client.init({})
}
});
Expand Down Expand Up @@ -66,30 +65,30 @@ export default class Google {
var countDone = 0, countOk = 0;

const index = {};
for (var i=0; i<params.ids.length; i++) if (index[params.ids[i]] === undefined) {
for (var i = 0; i < params.ids.length; i++) if (index[params.ids[i]] === undefined) {
index[params.ids[i]] = i;
}

for (var i=0; i<params.ids.length; i++) {
for (var i = 0; i < params.ids.length; i++) {
const file_id = params.ids[i];
this.downloadFile(
{id:file_id, name:'track.gpx'},
{ id: file_id, name: 'track.gpx' },
function (trace) {
countDone++;
if (trace) {
countOk++;
trace.key = file_id;
for (var j=total.traces.length-countOk; j<total.traces.length-1; j++) {
for (var j = total.traces.length - countOk; j < total.traces.length - 1; j++) {
if (index[total.traces[j].key] > index[file_id]) {
sortable.el.appendChild(total.traces[j].tab);
}
}
}
if (countDone == params.ids.length) {
for (var j=1; j<sortable.el.children.length; j++) {
for (var j = 1; j < sortable.el.children.length; j++) {
const tab = sortable.el.children[j];
const trace = tab.trace;
trace.index = j-1;
trace.index = j - 1;
trace.key = null;
total.traces[trace.index] = trace;
if (trace.hasFocus) {
Expand All @@ -104,13 +103,13 @@ export default class Google {

loadPicker(folderMode) {
this.folderMode = folderMode;
if (!this.access_token || Date.now() >= this.refresh_time) {
if (!this.access_token || Date.now() >= this.refresh_time) {
this.mustLoadPicker = true;
this.tokenClient.requestAccessToken();
return;
}
if (this.pickerApiLoaded) this.createPicker();
else gapi.load('picker', {'callback': this.onPickerApiLoad.bind(this)});
else gapi.load('picker', { 'callback': this.onPickerApiLoad.bind(this) });
}

onPickerApiLoad() {
Expand Down Expand Up @@ -150,7 +149,7 @@ export default class Google {

pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
for (var i=0; i<data.docs.length; i++)
for (var i = 0; i < data.docs.length; i++)
this.downloadFile(data.docs[i]);
}
}
Expand All @@ -169,7 +168,7 @@ export default class Google {
this.checkAllFilesInFolder(data.docs[0].id, buttons.total.outputGPX(mergeAll, time, hr, atemp, cad, power, surface));

buttons.export_window.hide();
this.window = L.control.window(this.buttons.map,{title:'',content:'Uploading...',className:'panels-container',closeButton:false,visible:true});
this.window = L.control.window(this.buttons.map, { title: '', content: 'Uploading...', className: 'panels-container', closeButton: false, visible: true });
}
}

Expand All @@ -178,31 +177,31 @@ export default class Google {
gapi.client.request({
'path': '/drive/v2/files',
'method': 'GET',
'params': {'q': "'" + folderId + "' in parents and trashed=false"},
'params': { 'q': "'" + folderId + "' in parents and trashed=false" },
callback: function (resp) {
_this.fileIds = [];
_this.completed = 0;
for (var i=0; i<output.length; i++) {
for (var i = 0; i < output.length; i++) {
var replace = false;
for (var j=0; j<resp.items.length; j++) {
for (var j = 0; j < resp.items.length; j++) {
if (resp.items[j].title == output[i].name) {
_this.saveFile(output[i].name, output[i].text, folderId, i, output.length, resp.items[j].id);
replace = true;
break;
}
}
if (!replace) _this.saveFile(output[i].name, output[i].text, folderId, i, output.length);
if (!replace) _this.saveFile(output[i].name, output[i].text, folderId, i, output.length);
}
}
});
}

saveFile(filename, filecontent, folderid, index, number, fileId) {
var file = new Blob([filecontent], {type: 'text/xml'});
var file = new Blob([filecontent], { type: 'text/xml' });
var metadata = {
'title': filename,
'mimeType': 'application/gpx+xml',
'parents': [{"kind": "drive#parentReference", "id": folderid}]
'parents': [{ "kind": "drive#parentReference", "id": folderid }]
};

const _this = this;
Expand All @@ -221,22 +220,22 @@ export default class Google {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + _this.access_token
},
'body':{
'body': {
'role': 'reader',
'type': 'anyone'
}
});
request.execute();

if (_this.completed == number) {
var url = 'https://gpx.studio'+window.location.pathname.replace('index.html','')+'?state=%7B%22ids%22:%5B%22';
for (var i=0; i<_this.fileIds.length; i++) {
var url = 'https://gpx.studio' + window.location.pathname.replace('index.html', '') + '?state=%7B%22ids%22:%5B%22';
for (var i = 0; i < _this.fileIds.length; i++) {
url += _this.fileIds[i];
if (i<_this.fileIds.length-1) url += '%22,%22';
if (i < _this.fileIds.length - 1) url += '%22,%22';
}
url += '%22%5D%7D';

var code = '<iframe src="'+url+'&embed" width="100%" height="500" frameborder="0" allowfullscreen><p><a href="'+url+'"></a></p></iframe>';
var code = '<iframe src="' + url + '&embed" width="100%" height="500" frameborder="0" allowfullscreen><p><a href="' + url + '"></a></p></iframe>';

_this.buttons.copy_link.addEventListener('click', function () {
navigator.clipboard.writeText(url);
Expand Down Expand Up @@ -272,7 +271,7 @@ export default class Google {
} else this.last_request = new Date();

const request = new XMLHttpRequest();
var file_url = 'https://content.googleapis.com/drive/v2/files/'+file.id+'?key='+this.developerKey;
var file_url = 'https://content.googleapis.com/drive/v2/files/' + file.id + '?key=' + this.developerKey;
request.open('GET', file_url, true);
if (this.access_token) request.setRequestHeader('Authorization', 'Bearer ' + this.access_token);
const _this = this;
Expand All @@ -282,7 +281,7 @@ export default class Google {
const resp = JSON.parse(request.response);
var file_url = resp.downloadUrl;
if (file_url) {
file_url = file_url.replace('content.google','www.google');
file_url = file_url.replace('content.google', 'www.google');
xhr.open('GET', file_url, true);
if (_this.access_token) xhr.setRequestHeader('Authorization', 'Bearer ' + _this.access_token);
xhr.onreadystatechange = function () {
Expand Down

0 comments on commit 8abdef3

Please sign in to comment.