summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
authorSheogorath2018-05-16 01:19:44 +0200
committerSheogorath2018-05-16 01:34:55 +0200
commitad69c5017b28f333bb5ed9a3ee20d95c92d7c046 (patch)
tree17b380f2a2a137c10b3248f79415de7d794579a5 /public/js/index.js
parentb8e7c4b97a2a8369c9f1989352dec65867d838ac (diff)
Removing google drive integration
It's sad but it's not working. For multiple releases this should be already broken which shows how often it's used. As there is also a security issue related to that, it's better to remove the feature completely. Whoever wants to rewrite it, feel free to go. This commit removes the Google Drive integration from HackMD's Frontend editor and this way removes the need to provide any API key and Client ID in the frontend. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js104
1 files changed, 0 insertions, 104 deletions
diff --git a/public/js/index.js b/public/js/index.js
index d76a37fe..c6a4f770 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -30,8 +30,6 @@ import {
import {
debug,
DROPBOX_APP_KEY,
- GOOGLE_API_KEY,
- GOOGLE_CLIENT_ID,
noteid,
noteurl,
urlpath,
@@ -908,29 +906,6 @@ if (DROPBOX_APP_KEY) {
ui.toolbar.export.dropbox.hide()
}
-// check if google api key and client id are set and load scripts
-if (GOOGLE_API_KEY && GOOGLE_CLIENT_ID) {
- $('<script>')
- .attr('type', 'text/javascript')
- .attr('src', 'https://www.google.com/jsapi?callback=onGoogleAPILoaded')
- .prop('async', true)
- .prop('defer', true)
- .appendTo('body')
-} else {
- ui.toolbar.import.googleDrive.hide()
- ui.toolbar.export.googleDrive.hide()
-}
-
-function onGoogleAPILoaded () {
- $('<script>')
- .attr('type', 'text/javascript')
- .attr('src', 'https://apis.google.com/js/client:plusone.js?onload=onGoogleClientLoaded')
- .prop('async', true)
- .prop('defer', true)
- .appendTo('body')
-}
-window.onGoogleAPILoaded = onGoogleAPILoaded
-
// button actions
// share
ui.toolbar.publish.attr('href', noteurl + '/publish')
@@ -979,53 +954,6 @@ ui.toolbar.export.dropbox.click(function () {
}
Dropbox.save(options)
})
-function uploadToGoogleDrive (accessToken) {
- ui.spinner.show()
- var filename = renderFilename(ui.area.markdown) + '.md'
- var markdown = editor.getValue()
- var blob = new Blob([markdown], {
- type: 'text/markdown;charset=utf-8'
- })
- blob.name = filename
- var uploader = new MediaUploader({
- file: blob,
- token: accessToken,
- onComplete: function (data) {
- data = JSON.parse(data)
- showMessageModal('<i class="fa fa-cloud-upload"></i> Export to Google Drive', 'Export Complete!', data.alternateLink, 'Click here to view your file', true)
- ui.spinner.hide()
- },
- onError: function (data) {
- showMessageModal('<i class="fa fa-cloud-upload"></i> Export to Google Drive', 'Export Error :(', '', data, false)
- ui.spinner.hide()
- }
- })
- uploader.upload()
-}
-function googleApiAuth (immediate, callback) {
- gapi.auth.authorize(
- {
- 'client_id': GOOGLE_CLIENT_ID,
- 'scope': 'https://www.googleapis.com/auth/drive.file',
- 'immediate': immediate
- }, callback || function () { })
-}
-function onGoogleClientLoaded () {
- googleApiAuth(true)
- buildImportFromGoogleDrive()
-}
-window.onGoogleClientLoaded = onGoogleClientLoaded
-// export to google drive
-ui.toolbar.export.googleDrive.click(function (e) {
- var token = gapi.auth.getToken()
- if (token) {
- uploadToGoogleDrive(token.access_token)
- } else {
- googleApiAuth(false, function (result) {
- uploadToGoogleDrive(result.access_token)
- })
- }
-})
// export to gist
ui.toolbar.export.gist.attr('href', noteurl + '/gist')
// export to snippet
@@ -1075,38 +1003,6 @@ ui.toolbar.import.dropbox.click(function () {
}
Dropbox.choose(options)
})
-// import from google drive
-function buildImportFromGoogleDrive () {
- /* eslint-disable no-unused-vars */
- let picker = new FilePicker({
- apiKey: GOOGLE_API_KEY,
- clientId: GOOGLE_CLIENT_ID,
- buttonEl: ui.toolbar.import.googleDrive,
- onSelect: function (file) {
- if (file.downloadUrl) {
- ui.spinner.show()
- var accessToken = gapi.auth.getToken().access_token
- $.ajax({
- type: 'GET',
- beforeSend: function (request) {
- request.setRequestHeader('Authorization', 'Bearer ' + accessToken)
- },
- url: file.downloadUrl,
- success: function (data) {
- if (file.fileExtension === 'html') { parseToEditor(data) } else { replaceAll(data) }
- },
- error: function (data) {
- showMessageModal('<i class="fa fa-cloud-download"></i> Import from Google Drive', 'Import failed :(', '', data, false)
- },
- complete: function () {
- ui.spinner.hide()
- }
- })
- }
- }
- })
- /* eslint-enable no-unused-vars */
-}
// import from gist
ui.toolbar.import.gist.click(function () {
// na