google drive support, working

This commit is contained in:
Xuan Sang LE 2018-02-28 00:15:41 +01:00
parent 7df31a0f45
commit 77336716b5
3 changed files with 27 additions and 16 deletions

View File

@ -12,6 +12,7 @@
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" }, { text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", 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: "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" } { text: "Shared", path: 'shared:///' , iconclass: "fa fa-share-square", type: "fs" }
] if not _OS.setting.VFS.mountpoints ] if not _OS.setting.VFS.mountpoints
@ -29,5 +30,5 @@
API_KEY: "AIzaSyBZhM5KbARvT10acWC8JQKlRn2WbSsmfLc" API_KEY: "AIzaSyBZhM5KbARvT10acWC8JQKlRn2WbSsmfLc"
apilink: "https://apis.google.com/js/api.js" apilink: "https://apis.google.com/js/api.js"
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"] 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 } unless _OS.setting.VFS.gdrive

View File

@ -71,22 +71,31 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
switch n switch n
when "read" when "read"
return unless @info.id return unless @info.id
console.log @info.webContentLink if @info.mimeType is "application/vnd.google-apps.folder"
accessToken = gapi.auth.getToken().access_token gapi.client.drive.files.list {
xhr = new XMLHttpRequest() q: "'#{me.info.id}' in parents and trashed = false",
xhr.open 'GET', @info.webContentLink fields: "files(#{me.fields()})"
xhr.setRequestHeader 'Authorization', 'Bearer ' + accessToken }
xhr.setRequestHeader 'Access-Control-Allow-Origin', '*' .then (r) ->
xhr.onload = () -> return unless r.result.files and r.result.files.length > 0
f xhr.responseText for file in r.result.files
file.path = me.path + "/" + file.name
xhr.onerror = () -> file.mime = file.mimeType
console.log "eror download" file.filename = file.name
file.type = "file"
xhr.send() 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" when "mk"
return return
when "write" when "write"

View File

@ -102,6 +102,7 @@ class Files extends this.OS.GUI.BaseApplication
d.result.unshift p d.result.unshift p
($ me.navinput).val dir.path ($ me.navinput).val dir.path
me.view.set "path", dir.path me.view.set "path", dir.path
console.log d.result
me.view.set "data", d.result me.view.set "data", d.result
mnFile:() -> mnFile:() ->