apps-sdk 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/libraries/Networking.js +1 -1
- package/src/libraries/Storage.js +56 -18
package/package.json
CHANGED
|
@@ -85,7 +85,7 @@ class Networking {
|
|
|
85
85
|
|
|
86
86
|
async request(url, data = {}, encrypt = this.DEFAULT_ENCRYPT_VALUE) {
|
|
87
87
|
data = { ...Session.sessionData, ...data };
|
|
88
|
-
let dataConsoleLog = data;
|
|
88
|
+
let dataConsoleLog = JSON.parse(JSON.stringify(data));
|
|
89
89
|
if (dataConsoleLog && dataConsoleLog.img) {
|
|
90
90
|
dataConsoleLog.img = dataConsoleLog.img.substring(0, 50) + '...';
|
|
91
91
|
}
|
package/src/libraries/Storage.js
CHANGED
|
@@ -4,6 +4,8 @@ import * as FileSystem from 'expo-file-system';
|
|
|
4
4
|
import * as Sharing from 'expo-sharing';
|
|
5
5
|
import utils from "./Utils";
|
|
6
6
|
|
|
7
|
+
const CREATIONS_DIR = `${FileSystem.documentDirectory}/creations`
|
|
8
|
+
|
|
7
9
|
class Storage {
|
|
8
10
|
async storeData(key, value) {
|
|
9
11
|
try {
|
|
@@ -46,26 +48,62 @@ class Storage {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
async handleDownloadImage(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
async handleDownloadImage(base64, fileName) {
|
|
52
|
+
try {
|
|
53
|
+
const { status } = await MediaLibrary.requestPermissionsAsync();
|
|
54
|
+
if (status === 'granted') {
|
|
55
|
+
let fileUri = FileSystem.documentDirectory + fileName + '.jpg';
|
|
56
|
+
if (utils.isBase64Image(base64)) {
|
|
57
|
+
console.log('DOWNLOADIMAGE isBase64Image');
|
|
58
|
+
const data = await fetch(base64);
|
|
59
|
+
const blob = await data.blob();
|
|
60
|
+
await FileSystem.writeAsStringAsync(fileUri, blob, { encoding: FileSystem.EncodingType.Base64 });
|
|
61
|
+
} else {
|
|
62
|
+
console.log('DOWNLOADIMAGE isNOTBase64Image');
|
|
63
|
+
const { uri: localUri } = await FileSystem.downloadAsync(base64, fileUri);
|
|
64
|
+
fileUri = localUri;
|
|
65
|
+
}
|
|
66
|
+
const asset = await MediaLibrary.createAssetAsync(fileUri);
|
|
67
|
+
const albums = await MediaLibrary.getAlbumsAsync();
|
|
68
|
+
let album = albums.find(a => a.title === 'Camera' || a.title === 'Camera Roll' || a.title === 'Pictures');
|
|
69
|
+
console.log('DOWNLOADIMAGE album:', album);
|
|
70
|
+
if (album) {
|
|
71
|
+
console.log('DOWNLOADIMAGE addAssetsToAlbumAsync');
|
|
72
|
+
await MediaLibrary.addAssetsToAlbumAsync([asset], album, false);
|
|
73
|
+
} else {
|
|
74
|
+
console.log('DOWNLOADIMAGE createAlbumAsync');
|
|
75
|
+
album = await MediaLibrary.createAlbumAsync('Descargas', asset, false);
|
|
76
|
+
}
|
|
64
77
|
} else {
|
|
65
|
-
|
|
78
|
+
console.log('Permiso de galería denegado');
|
|
66
79
|
}
|
|
67
|
-
}
|
|
68
|
-
console.
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error al guardar la imagen en la biblioteca de fotos:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async handleDownloadImageToCreations(base64Image, fileName, data) {
|
|
86
|
+
try {
|
|
87
|
+
const directoryUri = CREATIONS_DIR + '/' + fileName;
|
|
88
|
+
console.log('handleDownloadImageToCreations directoryUri:', directoryUri);
|
|
89
|
+
await this.createCreationsDir(directoryUri);
|
|
90
|
+
const fileUri = CREATIONS_DIR + '/' + fileName + '.jpg';
|
|
91
|
+
console.log('handleDownloadImageToCreations fileUri:', fileUri);
|
|
92
|
+
const fileData = CREATIONS_DIR + '/' + fileName + '/data.json';
|
|
93
|
+
console.log('handleDownloadImageToCreations fileData:', fileData);
|
|
94
|
+
await FileSystem.writeAsStringAsync(fileUri, base64Image, { encoding: FileSystem.EncodingType.Base64,})
|
|
95
|
+
await FileSystem.writeAsStringAsync(fileData, JSON.stringify(data), { encoding: FileSystem.EncodingType.UTF8,})
|
|
96
|
+
return { directoryUri, fileUri, fileData }
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error('Error al guardar la imagen en FileSystem:', error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async createCreationsDir(dirName) {
|
|
103
|
+
try {
|
|
104
|
+
await FileSystem.makeDirectoryAsync(`${CREATIONS_DIR}/${dirName}`, { intermediates: true });
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error('Error al crear el directorio de creaciones:', error);
|
|
69
107
|
}
|
|
70
108
|
}
|
|
71
109
|
|