alchemy-media 0.9.0-alpha.2 → 0.9.0-alpha.3

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
@@ -1,3 +1,7 @@
1
+ ## 0.9.0-alpha.3 (2024-08-16)
2
+
3
+ * Implement Alchemy v1.4 `Field` changes
4
+
1
5
  ## 0.9.0-alpha.2 (2024-02-19)
2
6
 
3
7
  * Add `getFile()` method to `MediaFile` and `MediaRaw` documents
@@ -68,30 +68,31 @@ if (Blast.isBrowser) {
68
68
  *
69
69
  * @author Jelle De Loecker <jelle@develry.be>
70
70
  * @since 0.2.0
71
- * @version 0.2.0
71
+ * @version 0.9.0
72
72
  *
73
- * @param {Mixed} value
74
- * @param {Object} data
75
- * @param {Datasource} datasource
76
- * @param {Function} callback
73
+ * @param {Alchemy.OperationalContext.SaveFieldToDatasource} context
74
+ * @param {*} value
77
75
  *
78
- * @return {Mixed}
76
+ * @return {Pledge<ObjectId>|ObjectId}
79
77
  */
80
- FileField.setMethod(function _toDatasource(value, data, datasource, callback) {
78
+ FileField.setMethod(function _toDatasource(context, value) {
81
79
 
82
- var options = Object.assign({}, this.options);
80
+ let options = Object.assign({}, this.options);
83
81
 
84
- if (typeof value == 'string' && (value.startsWith('http') || value.startsWith('/'))) {
82
+ let pass_through_media_file = typeof value == 'string' && (value.startsWith('http') || value.startsWith('/'));
85
83
 
86
- this.getModel('MediaFile').addFile(value, options, function addedFile(err, result) {
87
-
88
- if (err != null) {
89
- return callback(err);
90
- }
84
+ if (!pass_through_media_file) {
85
+ if (value && typeof value == 'object' && !alchemy.isObjectId(value)) {
86
+ pass_through_media_file = true;
87
+ }
88
+ }
91
89
 
92
- callback(null, result._id);
93
- });
94
- } else {
95
- callback(null, this.cast(value));
90
+ if (!pass_through_media_file) {
91
+ return this.cast(value);
96
92
  }
93
+
94
+ return Swift.waterfall(
95
+ () => this.getModel('MediaFile').addFile(value, options),
96
+ result => result._id,
97
+ );
97
98
  });
@@ -151,6 +151,8 @@ MediaFile.Document.setFieldGetter(function path() {
151
151
  *
152
152
  * @param {String|ObjectID} id
153
153
  * @param {Function} callback
154
+ *
155
+ * @return {Pledge<Alchemy.Document.MediaFile>}
154
156
  */
155
157
  MediaFile.setMethod(function getFile(id, callback) {
156
158
 
@@ -165,6 +167,9 @@ MediaFile.setMethod(function getFile(id, callback) {
165
167
  }
166
168
  };
167
169
 
170
+ let pledge = new Swift();
171
+ pledge.done(callback);
172
+
168
173
  Function.series(function findInExtra(next) {
169
174
  if (!alchemy.plugins.media.extra_media_model) {
170
175
  return next();
@@ -209,15 +214,17 @@ MediaFile.setMethod(function getFile(id, callback) {
209
214
  }, async function done(err) {
210
215
 
211
216
  if (err) {
212
- return callback(err);
217
+ return pledge.reject(err);
213
218
  }
214
219
 
215
220
  if (!result.MediaRaw) {
216
221
  await result.populate('MediaRaw');
217
222
  }
218
223
 
219
- callback(null, result);
224
+ pledge.resolve(result);
220
225
  });
226
+
227
+ return pledge;
221
228
  });
222
229
 
223
230
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "alchemy-media",
3
3
  "description": "The media plugin for Alchemy",
4
- "version": "0.9.0-alpha.2",
4
+ "version": "0.9.0-alpha.3",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "https://github.com/11ways/alchemy-media.git"