Skip to content

Commit

Permalink
add fallback for loading remote URLs instead of instantly throwing 40…
Browse files Browse the repository at this point in the history
…0 automatically
  • Loading branch information
rikschennink committed Jun 22, 2020
1 parent 7aea132 commit ecbc3b1
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 35 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog

## 4.17.2
## 4.18.0

- Add fallback for `fetch` when loading remote URLs, if no custom fetch supplied, will use default request.
- Add TypeScript dynamic label types.
- Fix issue where order of files wasn't correct when setting initial files.



## 4.17.1

- Fix issue where reorder event was fired on each drag interaction, now only fires when order changes.
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.17.1
* FilePond 4.18.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
12 changes: 7 additions & 5 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.17.1
* FilePond 4.18.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -3997,7 +3997,7 @@ const getItemById = (items, itemId) => {
return items[index] || null;
};

const fetchLocal = (url, load, error, progress, abort, headers) => {
const fetchBlob = (url, load, error, progress, abort, headers) => {
const request = sendRequest(null, url, {
method: 'GET',
responseType: 'blob'
Expand Down Expand Up @@ -4647,10 +4647,12 @@ const actions = (dispatch, query, state) => ({
// this creates a function that loads the file based on the type of file (string, base64, blob, file) and location of file (local, remote, limbo)
createFileLoader(
origin === FileOrigin.INPUT
? // input
? // input, if is remote, see if should use custom fetch, else use default fetchBlob
isString(source) && isExternalURL(source)
? createFetchFunction(url, fetch) // remote url
: fetchLocal // local url
? fetch
? createFetchFunction(url, fetch)
: fetchBlob // remote url
: fetchBlob // try to fetch url
: // limbo or local
origin === FileOrigin.LIMBO
? createFetchFunction(url, restore) // limbo
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.17.1
* FilePond 4.18.0
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -6378,7 +6378,7 @@
return items[index] || null;
};

var fetchLocal = function fetchLocal(
var fetchBlob = function fetchBlob(
url,
load,
error,
Expand Down Expand Up @@ -7117,10 +7117,12 @@
// this creates a function that loads the file based on the type of file (string, base64, blob, file) and location of file (local, remote, limbo)
createFileLoader(
origin === FileOrigin.INPUT
? // input
? // input, if is remote, see if should use custom fetch, else use default fetchBlob
isString(source) && isExternalURL(source)
? createFetchFunction(url, fetch) // remote url
: fetchLocal // local url
? fetch
? createFetchFunction(url, fetch)
: fetchBlob // remote url
: fetchBlob // try to fetch url
: // limbo or local
origin === FileOrigin.LIMBO
? createFetchFunction(url, restore) // limbo
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@
// Create the FilePond instance
const pond = FilePond.create(inputElement, {
allowMultiple: true,
allowReorder: true,
instantUpload: false,
server: {
load: (source,load) => {
fetch(source).then(res => res.blob()).then(load);
}
},
files: [
{ source:'index.html', options: { type:'local'} },
{ source:'banner.js', options: { type:'local'} },
]
allowReorder: true
});

// Easy console access for testing purposes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.17.1",
"version": "4.18.0",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
8 changes: 4 additions & 4 deletions src/js/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { InteractionMethod } from './enum/InteractionMethod';
import { applyFilterChain, applyFilters } from '../filter';
import { createItemAPI } from './utils/createItemAPI';
import { createResponse } from '../utils/createResponse';
import { fetchLocal } from './utils/fetchLocal';
import { fetchBlob } from './utils/fetchBlob';
import { isExternalURL } from '../utils/isExternalURL';
import { isString } from '../utils/isString';
import { isFile } from '../utils/isFile';
Expand Down Expand Up @@ -586,10 +586,10 @@ export const actions = (dispatch, query, state) => ({
// this creates a function that loads the file based on the type of file (string, base64, blob, file) and location of file (local, remote, limbo)
createFileLoader(
origin === FileOrigin.INPUT
// input
// input, if is remote, see if should use custom fetch, else use default fetchBlob
? isString(source) && isExternalURL(source)
? createFetchFunction(url, fetch) // remote url
: fetchLocal // local url
? (fetch ? createFetchFunction(url, fetch) : fetchBlob) // remote url
: fetchBlob // try to fetch url
// limbo or local
: origin === FileOrigin.LIMBO
? createFetchFunction(url, restore) // limbo
Expand Down
2 changes: 1 addition & 1 deletion src/js/app/utils/createFileLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const createFileLoader = fetchFn => {

// loads a url
const loadURL = url => {

// is remote url and no fetch method supplied
if (!fetchFn) {
api.fire('error', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getFileFromBlob } from '../../utils/getFileFromBlob';
import { getFileInfoFromHeaders } from '../../utils/getFileInfoFromHeaders';
import { getFilenameFromURL } from '../../utils/getFilenameFromURL';

export const fetchLocal = (url, load, error, progress, abort, headers) => {
export const fetchBlob = (url, load, error, progress, abort, headers) => {
const request = sendRequest(null, url, {
method: 'GET',
responseType: 'blob'
Expand Down

0 comments on commit ecbc3b1

Please sign in to comment.