fixFile function file type upload if file type file type type if file

 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
fixFile: function (file, type, upload) {
if (!file.type)
file.type = type;
if (!file.nid) {
if (file.id) {
file.nid = file.id;
} else
return false;
}
if ((!file.filename || !file.fileext) && file.name) {
var m = file.name.match(/^(.*?)\.([^\.]+)$/i);
if (type == Spaces.TYPES.MUSIC && (!m || !m[2] || !/^mp3|aac$/i.test(m[2]))) {
file.filename = file.name;
file.fileext = "mp3";
} else {
if (m) {
file.filename = m[1];
file.fileext = m[2];
} else
return false;
}
}
if (upload && file.preview && file.thumbLink)
file.preview.previewURL = file.thumbLink;
if (!file.name)
file.name = file.filename + "." + file.fileext;
return file;
},