alchemy-media 0.9.0-alpha → 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 +8 -0
- package/helper_field/file_field_type.js +19 -18
- package/model/media_file_model.js +22 -2
- package/model/media_raw_model.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -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.
|
|
71
|
+
* @version 0.9.0
|
|
72
72
|
*
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {Datasource} datasource
|
|
76
|
-
* @param {Function} callback
|
|
73
|
+
* @param {Alchemy.OperationalContext.SaveFieldToDatasource} context
|
|
74
|
+
* @param {*} value
|
|
77
75
|
*
|
|
78
|
-
* @return {
|
|
76
|
+
* @return {Pledge<ObjectId>|ObjectId}
|
|
79
77
|
*/
|
|
80
|
-
FileField.setMethod(function _toDatasource(
|
|
78
|
+
FileField.setMethod(function _toDatasource(context, value) {
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
let options = Object.assign({}, this.options);
|
|
83
81
|
|
|
84
|
-
|
|
82
|
+
let pass_through_media_file = typeof value == 'string' && (value.startsWith('http') || value.startsWith('/'));
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
224
|
+
pledge.resolve(result);
|
|
220
225
|
});
|
|
226
|
+
|
|
227
|
+
return pledge;
|
|
221
228
|
});
|
|
222
229
|
|
|
223
230
|
/**
|
|
@@ -254,4 +261,17 @@ MediaFile.setMethod(function addFile(file, options, callback) {
|
|
|
254
261
|
});
|
|
255
262
|
|
|
256
263
|
return pledge;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Get a Inode.File instance
|
|
268
|
+
*
|
|
269
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
270
|
+
* @since 0.9.0
|
|
271
|
+
* @version 0.9.0
|
|
272
|
+
*
|
|
273
|
+
* @return {Alchemy.Inode.File}
|
|
274
|
+
*/
|
|
275
|
+
MediaFile.setDocumentMethod(function getFile() {
|
|
276
|
+
return new Classes.Alchemy.Inode.File(this.path);
|
|
257
277
|
});
|
package/model/media_raw_model.js
CHANGED
|
@@ -557,4 +557,17 @@ MediaRaw.setMethod(function getPathFromId(objectId) {
|
|
|
557
557
|
filePath = path.resolve(this.basePath, year, month, String(objectId));
|
|
558
558
|
|
|
559
559
|
return filePath;
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Get a Inode.File instance
|
|
564
|
+
*
|
|
565
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
566
|
+
* @since 0.9.0
|
|
567
|
+
* @version 0.9.0
|
|
568
|
+
*
|
|
569
|
+
* @return {Alchemy.Inode.File}
|
|
570
|
+
*/
|
|
571
|
+
MediaRaw.setDocumentMethod(function getFile() {
|
|
572
|
+
return new Classes.Alchemy.Inode.File(this.path);
|
|
560
573
|
});
|