apps-sdk 1.0.25 → 1.0.26
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/Storage.js +86 -6
- package/types/index.d.ts +4 -0
package/package.json
CHANGED
package/src/libraries/Storage.js
CHANGED
|
@@ -87,11 +87,13 @@ class Storage {
|
|
|
87
87
|
const directoryUri = CREATIONS_DIR + '/' + fileName;
|
|
88
88
|
console.log('handleDownloadImageToCreations directoryUri:', directoryUri);
|
|
89
89
|
await this.createCreationsDir(directoryUri);
|
|
90
|
-
const fileUri =
|
|
90
|
+
const fileUri = directoryUri + '/image.jpg';
|
|
91
91
|
console.log('handleDownloadImageToCreations fileUri:', fileUri);
|
|
92
|
-
const fileData =
|
|
92
|
+
const fileData = directoryUri + '/data.json';
|
|
93
93
|
console.log('handleDownloadImageToCreations fileData:', fileData);
|
|
94
|
-
|
|
94
|
+
console.log('handleDownloadImageToCreations base64Image:', base64Image.substring(0, 50) + '...');
|
|
95
|
+
const base64Data = base64Image.replace(/^data:image\/[a-z]+;base64,/, '');
|
|
96
|
+
await FileSystem.writeAsStringAsync(fileUri, base64Data, { encoding: FileSystem.EncodingType.Base64,})
|
|
95
97
|
await FileSystem.writeAsStringAsync(fileData, JSON.stringify(data), { encoding: FileSystem.EncodingType.UTF8,})
|
|
96
98
|
return { directoryUri, fileUri, fileData }
|
|
97
99
|
} catch (error) {
|
|
@@ -99,11 +101,89 @@ class Storage {
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
async
|
|
104
|
+
async handleDownloadImageToGallery(imageURI) {
|
|
103
105
|
try {
|
|
104
|
-
|
|
106
|
+
const { status } = await MediaLibrary.requestPermissionsAsync();
|
|
107
|
+
if(status !== 'granted') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return await MediaLibrary.createAssetAsync(imageURI);
|
|
111
|
+
} catch(error) {
|
|
112
|
+
console.error('Error al guardar la imagen en la galería:', error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async getCreations() {
|
|
117
|
+
try {
|
|
118
|
+
const info = await FileSystem.getInfoAsync(CREATIONS_DIR);
|
|
119
|
+
if (!info.exists) {
|
|
120
|
+
console.error('El directorio no existe:', CREATIONS_DIR);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const directories = await FileSystem.readDirectoryAsync(CREATIONS_DIR);
|
|
125
|
+
console.log('getCreations directories:', directories);
|
|
126
|
+
const directoryData = [];
|
|
127
|
+
|
|
128
|
+
for (const directory of directories) {
|
|
129
|
+
const directoryUri = `${CREATIONS_DIR}/${directory}`;
|
|
130
|
+
const imageUri = `${directoryUri}/image.jpg`;
|
|
131
|
+
const dataUri = `${directoryUri}/data.json`;
|
|
132
|
+
|
|
133
|
+
const imageData = await FileSystem.readAsStringAsync(imageUri, { encoding: FileSystem.EncodingType.Base64 });
|
|
134
|
+
const jsonData = await FileSystem.readAsStringAsync(dataUri, { encoding: FileSystem.EncodingType.UTF8 });
|
|
135
|
+
console.log('getCreations jsonData:', jsonData);
|
|
136
|
+
|
|
137
|
+
let dataParsed = JSON.parse(jsonData)
|
|
138
|
+
console.log('getCreations dataParsed:', dataParsed);
|
|
139
|
+
directoryData.push({
|
|
140
|
+
url: imageUri,
|
|
141
|
+
job_id: directory,
|
|
142
|
+
data: dataParsed['_j'] || dataParsed
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
directoryData.sort((a, b) => {
|
|
147
|
+
const dateA = new Date(a.data.creationDate);
|
|
148
|
+
const dateB = new Date(b.data.creationDate);
|
|
149
|
+
return dateB.getTime() - dateA.getTime();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return directoryData;
|
|
105
153
|
} catch (error) {
|
|
106
|
-
console.error('Error al
|
|
154
|
+
console.error('Error al obtener los datos de las imágenes:', error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async deleteCreation (dirName) {
|
|
159
|
+
const directoryUri = `${CREATIONS_DIR}/${dirName}`;
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await FileSystem.deleteAsync(directoryUri, { idempotent: true });
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error("Error deleting directory:", error);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
async deleteAllCreations() {
|
|
169
|
+
try {
|
|
170
|
+
const dirNames = await FileSystem.readDirectoryAsync(CREATIONS_DIR);
|
|
171
|
+
|
|
172
|
+
for (const dirName of dirNames) {
|
|
173
|
+
const directoryUri = `${CREATIONS_DIR}/${dirName}`;
|
|
174
|
+
await FileSystem.deleteAsync(directoryUri, { idempotent: true });
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error("Error deleting all directories:", error);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
async createCreationsDir (dirName) {
|
|
182
|
+
const directory = await FileSystem.getInfoAsync(dirName)
|
|
183
|
+
if (!directory.exists) {
|
|
184
|
+
console.log('createCreationsDir', dirName);
|
|
185
|
+
await FileSystem.makeDirectoryAsync(dirName, { intermediates: true })
|
|
186
|
+
const newDirectory = await FileSystem.getInfoAsync(dirName)
|
|
107
187
|
}
|
|
108
188
|
}
|
|
109
189
|
|
package/types/index.d.ts
CHANGED
|
@@ -67,6 +67,10 @@ declare module 'apps-sdk' {
|
|
|
67
67
|
handleShareFile(url: string, filename: string): Promise<void>;
|
|
68
68
|
createCreationsDir(dirName: string): Promise<void>;
|
|
69
69
|
handleDownloadImageToCreations(base64Image: string, fileName: string, data: object): Promise<void>;
|
|
70
|
+
getCreations(): Promise<any>;
|
|
71
|
+
deleteCreation(dirName: string): Promise<void>;
|
|
72
|
+
deleteAllCreations(): Promise<void>;
|
|
73
|
+
handleDownloadImageToGallery(imageURI: string): Promise<void>;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
export class Utils {
|