forked from mkaminsky11/codeyourcloud
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.js
More file actions
100 lines (84 loc) · 1.91 KB
/
Copy pathinit.js
File metadata and controls
100 lines (84 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function loadDrive(){
gapi.auth.authorize({'client_id': CLIENT_ID, 'scope': SCOPES.join(' '), 'immediate': true},handleAuth);
}
//handles result
function handleAuth(authResult){
if (!authResult.error) {
loadClient();
sendData({type:"login",value:"true"});
}
else {
sendData({type:"login",value:"false"});
}
}
function loadClient() {
gapi.client.load('drive', 'v2', load_drive);
if(getParameterByName("id") !== ""){
current = getParameterByName("id");
gapi.load("auth:client,drive-realtime,drive-share", load_real);
sendData({type:"welcome",value:"false"});
}
else{
//welcome();
sendData({type:"welcome",value:"true"});
}
}
function load_drive(){
setInterval(function(){
refreshToken();
},3000000);
get_info();
drive_loaded = true;
if(real_loaded){
init();
}
}
function refreshToken() {
gapi.auth.authorize({'client_id': CLIENT_ID, 'scope': SCOPES.join(' '), 'immediate':true},function(result){
});
}
function get_info(){
var request = gapi.client.drive.about.get();
request.execute(function(resp) {
myRootFolderId = resp.rootFolderId;
myEmail = resp.user.emailAddress;
userName = resp.name;
try{
userUrl = resp.user.picture.url;
}
catch(e){}
try{
userId = resp.user.permissionId;
}
catch(e){}
sendData({
type: "info_drive",
folder: myRootFolderId,
mail: myEmail,
name: userName,
photo: userUrl,
id: userId
});
});
}
function load_real(){
real_loaded = true;
if(drive_loaded){
init();
}
}
function init_realtime(model){
init_needed = true;
getContentOfFile(current, model);
}
function errorFn(error){
was_error = true;
console.log(error);
sendData({
type:"error",
data:error
});
}
function init(){
gapi.drive.realtime.load(current, loaded_realtime, init_realtime, errorFn);
}