mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 17:58:22 +01:00
google drive support, working
This commit is contained in:
parent
7df31a0f45
commit
77336716b5
@ -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
|
@ -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
|
||||
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
|
||||
|
||||
xhr.onerror = () ->
|
||||
console.log "eror download"
|
||||
|
||||
xhr.send()
|
||||
|
||||
|
||||
return
|
||||
when "mk"
|
||||
return
|
||||
when "write"
|
||||
|
@ -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:() ->
|
||||
|
Loading…
Reference in New Issue
Block a user