Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
jio
Commits
885bd2c1
Commit
885bd2c1
authored
Feb 22, 2018
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cloudoostorage] wip
parent
6b952fc2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
225 additions
and
17 deletions
+225
-17
src/jio.storage/cloudoostorage.js
src/jio.storage/cloudoostorage.js
+225
-17
No files found.
src/jio.storage/cloudoostorage.js
View file @
885bd2c1
/*jslint nomen: true*/
/*global jIO*/
(
function
(
jIO
)
{
/*global jIO
, RSVP, Blob, Uint8Array, DOMParser
*/
(
function
(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
)
{
"
use strict
"
;
var
content_type_dict
=
{
"
application/x-asc-text
"
:
"
docy
"
,
"
application/x-asc-presentation
"
:
""
,
"
application/x-asc-spreadsheet
"
:
""
};
function
b64toBlob
(
b64Data
,
contentType
,
sliceSize
)
{
contentType
=
contentType
||
''
;
sliceSize
=
sliceSize
||
512
;
var
byteCharacters
=
window
.
atob
(
b64Data
),
byteArrays
=
[],
slice
,
byteArray
,
byteNumbers
=
[],
offset
,
i
;
for
(
offset
=
0
;
offset
<
byteCharacters
.
length
;
offset
+=
sliceSize
)
{
slice
=
byteCharacters
.
slice
(
offset
,
offset
+
sliceSize
);
for
(
i
=
0
;
i
<
slice
.
length
;
i
+=
1
)
{
byteNumbers
[
i
]
=
slice
.
charCodeAt
(
i
);
}
byteArray
=
new
Uint8Array
(
byteNumbers
);
byteArrays
.
push
(
byteArray
);
}
return
new
Blob
(
byteArrays
,
{
type
:
contentType
});
}
function
getInfoDocId
(
id
,
attachment_id
)
{
return
'
cloudoo/
'
+
id
+
'
/
'
+
attachment_id
;
}
function
convert
(
storage
,
blob
,
from
,
to
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
result
)
{
// WIP: use something cleaner
var
file
=
result
.
target
.
result
.
split
(
'
base64,
'
)[
1
],
xml
=
'
<?xml version="1.0" encoding="UTF-8"?><methodCall>
'
+
'
<methodName>convertFile</methodName><params>
'
+
'
<param><value><string>
'
+
file
+
'
</string></value></param>
'
+
'
<param><value><string>
'
+
from
+
'
</string></value></param>
'
+
'
<param><value><string>
'
+
to
+
'
</string></value></param></params></methodCall>
'
;
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
storage
.
_url
,
data
:
xml
});
})
.
push
(
function
(
result
)
{
var
data
=
(
new
DOMParser
().
parseFromString
(
result
.
currentTarget
.
response
,
"
application/xml
"
)),
content
=
data
.
getElementsByTagName
(
'
string
'
)[
0
].
textContent
;
if
(
content
!==
undefined
)
{
return
b64toBlob
(
content
,
to
);
}
throw
new
jIO
.
util
.
jIOError
(
'
conversion failed
'
,
400
);
});
}
function
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
{
return
storage
.
get
(
getInfoDocId
(
id
,
attachment_id
))
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
storage
.
get
(
id
)
.
push
(
function
(
doc
)
{
var
format
=
doc
.
content_type
||
undefined
;
if
(
content_type_dict
.
hasOwnProperty
(
format
))
{
format
=
content_type_dict
[
format
];
}
return
{
portal_type
:
"
Conversion Info
"
,
convert_dict
:
{},
format
:
format
,
attachment_id
:
attachment_id
,
doc_id
:
id
};
});
}
throw
error
;
});
}
function
convertAttachment
(
storage
,
id
,
attachment_id
,
format
)
{
var
info_doc
;
return
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc
)
{
info_doc
=
doc
;
return
storage
.
getAttachment
(
id
,
attachment_id
)
.
push
(
function
(
blob
)
{
return
convert
(
storage
,
blob
,
info_doc
.
format
,
format
);
})
.
push
(
function
(
blob
)
{
return
storage
.
putAttachment
(
id
,
attachment_id
+
'
?
'
+
format
)
.
push
(
function
()
{
info_doc
.
convert_dict
[
format
]
=
true
;
return
storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
info_doc
);
})
.
push
(
function
()
{
return
blob
;
});
},
undefined
,
function
(
error
)
{
info_doc
.
convert_dict
[
format
]
=
false
;
return
storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
info_doc
)
.
push
(
function
()
{
throw
error
;
});
});
});
}
function
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
{
var
doc_info
;
return
getOrCreateInfoDoc
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc
)
{
var
format
,
promise_list
=
[];
doc_info
=
doc
;
for
(
format
in
doc
.
convert_list
)
{
if
(
doc
.
convert_list
.
hasOwnProperty
(
format
))
{
if
(
doc
.
convert_list
[
format
])
{
promise_list
.
push
(
storage
.
removeAttachment
(
id
,
attachment_id
+
'
?
'
+
format
)
);
}
}
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
()
{
doc_info
.
convert_list
=
{};
return
doc_info
;
});
}
/**
* The jIO CloudooStorage extension
*
* Convert attachment : att_id
:format ?!
* Convert attachment : att_id
?format
* cloudoo_info :
* {
* portal_type: "C
loudoo Conversion
"
* portal_type: "C
onversion Info
"
* base_format: format de base ( content_type du document )
* to_convert_list: [liste des format a convertir pendant la synchro]
* format_avaible_list : [liste des formats deja disponible]
...
...
@@ -19,7 +168,7 @@
* @constructor
*/
function
CloudooStorage
(
spec
)
{
this
.
_
serveur_url
=
spec
.
serveur_
url
;
this
.
_
url
=
spec
.
url
;
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
}
...
...
@@ -35,24 +184,83 @@
CloudooStorage
.
prototype
.
remove
=
function
()
{
return
this
.
_sub_storage
.
remove
.
apply
(
this
.
_sub_storage
,
arguments
);
};
CloudooStorage
.
prototype
.
getAttachment
=
function
()
{
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
CloudooStorage
.
prototype
.
getAttachment
=
function
(
id
,
attachment_id
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
undefined
,
function
(
error
)
{
var
att_id_list
=
attachment_id
.
split
(
'
?
'
);
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
&&
att_id_list
.
length
>
1
)
{
return
convertAttachment
(
storage
,
id
,
att_id_list
[
0
],
att_id_list
[
1
]
);
}
throw
error
;
});
};
CloudooStorage
.
prototype
.
putAttachment
=
function
()
{
// putAttachment sur l'id de base suprime les conversions existente
// Les refaire sur la synchro ?
//
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
CloudooStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
function
()
{
var
att_id_list
=
attachment_id
.
split
(
'
?
'
);
if
(
att_id_list
.
length
===
1
)
{
return
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
.
push
(
function
(
doc_info
)
{
return
storage
.
put
(
getInfoDocId
(
id
,
attachment_id
),
doc_info
);
});
}
});
};
CloudooStorage
.
prototype
.
removeAttachment
=
function
()
{
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
CloudooStorage
.
prototype
.
removeAttachment
=
function
(
id
,
attachment_id
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
function
()
{
var
att_id_list
=
attachment_id
.
split
(
'
?
'
);
if
(
att_id_list
.
length
===
1
)
{
return
removeConvertedAttachment
(
storage
,
id
,
attachment_id
)
.
push
(
function
()
{
return
storage
.
remove
(
getInfoDocId
(
id
,
attachment_id
));
});
}
});
};
CloudooStorage
.
prototype
.
allAttachments
=
function
()
{
return
this
.
_sub_storage
.
allAttachments
.
apply
(
this
.
_sub_storage
,
arguments
);
};
CloudooStorage
.
prototype
.
repair
=
function
()
{
return
this
.
_sub_storage
.
repair
.
apply
(
this
.
_sub_storage
,
arguments
);
var
storage
=
this
;
return
this
.
_sub_storage
.
repair
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
function
()
{
return
storage
.
allDocs
({
query
:
'
portal_type: "Conversion Info"
'
,
select_list
:
[
'
convert_list
'
,
'
doc_id
'
,
'
attachment_id
'
]
});
})
.
push
(
function
(
result
)
{
var
i
,
promise_list
=
[],
format
,
value
;
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
value
=
result
.
data
.
rows
[
i
].
value
;
for
(
format
in
value
.
convert_list
)
{
if
(
value
.
convert_list
.
hasOwnProperty
(
format
)
&&
value
.
convert_list
[
format
]
===
false
)
{
promise_list
.
push
(
convertAttachment
(
storage
,
value
.
doc_id
,
value
.
attachment_id
,
format
));
}
}
}
return
RSVP
.
all
(
promise_list
);
});
};
CloudooStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
this
.
_sub_storage
.
hasCapacity
(
name
);
...
...
@@ -64,4 +272,4 @@
jIO
.
addStorage
(
'
cloudoo
'
,
CloudooStorage
);
}(
jIO
));
}(
jIO
,
Uint8Array
,
Blob
,
RSVP
,
DOMParser
));
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