summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
committerJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
commitef4f212fc1482136dba1e690ec589b315b4a377f (patch)
tree0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows
parent5fa81da81260d65113f57a293b6256d334fe8e2d (diff)
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows')
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js86
1 files changed, 70 insertions, 16 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js
index 99e0af15..ff257d52 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js
+++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js
@@ -10,6 +10,36 @@ module.exports = {
var fileOrFileArray = args[2];
//Web link
var url = args[3];
+
+ var folder = Windows.Storage.ApplicationData.current.temporaryFolder;
+
+ var getExtension = function (strBase64) {
+ return strBase64.substring(strBase64.indexOf("/") + 1, strBase64.indexOf(";base64"));
+ };
+
+ var replaceAll = function (str, find, replace) {
+ return str.replace(new RegExp(find, 'g'), replace);
+ };
+
+ var sanitizeFilename = function (name) {
+ return replaceAll(name, "[:\\\\/*?|<> ]", "_");
+ };
+
+ var getFileName = function (position, fileExtension) {
+ var fileName = (subject ? sanitizeFilename(subject) : "file") + (position == 0 ? "" : "_" + position) + "." + fileExtension;
+ return fileName;
+ };
+
+ var createTemporalFile = function (fileName, buffer) {
+
+ var filePath = "";
+ return folder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
+ filePath = file.path;
+ return Windows.Storage.FileIO.writeBufferAsync(file, buffer);
+ }).then(function(){
+ return Windows.Storage.StorageFile.getFileFromPathAsync(filePath);
+ });
+ };
var doShare = function (e) {
e.request.data.properties.title = subject?subject: "Sharing";
@@ -19,25 +49,49 @@ module.exports = {
var deferral = e.request.getDeferral();
var storageItems = [];
var filesCount = fileOrFileArray.length;
+
+ var completeFile = function () {
+ if (!--filesCount) {
+ storageItems.length && e.request.data.setStorageItems(storageItems);
+ deferral.complete();
+ }
+ };
+
for (var i = 0; i < fileOrFileArray.length; i++) {
- Windows.Storage.StorageFile.getFileFromPathAsync(fileOrFileArray[i]).done(
- function (file) {
- storageItems.push(file);
- if (!--filesCount) {
- e.request.data.setStorageItems(storageItems);
- deferral.complete();
- }
- },
- function() {
- if (!--filesCount) {
- e.request.data.setStorageItems(storageItems);
- deferral.complete();
+
+ var file = fileOrFileArray[i];
+ if (file.indexOf("data:") >= 0) {
+ var fileName = getFileName(i, getExtension(file));
+ var buffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(file.split(',')[1]);
+ if (buffer) {
+ createTemporalFile(fileName, buffer).done(
+ function (file) {
+ storageItems.push(file);
+ completeFile();
+ },
+ function () {
+ completeFile();
+ }
+ );
+ }
+ else {
+ completeFile();
+ }
+ }
+ else {
+ Windows.Storage.StorageFile.getFileFromPathAsync(file).done(
+ function (file) {
+ storageItems.push(file);
+ completeFile();
+ },
+ function () {
+ completeFile();
}
- }
- );
+ );
+ }
}
}
- }
+ };
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
@@ -96,7 +150,7 @@ module.exports = {
);
}
}
- }
+ };
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();