From 77336716b528660a5bdf4a862b120d273437ad44 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Wed, 28 Feb 2018 00:15:41 +0100 Subject: [PATCH] google drive support, working --- src/core/settings.coffee | 3 +- src/core/vfs/GoogleDriveHandler.coffee | 39 ++++++++++++++++---------- src/packages/Files/main.coffee | 1 + 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/core/settings.coffee b/src/core/settings.coffee index 8291fab..8a1277b 100644 --- a/src/core/settings.coffee +++ b/src/core/settings.coffee @@ -12,6 +12,7 @@ { text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" }, { text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" }, { text: "Desktop", path: _OS.setting.desktop.path , iconclass: "fa fa-desktop", type: "fs" }, + { text: "Google Drive", path: 'gdv:///', iconclass: "fa fa-google-drive", type: "fs" }, { text: "Shared", path: 'shared:///' , iconclass: "fa fa-share-square", type: "fs" } ] if not _OS.setting.VFS.mountpoints @@ -29,5 +30,5 @@ API_KEY: "AIzaSyBZhM5KbARvT10acWC8JQKlRn2WbSsmfLc" apilink: "https://apis.google.com/js/api.js" DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"] - SCOPES: 'https://www.googleapis.com/auth/drive.metadata.readonly' + SCOPES: 'https://www.googleapis.com/auth/drive' } unless _OS.setting.VFS.gdrive \ No newline at end of file diff --git a/src/core/vfs/GoogleDriveHandler.coffee b/src/core/vfs/GoogleDriveHandler.coffee index 2a70d92..1d5e5c8 100644 --- a/src/core/vfs/GoogleDriveHandler.coffee +++ b/src/core/vfs/GoogleDriveHandler.coffee @@ -71,22 +71,31 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler switch n when "read" return unless @info.id - console.log @info.webContentLink - accessToken = gapi.auth.getToken().access_token - xhr = new XMLHttpRequest() - xhr.open 'GET', @info.webContentLink - xhr.setRequestHeader 'Authorization', 'Bearer ' + accessToken - xhr.setRequestHeader 'Access-Control-Allow-Origin', '*' - xhr.onload = () -> - f xhr.responseText - - xhr.onerror = () -> - console.log "eror download" - - xhr.send() - + if @info.mimeType is "application/vnd.google-apps.folder" + gapi.client.drive.files.list { + q: "'#{me.info.id}' in parents and trashed = false", + fields: "files(#{me.fields()})" + } + .then (r) -> + return unless r.result.files and r.result.files.length > 0 + for file in r.result.files + file.path = me.path + "/" + file.name + file.mime = file.mimeType + file.filename = file.name + file.type = "file" + file.gid = file.id + if file.mimeType is "application/vnd.google-apps.folder" + file.mime = "dir" + file.type = "dir" + f { result: r.result.files } + else + gapi.client.drive.files.get { + fileId: me.info.id, + alt: 'media' + } + .then (r) -> + f r.body - return when "mk" return when "write" diff --git a/src/packages/Files/main.coffee b/src/packages/Files/main.coffee index 0cd6ef5..65dd106 100644 --- a/src/packages/Files/main.coffee +++ b/src/packages/Files/main.coffee @@ -102,6 +102,7 @@ class Files extends this.OS.GUI.BaseApplication d.result.unshift p ($ me.navinput).val dir.path me.view.set "path", dir.path + console.log d.result me.view.set "data", d.result mnFile:() ->