Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
lucas.parsy
jio
Commits
2e509df1
Commit
2e509df1
authored
Oct 19, 2015
by
lucas.parsy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed names of variables and checked user input in putAttachment method
parent
8dcd2eac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
58 deletions
+64
-58
src/jio.storage/gdrivestorage.js
src/jio.storage/gdrivestorage.js
+64
-58
No files found.
src/jio.storage/gdrivestorage.js
View file @
2e509df1
...
...
@@ -70,14 +70,14 @@
});
}
function
list
Files
(
result
,
token
)
{
function
list
Directory
(
result
,
token
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
listPage
(
result
,
token
);
})
.
push
(
function
()
{
if
(
result
.
nextPageToken
)
{
return
list
Files
(
result
,
token
);
return
list
Directory
(
result
,
token
);
}
return
result
;
});
...
...
@@ -85,56 +85,56 @@
function
splitpath
(
path
)
{
var
name
=
path
.
split
(
"
/
"
),
i
t_name
;
i
;
for
(
i
t_name
=
0
;
it_name
<
name
.
length
;
it_name
+=
1
)
{
if
(
name
[
i
t_name
]
===
""
)
{
name
.
splice
(
i
t_name
,
1
);
i
t_name
-=
1
;
for
(
i
=
0
;
i
<
name
.
length
;
i
+=
1
)
{
if
(
name
[
i
]
===
""
)
{
name
.
splice
(
i
,
1
);
i
-=
1
;
}
}
return
name
;
}
function
getFileId
(
path
,
token
,
list
)
{
var
i
t_name
,
itFi
,
itPa
,
parent
I
d
,
found
I
tem
,
var
i
,
j
,
k
,
parent
_i
d
,
found
_i
tem
,
result
=
{},
name
=
splitpath
(
path
);
if
(
!
name
.
length
)
{
return
result
;
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
list
||
list
Files
([],
token
);
return
list
||
list
Directory
([],
token
);
})
.
push
(
function
(
file
s
)
{
for
(
i
t_name
=
0
;
it_name
<
name
.
length
;
it_name
+=
1
)
{
found
I
tem
=
false
;
for
(
itFi
=
0
;
itFi
<
files
.
length
;
itFi
+=
1
)
{
if
(
file
s
[
itFi
].
title
===
name
[
it_name
])
{
for
(
itPa
=
0
;
itPa
<
files
[
itFi
].
parents
.
length
;
itPa
+=
1
)
{
if
((
!
i
t_name
&&
files
[
itFi
].
parents
[
itPa
].
isRoot
)
||
(
i
t_name
&&
files
[
itFi
].
parents
[
itPa
].
id
===
parentI
d
))
{
if
(
found
I
tem
===
true
)
{
.
push
(
function
(
file
_list
)
{
for
(
i
=
0
;
i
<
name
.
length
;
i
+=
1
)
{
found
_i
tem
=
false
;
for
(
j
=
0
;
j
<
file_list
.
length
;
j
+=
1
)
{
if
(
file
_list
[
j
].
title
===
name
[
i
])
{
for
(
k
=
0
;
k
<
file_list
[
j
].
parents
.
length
;
k
+=
1
)
{
if
((
!
i
&&
file_list
[
j
].
parents
[
k
].
isRoot
)
||
(
i
&&
file_list
[
j
].
parents
[
k
].
id
===
parent_i
d
))
{
if
(
found
_i
tem
===
true
)
{
//if 2 files with same name in same folder.
throw
new
jIO
.
util
.
jIOError
(
"
Method not implemented
"
,
405
);
}
found
I
tem
=
true
;
parent
Id
=
files
[
itFi
].
id
;
found
_i
tem
=
true
;
parent
_id
=
file_list
[
j
].
id
;
if
(
i
t_name
===
(
name
.
length
-
2
)
&&
file
s
[
itFi
].
mimeType
===
FOLDER
)
{
result
.
parent
=
parent
I
d
;
if
(
i
===
(
name
.
length
-
2
)
&&
file
_list
[
j
].
mimeType
===
FOLDER
)
{
result
.
parent
=
parent
_i
d
;
}
if
(
i
t_name
===
(
name
.
length
-
1
))
{
result
.
id
=
parent
I
d
;
result
.
is
Dir
=
(
files
[
itFi
].
mimeType
===
FOLDER
)
if
(
i
===
(
name
.
length
-
1
))
{
result
.
id
=
parent
_i
d
;
result
.
is
_dir
=
(
file_list
[
j
].
mimeType
===
FOLDER
)
?
true
:
false
;
}
break
;
...
...
@@ -143,7 +143,7 @@
}
}
}
if
(
!
found
I
tem
)
{
break
;
}
if
(
!
found
_i
tem
)
{
break
;
}
}
return
result
;
});
...
...
@@ -176,9 +176,14 @@
parentlist
=
parent
?
'
{id: "
'
+
parent
+
'
"}
'
:
""
,
type
=
data
?
""
:
'
"mimeType" : "
'
+
FOLDER
+
'
",
\n
'
;
if
(
title
.
indexOf
(
boundary
)
!==
-
1
||
(
datatype
&&
datatype
.
indexOf
(
boundary
)
!==
-
1
))
{
throw
new
TypeError
(
"
you can't put this string in any element of
"
+
"
your request (title, datatype):
\n
"
+
boundary
);
}
str
=
'
--
'
+
boundary
+
'
\n
'
+
'
Content-Type: application/json; charset=UTF-8
\n\n
'
+
'
{
\n
"title": "
'
+
title
+
'
",
\n
'
+
'
{
\n
"title": "
'
+
encodeURIComponent
(
title
)
+
'
",
\n
'
+
type
+
'
"parents": [
'
+
parentlist
+
'
]
\n
}
\n\n
'
+
'
--
'
+
boundary
;
...
...
@@ -198,16 +203,17 @@
function
putElement
(
id
,
data
,
token
)
{
var
title
=
splitpath
(
id
),
boundary
=
"
-------314159265358979323846
"
,
file
s
;
file
_list
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
getFileId
(
id
,
token
);
})
.
push
(
function
(
result
)
{
files
=
result
;
if
((
files
.
id
&&
!
data
)
||
(
!
files
.
parent
&&
title
.
length
>
1
)
||
files
.
isDir
)
{
file_list
=
result
;
if
((
file_list
.
id
&&
!
data
)
||
(
!
file_list
.
parent
&&
title
.
length
>
1
)
||
file_list
.
is_dir
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Method Not Allowed
"
,
405
);
}
})
...
...
@@ -218,17 +224,17 @@
.
push
(
function
(
blob
)
{
var
update
=
false
;
if
(
blob
)
{
blob
=
blob
.
currentTarget
.
result
;
}
if
(
blob
&&
file
s
.
id
)
{
update
=
true
;
}
if
(
blob
&&
file
_list
.
id
)
{
update
=
true
;
}
return
jIO
.
util
.
ajax
({
"
type
"
:
update
?
"
PUT
"
:
"
POST
"
,
"
url
"
:
upload_template
.
expand
({
access_token
:
token
,
id
:
update
?
file
s
.
id
:
[]
id
:
update
?
file
_list
.
id
:
[]
}),
headers
:
{
"
Content-Type
"
:
'
multipart/related; boundary="
'
+
boundary
+
'
"
'
},
data
:
createPostRequest
(
title
.
pop
(),
file
s
.
parent
,
data
:
createPostRequest
(
title
.
pop
(),
file
_list
.
parent
,
blob
,
data
.
type
,
boundary
)
});
},
undefined
);
...
...
@@ -260,7 +266,7 @@
if
(
title
.
length
&&
!
result
.
id
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Not Found
"
,
404
);
}
if
(
!
title
.
length
||
result
.
is
D
ir
!==
deleteDir
)
{
if
(
!
title
.
length
||
result
.
is
_d
ir
!==
deleteDir
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Method Not Allowed
"
,
405
);
}
return
jIO
.
util
.
ajax
({
...
...
@@ -299,7 +305,7 @@
if
(
!
result
.
id
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document:
"
+
id
,
404
);
}
if
(
result
.
is
D
ir
)
{
return
{};
}
if
(
result
.
is
_d
ir
)
{
return
{};
}
throw
new
jIO
.
util
.
jIOError
(
"
Not a directory:
"
+
id
,
404
);
});
};
...
...
@@ -307,16 +313,16 @@
GdriveStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
that
=
this
,
file
s
,
file
_list
,
title
=
splitpath
(
id
),
i
tFi
,
itPa
;
i
,
j
;
id
=
restrictDocumentId
(
id
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
file
s
=
listFiles
([],
that
.
_access_token
);
return
file
s
;
file
_list
=
listDirectory
([],
that
.
_access_token
);
return
file
_list
;
})
.
push
(
function
(
list
)
{
var
result
;
...
...
@@ -326,21 +332,21 @@
.
push
(
function
(
obj
)
{
var
result
=
{};
file
s
=
files
.
fulfillmentValue
;
file
_list
=
file_list
.
fulfillmentValue
;
if
(
title
.
length
)
{
if
(
!
obj
.
id
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document:
"
+
id
,
404
);
}
if
(
!
obj
.
is
D
ir
)
{
if
(
!
obj
.
is
_d
ir
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Not a directory:
"
+
id
,
404
);
}
}
for
(
i
tFi
=
0
;
itFi
<
files
.
length
;
itF
i
+=
1
)
{
for
(
itPa
=
0
;
itPa
<
files
[
itFi
].
parents
.
length
;
itPa
+=
1
)
{
if
(
file
s
[
itF
i
].
mimeType
!==
FOLDER
&&
((
!
title
.
length
&&
file
s
[
itFi
].
parents
[
itPa
].
isRoot
)
||
(
title
.
length
&&
file
s
[
itFi
].
parents
[
itPa
].
id
===
obj
.
id
)))
{
result
[
file
s
[
itF
i
].
title
]
=
{};
for
(
i
=
0
;
i
<
file_list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
file_list
[
i
].
parents
.
length
;
j
+=
1
)
{
if
(
file
_list
[
i
].
mimeType
!==
FOLDER
&&
((
!
title
.
length
&&
file
_list
[
i
].
parents
[
j
].
isRoot
)
||
(
title
.
length
&&
file
_list
[
i
].
parents
[
j
].
id
===
obj
.
id
)))
{
result
[
file
_list
[
i
].
title
]
=
{};
break
;
}
}
...
...
@@ -366,7 +372,7 @@
404
);
}
if
(
result
.
is
D
ir
)
{
if
(
result
.
is
_d
ir
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Method not implemented
"
,
405
);
}
return
jIO
.
util
.
ajax
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment