nexabase-console 1.0.3 → 1.0.4
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/dist/index.d.ts +8 -1
- package/dist/index.js +32 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -59,10 +59,16 @@ export interface DatabaseReference {
|
|
|
59
59
|
onDataChanged: (callback: (data: any) => void) => void;
|
|
60
60
|
}
|
|
61
61
|
export interface StorageReference {
|
|
62
|
-
|
|
62
|
+
name: string;
|
|
63
|
+
fullPath: string;
|
|
64
|
+
put: (file: File | Blob, onProgress?: (percent: number) => void) => Promise<{
|
|
63
65
|
url: string;
|
|
64
66
|
success: boolean;
|
|
65
67
|
}>;
|
|
68
|
+
delete: () => Promise<{
|
|
69
|
+
success: boolean;
|
|
70
|
+
message?: string;
|
|
71
|
+
}>;
|
|
66
72
|
}
|
|
67
73
|
export interface WriteBatch {
|
|
68
74
|
set: (docRef: DocumentReference, data: any) => WriteBatch;
|
|
@@ -111,6 +117,7 @@ export declare class NexaApp {
|
|
|
111
117
|
};
|
|
112
118
|
storage(): {
|
|
113
119
|
ref: (path?: string) => StorageReference;
|
|
120
|
+
refFromURL: (url: string) => StorageReference;
|
|
114
121
|
};
|
|
115
122
|
_initFirestoreState(): Promise<void>;
|
|
116
123
|
_getOfflineQueue(): Promise<OfflineJob[]>;
|
package/dist/index.js
CHANGED
|
@@ -151,14 +151,38 @@ class NexaApp {
|
|
|
151
151
|
// -----------------------------------------------------------------
|
|
152
152
|
storage() {
|
|
153
153
|
return {
|
|
154
|
-
ref: (path = '') =>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
ref: (path = '') => {
|
|
155
|
+
const name = path.substring(path.lastIndexOf('/') + 1) || path;
|
|
156
|
+
return {
|
|
157
|
+
name,
|
|
158
|
+
fullPath: path,
|
|
159
|
+
put: async (file, onProgress) => {
|
|
160
|
+
const formData = new FormData();
|
|
161
|
+
formData.append('file', file);
|
|
162
|
+
const response = await this.client.post(`/api/project/${this.projectId}/storage/upload`, formData, {
|
|
163
|
+
headers: {
|
|
164
|
+
'Content-Type': 'multipart/form-data'
|
|
165
|
+
},
|
|
166
|
+
onUploadProgress: (progressEvent) => {
|
|
167
|
+
if (onProgress && progressEvent.total) {
|
|
168
|
+
const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
169
|
+
onProgress(percent);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return response.data;
|
|
174
|
+
},
|
|
175
|
+
delete: async () => {
|
|
176
|
+
const response = await this.client.delete(`/api/project/${this.projectId}/storage/${encodeURIComponent(name)}`);
|
|
177
|
+
return response.data;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
refFromURL: (url) => {
|
|
182
|
+
const cleanUrl = url.split('?')[0];
|
|
183
|
+
const filename = decodeURIComponent(cleanUrl.substring(cleanUrl.lastIndexOf('/') + 1));
|
|
184
|
+
return this.storage().ref(filename);
|
|
185
|
+
}
|
|
162
186
|
};
|
|
163
187
|
}
|
|
164
188
|
// -----------------------------------------------------------------
|
package/package.json
CHANGED