alchemy-media 0.9.0-alpha.3 → 0.9.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
- ## 0.9.0-alpha.3 (2024-08-16)
1
+ ## 0.9.0-alpha.4 (2024-10-10)
2
2
 
3
- * Implement Alchemy v1.4 `Field` changes
3
+ * Make `MediaRaw#addFile(url)` support data uris too
4
+
5
+ ## 0.9.0-alpha.3 (2024-08-16)
6
+
7
+ * Implement Alchemy v1.4 `Field` changes
4
8
 
5
9
  ## 0.9.0-alpha.2 (2024-02-19)
6
10
 
@@ -192,7 +192,7 @@ MediaRaw.Document.setMethod(function extraImportFromStream(input) {
192
192
  *
193
193
  * @author Jelle De Loecker <jelle@develry.be>
194
194
  * @since 0.0.1
195
- * @version 0.7.1
195
+ * @version 0.9.0
196
196
  *
197
197
  * @param {String} file The path to the file, can be a URL
198
198
  * @param {Object} options
@@ -217,8 +217,11 @@ MediaRaw.setMethod(function addFile(file, options, callback) {
217
217
  file = file.path;
218
218
  }
219
219
 
220
+ let is_url = file.startsWith('http://') || file.startsWith('https://'),
221
+ is_data_uri = !is_url && file.startsWith('data:');
222
+
220
223
  // If the given file is actually a url, we'll need to download it first
221
- if (file.startsWith('http://') || file.startsWith('https://')) {
224
+ if (is_url || is_data_uri) {
222
225
 
223
226
  // Set the url as the origin
224
227
  options.origin = file;
@@ -232,16 +235,18 @@ MediaRaw.setMethod(function addFile(file, options, callback) {
232
235
  return callback(err);
233
236
  }
234
237
 
235
- if (!options.filename) {
236
- options.filename = filename;
237
- }
238
+ if (!is_data_uri) {
239
+ if (!options.filename) {
240
+ options.filename = filename;
241
+ }
238
242
 
239
- if (!options.filename) {
240
- options.filename = Url.parse(file).pathname.split('/').last();
241
- }
243
+ if (!options.filename) {
244
+ options.filename = Url.parse(file).pathname.split('/').last();
245
+ }
242
246
 
243
- if (!options.name) {
244
- options.name = options.filename.beforeLast('.') || options.filename;
247
+ if (!options.name) {
248
+ options.name = options.filename.beforeLast('.') || options.filename;
249
+ }
245
250
  }
246
251
 
247
252
  that.addFile(tempfile, options, callback);
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.3",
4
+ "version": "0.9.0-alpha.4",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "https://github.com/11ways/alchemy-media.git"