-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
var permlink = (links) =>{
$('#permlink').remove();
if (typeof links !== 'string') {
// processing of zipped images
for(var i = 0; i < links.length; i++)
$('body').append("<div id='permlink'>"+
"<label>Permanent Link:-</label>"+
'<h3><a href="http://localhost:3000/file/'+links[i]+'">http://localhost:3000/file/'+links[i]+'</a></h3>'+
"</div>"
)
} else{
// processing of single image
$('body').append("<div id='permlink'>"+
"<label>Permanent Link:-</label>"+
'<h3><a href="http://localhost:3000/file/'+links+'">http://localhost:3000/file/'+links+'</a></h3>'+
"</div>")
}
}
var postreq = (url) =>{
var fd = new FormData($('form')[0]);
$.ajax({
method: 'post',
url: url,
data: fd,
cache: false,
contentType: false,
processData: false,
success: (data)=>{
permlink(data);
}
});
}
$('#form').on('submit', (e)=>{
// get file type
var filetype = $('input[name="file"]').val().split('.').pop();
e.preventDefault();
if (filetype === "zip"){
postreq('/file/zip');
} else if (filetype.match(/jpg|jpeg|png/)){
postreq('/file/image');
} else{
permlink("Error: please upload images in jpg or jpeg or png or zip format only");
}
$('input[name="file"]').val("");
});