Skip to content

Commit 44c55f2

Browse files
committed
fix errors with dependences of examples
1 parent df35fd8 commit 44c55f2

File tree

9 files changed

+222
-17
lines changed

9 files changed

+222
-17
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ npm-debug.log
2222
node_modules
2323

2424
### example ###
25-
public/lib/
25+
public/lib/
26+
27+
examples/public/uploads/
28+
examples/tmp/
29+
examples/public/lib/
30+
31+
package-lock.json
32+
examples/package-lock.json

examples/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name":"examples",
3-
"version":"0.0.1",
4-
"dependencies":{
5-
"express":"3.3.x",
6-
"swig":"1.0.x"
2+
"name": "examples",
3+
"version": "0.0.1",
4+
"dependencies": {
5+
"express": "3.3.x",
6+
"swig": "1.0.x"
77
}
8-
}
8+
}

examples/public/cors/postmessage.html

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!DOCTYPE html>
2+
<!--
3+
/*
4+
* jQuery File Upload Plugin postMessage API
5+
* https://github.com/blueimp/jQuery-File-Upload
6+
*
7+
* Copyright 2011, Sebastian Tschan
8+
* https://blueimp.net
9+
*
10+
* Licensed under the MIT license:
11+
* https://opensource.org/licenses/MIT
12+
*/
13+
-->
14+
<html lang="en">
15+
<head>
16+
<meta charset="utf-8" />
17+
<title>jQuery File Upload Plugin postMessage API</title>
18+
<script
19+
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
20+
integrity="sha384-xBuQ/xzmlsLoJpyjoggmTEz8OWUFM0/RC5BsqQBDX2v5cMvDHcMakNTNrHIW2I5f"
21+
crossorigin="anonymous"
22+
></script>
23+
</head>
24+
<body>
25+
<script>
26+
'use strict';
27+
var origin = /^https:\/\/example.org/,
28+
target = new RegExp('^(http(s)?:)?\\/\\/' + location.host + '\\/');
29+
$(window).on('message', function (e) {
30+
e = e.originalEvent;
31+
var s = e.data,
32+
xhr = $.ajaxSettings.xhr(),
33+
f;
34+
if (!origin.test(e.origin)) {
35+
throw new Error('Origin "' + e.origin + '" does not match ' + origin);
36+
}
37+
if (!target.test(e.data.url)) {
38+
throw new Error(
39+
'Target "' + e.data.url + '" does not match ' + target
40+
);
41+
}
42+
$(xhr.upload).on('progress', function (ev) {
43+
ev = ev.originalEvent;
44+
e.source.postMessage(
45+
{
46+
id: s.id,
47+
type: ev.type,
48+
timeStamp: ev.timeStamp,
49+
lengthComputable: ev.lengthComputable,
50+
loaded: ev.loaded,
51+
total: ev.total
52+
},
53+
e.origin
54+
);
55+
});
56+
s.xhr = function () {
57+
return xhr;
58+
};
59+
if (!(s.data instanceof Blob)) {
60+
f = new FormData();
61+
$.each(s.data, function (i, v) {
62+
f.append(v.name, v.value);
63+
});
64+
s.data = f;
65+
}
66+
$.ajax(s).always(function (result, statusText, jqXHR) {
67+
if (!jqXHR.done) {
68+
jqXHR = result;
69+
result = null;
70+
}
71+
e.source.postMessage(
72+
{
73+
id: s.id,
74+
status: jqXHR.status,
75+
statusText: statusText,
76+
result: result,
77+
headers: jqXHR.getAllResponseHeaders()
78+
},
79+
e.origin
80+
);
81+
});
82+
});
83+
</script>
84+
</body>
85+
</html>

examples/public/cors/result.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<!--
3+
/*
4+
* jQuery Iframe Transport Plugin Redirect Page
5+
* https://github.com/blueimp/jQuery-File-Upload
6+
*
7+
* Copyright 2010, Sebastian Tschan
8+
* https://blueimp.net
9+
*
10+
* Licensed under the MIT license:
11+
* https://opensource.org/licenses/MIT
12+
*/
13+
-->
14+
<html lang="en">
15+
<head>
16+
<meta charset="utf-8" />
17+
<title>jQuery Iframe Transport Plugin Redirect Page</title>
18+
</head>
19+
<body>
20+
<script>
21+
document.body.innerText = document.body.textContent = decodeURIComponent(
22+
window.location.search.slice(1)
23+
);
24+
</script>
25+
</body>
26+
</html>

examples/public/scripts/file_upload.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
$('#location_gallery').fileupload({
2+
// forceIframeTransport: true,
3+
redirect: location.protocol + '//' + location.host + '/cors/result.html?%s',
24
dataType:'json',
3-
url:'/upload/location',
5+
url:'http://172.17.0.138:3001/upload/location',
46
autoUpload: true,
57
sequentialUploads:true,
68
acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i,
@@ -86,7 +88,7 @@ $('#location_gallery').fileupload({
8688

8789
$('#location_cover').fileupload({
8890
dataType:'json',
89-
url:'/upload/location',
91+
url:'http://172.17.0.138:3001/upload/location',
9092
autoUpload: true,
9193
acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i,
9294
process:[
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* JavaScript Load Image Fetch
3+
* https://github.com/blueimp/JavaScript-Load-Image
4+
*
5+
* Copyright 2017, Sebastian Tschan
6+
* https://blueimp.net
7+
*
8+
* Licensed under the MIT license:
9+
* https://opensource.org/licenses/MIT
10+
*/
11+
12+
/* global define, module, require */
13+
14+
;(function (factory) {
15+
'use strict'
16+
if (typeof define === 'function' && define.amd) {
17+
// Register as an anonymous AMD module:
18+
define(['./load-image', './load-image-meta'], factory)
19+
} else if (typeof module === 'object' && module.exports) {
20+
factory(require('./load-image'), require('./load-image-meta'))
21+
} else {
22+
// Browser globals:
23+
factory(window.loadImage)
24+
}
25+
})(function (loadImage) {
26+
'use strict'
27+
28+
if (typeof fetch !== 'undefined' && typeof Request !== 'undefined') {
29+
loadImage.fetchBlob = function (url, callback, options) {
30+
if (loadImage.hasMetaOption(options)) {
31+
fetch(new Request(url, options))
32+
.then(function (response) {
33+
return response.blob()
34+
})
35+
.then(callback)['catch'](function (err) {
36+
console.log(err) // eslint-disable-line no-console
37+
callback()
38+
})
39+
} else {
40+
callback()
41+
}
42+
}
43+
} else if (
44+
// Check for XHR2 support:
45+
typeof XMLHttpRequest !== 'undefined' &&
46+
typeof ProgressEvent !== 'undefined'
47+
) {
48+
loadImage.fetchBlob = function (url, callback, options) {
49+
if (loadImage.hasMetaOption(options)) {
50+
// eslint-disable-next-line no-param-reassign
51+
options = options || {}
52+
var req = new XMLHttpRequest()
53+
req.open(options.method || 'GET', url)
54+
if (options.headers) {
55+
Object.keys(options.headers).forEach(function (key) {
56+
req.setRequestHeader(key, options.headers[key])
57+
})
58+
}
59+
req.withCredentials = options.credentials === 'include'
60+
req.responseType = 'blob'
61+
req.onload = function () {
62+
callback(req.response)
63+
}
64+
req.onerror = req.onabort = req.ontimeout = function (e) {
65+
console.log(e) // eslint-disable-line no-console
66+
callback()
67+
}
68+
req.send(options.body)
69+
} else {
70+
callback()
71+
}
72+
}
73+
}
74+
})

examples/views/form.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,28 @@
6666
</div>
6767

6868
</div>
69-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
69+
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.js"></script>
70+
<script src="https://cdn.jsdelivr.net/npm/fetch-polyfill@0.8.2/fetch.js"></script>
71+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
7072
<script src="//blueimp.github.io/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
71-
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image.min.js"></script>
72-
<script src="//blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.min.js"></script>
73+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image.js"></script>
74+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-scale.js"></script>
75+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-meta.js"></script>
76+
<script src="/scripts/load-image-fetch.js"></script>
77+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-orientation.js"></script>
78+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-exif.js"></script>
79+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-exif-map.js"></script>
80+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-iptc.js"></script>
81+
<script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image-iptc-map.js"></script>
82+
<script src="//blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.js"></script>
7383
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
7484
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload.js"></script>
7585
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-process.js"></script>
7686
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-image.js"></script>
7787
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-audio.js"></script>
7888
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-video.js"></script>
7989
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-validate.js"></script>
90+
<script src="//blueimp.github.io/jQuery-File-Upload/js/cors/jquery.xdr-transport.js"></script>
8091
<script src="//blueimp.github.io/jQuery-File-Upload/js/jquery.fileupload-ui.js"></script>
8192
<script type="text/javascript" src="/scripts/file_upload.js"></script>
8293
</body>

lib/filehandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module.exports = function (middleware, options) {
88
var UploadHandler = require('./uploadhandler')(options);
99
var handler = new UploadHandler(req, res, function (result, redirect) {
1010
if (redirect) {
11-
files = {files: result};
12-
res.redirect(redirect.replace(/%s/, encodeURIComponent(JSON.stringify(files))));
11+
// files = {files: result};
12+
res.redirect(redirect.replace(/%s/, encodeURIComponent(JSON.stringify(result))));
1313
} else {
1414
res.set({
1515
'Content-Type': (req.headers.accept || '').indexOf('application/json') !== -1

lib/uploadhandler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports = function (options) {
122122
_.each(options.imageVersions, function (value, version) {
123123
counter++;
124124
// creating directory recursive
125-
mkdirp(options.uploadDir() + '/' + version + '/', function (err, made) {
125+
mkdirp(options.uploadDir() + '/' + version + '/').then(function (err, made) {
126126
var opts = options.imageVersions[version];
127127
imageMagick.resize({
128128
width: opts.width,
@@ -136,7 +136,7 @@ module.exports = function (options) {
136136
}
137137
}
138138

139-
mkdirp(options.uploadDir() + '/', function(err, made) {
139+
mkdirp(options.uploadDir() + '/').then(function(err, made) {
140140
fs.rename(file.path, options.uploadDir() + '/' + fileInfo.name, function (err) {
141141
if (!err) {
142142
generatePreviews();
@@ -189,7 +189,7 @@ module.exports = function (options) {
189189
}
190190
fs.unlink(filepath, function (ex) {
191191
_.each(options.imageVersions, function (value, version) {
192-
fs.unlink(path.join(options.uploadDir(), version, fileName));
192+
fs.unlinkSync(path.join(options.uploadDir(), version, fileName));
193193
});
194194
self.emit('delete', fileName);
195195
self.callback({success: !ex});

0 commit comments

Comments
 (0)