mirror of
https://github.com/lxsang/antos-frontend.git
synced 2025-02-22 18:02:47 +01:00
google drive support, bug
This commit is contained in:
parent
d017c2dffa
commit
7df31a0f45
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
# GoogleDrive File Handler
|
# GoogleDrive File Handler
|
||||||
|
G_CACHE = {"gdv:///":"root"}
|
||||||
|
|
||||||
class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
||||||
constructor: (path) ->
|
constructor: (path) ->
|
||||||
super path
|
super path
|
||||||
@ -33,19 +35,57 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
|||||||
fn(gapi.auth2.getAuthInstance().isSignedIn.get())
|
fn(gapi.auth2.getAuthInstance().isSignedIn.get())
|
||||||
|
|
||||||
meta: (f) ->
|
meta: (f) ->
|
||||||
|
me = @
|
||||||
@oninit () ->
|
@oninit () ->
|
||||||
gapi.client.drive.files.list {
|
me.gid = G_CACHE[me.path] if G_CACHE[me.path]
|
||||||
q: 'parents = "root" and trashed = false ',
|
if me.gid
|
||||||
fields: "nextPageToken, files(id, name)"
|
#console.log "Gid exists ", me.gid
|
||||||
}
|
gapi.client.drive.files.get {
|
||||||
.then (r) ->
|
fileId: me.gid,
|
||||||
console.log(r)
|
fields: me.fields()
|
||||||
f()
|
}
|
||||||
|
.then (r) ->
|
||||||
|
return unless r.result
|
||||||
|
f(r)
|
||||||
|
else
|
||||||
|
#console.log "Find file in ", me.parent()
|
||||||
|
fp = me.parent().asFileHandler()
|
||||||
|
fp.meta (d) ->
|
||||||
|
file = d.result
|
||||||
|
G_CACHE[fp.path] = file.id
|
||||||
|
gapi.client.drive.files.list {
|
||||||
|
q: "name = '#{me.basename}' and '#{file.id}' in parents and trashed = false",
|
||||||
|
fields: "files(#{me.fields()})"
|
||||||
|
}
|
||||||
|
.then (r) ->
|
||||||
|
#console.log r
|
||||||
|
return unless r.result.files and r.result.files.length > 0
|
||||||
|
G_CACHE[me.path] = r.result.files[0].id
|
||||||
|
f { result: r.result.files[0] }
|
||||||
|
|
||||||
|
fields: () ->
|
||||||
|
return "webContentLink, id, name,mimeType,description, kind, parents, properties, iconLink, createdTime, modifiedTime, owners, permissions, fullFileExtension, fileExtension, size"
|
||||||
|
|
||||||
action: (n, p, f) ->
|
action: (n, p, f) ->
|
||||||
me = @
|
me = @
|
||||||
switch n
|
switch n
|
||||||
when "read"
|
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()
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
when "mk"
|
when "mk"
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user