@chat21/chat21-ionic 3.4.30-rc1 → 3.4.30-rc2

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/CHANGELOG.md CHANGED
@@ -8,6 +8,9 @@
8
8
  ### **Copyrigth**:
9
9
  *Tiledesk SRL*
10
10
 
11
+ # 3.4.29-rc2
12
+ - **changed**: minor updates on API to upload file/image into chat
13
+
11
14
  # 3.4.29-rc1
12
15
  - **changed**: API for upload a file/image into chat
13
16
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
3
  "author": "Tiledesk SRL",
4
- "version": "3.4.30-rc1",
4
+ "version": "3.4.30-rc2",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -41,5 +41,6 @@ export abstract class UploadService {
41
41
  abstract uploadProfile(userId: string, upload: UploadModel): Promise<any>;
42
42
  abstract delete(userId: string, path: string): Promise<any>;
43
43
  abstract deleteFile(userId: string, path: string): Promise<any>;
44
+ abstract deleteAsset(userId: string, path: string): Promise<any>
44
45
  abstract deleteProfile(userId: string, path: string): Promise<any>
45
46
  }
@@ -323,6 +323,10 @@ export class FirebaseUploadService extends UploadService {
323
323
  })
324
324
  }
325
325
 
326
+ public async deleteAsset(userId: string, path: string): Promise<any>{
327
+ return this.deleteProfile(userId, path);
328
+ }
329
+
326
330
  public async deleteProfile(userId: string, path: string): Promise<any>{
327
331
  const that = this;
328
332
  const file_name_photo = 'photo.jpg';
@@ -51,26 +51,32 @@ export class NativeUploadService extends UploadService {
51
51
  //USE IMAGE API
52
52
  const url = this.URL_TILEDESK_UPLOAD + 'images/users'
53
53
  return new Promise((resolve, reject) => {
54
- that.http.post(url, formData, requestOptions).subscribe(data => {
55
- const downloadURL = this.URL_TILEDESK_UPLOAD + 'images?path=' + encodeURIComponent(data?.['filename']);
56
- resolve({downloadURL : downloadURL, src: downloadURL})
57
- // that.BSStateUpload.next({upload: upload});
58
- }, (error) => {
59
- reject(error)
54
+ that.http.post(url, formData, requestOptions).pipe(first()).subscribe({
55
+ next: (data) => {
56
+ const downloadURL = this.URL_TILEDESK_UPLOAD + 'images?path=' + encodeURIComponent(data?.['filename']);
57
+ resolve({downloadURL : downloadURL, src: downloadURL})
58
+ // that.BSStateUpload.next({upload: upload});
59
+ },
60
+ error: (error) => {
61
+ reject(error)
62
+ }
60
63
  });
61
64
  });
62
65
  } else {
63
66
  //USE FILE API
64
67
  const url = this.URL_TILEDESK_UPLOAD + 'files/users'
65
68
  return new Promise((resolve, reject) => {
66
- that.http.post(url, formData, requestOptions).subscribe(data => {
67
- const src = this.URL_TILEDESK_UPLOAD + 'files?path=' + encodeURI(data['filename']);
68
- const downloadURL = this.URL_TILEDESK_UPLOAD + 'files/download' + '?path=' + encodeURI(data['filename']);
69
- resolve({downloadURL : downloadURL, src: src})
70
- // that.BSStateUpload.next({upload: upload});
71
- }, (error) => {
72
- this.logger.error('[NATIVE UPLOAD] - ERROR upload new file ', error)
73
- reject(error)
69
+ that.http.post(url, formData, requestOptions).pipe(first()).subscribe({
70
+ next: (data) => {
71
+ const src = this.URL_TILEDESK_UPLOAD + 'files?path=' + encodeURIComponent(data['filename']);
72
+ const downloadURL = this.URL_TILEDESK_UPLOAD + 'files/download' + '?path=' + encodeURIComponent(data['filename']);
73
+ resolve({downloadURL : downloadURL, src: src})
74
+ // that.BSStateUpload.next({upload: upload});
75
+ },
76
+ error: (error) => {
77
+ this.logger.error('[NATIVE UPLOAD] - ERROR upload new file ', error)
78
+ reject(error)
79
+ }
74
80
  });
75
81
  });
76
82
  }
@@ -92,8 +98,9 @@ export class NativeUploadService extends UploadService {
92
98
  return new Promise((resolve, reject) => {
93
99
  that.http.post(url, formData, requestOptions).pipe(first()).subscribe({
94
100
  next: (data) => {
95
- const downloadURL = this.getBaseUrl() + 'files' + '?path=' + encodeURIComponent(data['filename']);
96
- resolve({downloadURL : downloadURL, src: downloadURL})
101
+ const src = this.URL_TILEDESK_UPLOAD + 'files?path=' + encodeURIComponent(data['filename']);
102
+ const downloadURL = this.URL_TILEDESK_UPLOAD + 'files/download?path=' + encodeURIComponent(data['filename']);
103
+ resolve({downloadURL : downloadURL, src: src})
97
104
  },
98
105
  error: (error) => {
99
106
  reject(error)
@@ -112,19 +119,14 @@ export class NativeUploadService extends UploadService {
112
119
  formData.append('file', upload.file);
113
120
 
114
121
  const that = this;
115
- const url = this.URL_TILEDESK_FILE + `/assets?expiration=${expiration}`
122
+ const queryString = expiration !== undefined ? `?expiration=${encodeURIComponent(String(expiration))}` : ''
123
+ const url = this.URL_TILEDESK_FILE + `/assets${queryString}`
116
124
  return new Promise((resolve, reject) => {
117
125
  that.http.post(url, formData, requestOptions).pipe(first()).subscribe({
118
126
  next: (data) => {
119
- // API responses can vary; try common fields first, otherwise fallback to filename/path.
120
- const directUrl = data?.['downloadURL'] || data?.['url'] || data?.['src'];
121
- const filenameOrPath = data?.['filename'] || data?.['path'];
122
- const downloadURL = directUrl || (filenameOrPath ? (this.getBaseUrl() + 'files' + '?path=' + encodeURIComponent(filenameOrPath)) : null);
123
- if (!downloadURL) {
124
- reject(new Error('[NATIVE UPLOAD] uploadAsset: unexpected response payload'))
125
- return;
126
- }
127
- resolve({ downloadURL: downloadURL, src: downloadURL })
127
+ const src = this.URL_TILEDESK_UPLOAD + 'files?path=' + data['filename'];
128
+ const downloadURL = this.URL_TILEDESK_UPLOAD + 'files/download?path=' + encodeURIComponent(data['filename']);
129
+ resolve({downloadURL : downloadURL, src: src})
128
130
  },
129
131
  error: (error) => {
130
132
  reject(error)
@@ -145,8 +147,8 @@ export class NativeUploadService extends UploadService {
145
147
 
146
148
  // USE IMAGE API
147
149
  const that = this;
148
- const botId = userId?.startsWith('bot_') ? userId.substring('bot_'.length) : userId
149
- const url = this.URL_TILEDESK_FILE + `/users/photo?bot_id=${botId}`
150
+ const queryString = userId?.startsWith('bot_') ? `?bot_id=${encodeURIComponent(userId.substring('bot_'.length))}` : ''
151
+ const url = this.URL_TILEDESK_FILE + `/users/photo${queryString}`
150
152
  return new Promise((resolve, reject) => {
151
153
  that.http.put(url, formData, requestOptions).pipe(first()).subscribe({
152
154
  next: (data) => {
@@ -173,12 +175,15 @@ export class NativeUploadService extends UploadService {
173
175
  const that = this;
174
176
  const url = this.URL_TILEDESK_UPLOAD + 'images/users' + '?path=' + path.split('path=')[1]
175
177
  return new Promise((resolve, reject) => {
176
- that.http.delete(url, requestOptions).subscribe(data => {
177
- // const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['filename'];
178
- resolve(true)
179
- // that.BSStateUpload.next({upload: upload});
180
- }, (error) => {
181
- reject(error)
178
+ that.http.delete(url, requestOptions).pipe(first()).subscribe({
179
+ next: (data) => {
180
+ // const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['filename'];
181
+ resolve(true)
182
+ // that.BSStateUpload.next({upload: upload});
183
+ },
184
+ error: (error) => {
185
+ reject(error)
186
+ }
182
187
  });
183
188
  });
184
189
  }
@@ -208,6 +213,10 @@ export class NativeUploadService extends UploadService {
208
213
  });
209
214
  }
210
215
 
216
+ deleteAsset(userId: string, path: string): Promise<any>{
217
+ return this.deleteFile(userId, path);
218
+ }
219
+
211
220
  deleteProfile(userId: string, path: string): Promise<any>{
212
221
  this.logger.log('[NATIVE UPLOAD] - delete image ... upload', userId)
213
222
  const headers = new HttpHeaders({