|
|
@@ -99,8 +99,30 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ attachmentSchema.statics.guessExtByFileType = function (fileType) {
|
|
|
+ let ext = '';
|
|
|
+ const isImage = fileType.match(/^image\/(.+)/i);
|
|
|
+
|
|
|
+ if (isImage) {
|
|
|
+ ext = isImage[1].toLowerCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ return ext;
|
|
|
+ };
|
|
|
+
|
|
|
attachmentSchema.statics.createAttachmentFilePath = function (pageId, fileName, fileType) {
|
|
|
- var ext = '.' + fileName.match(/(.*)(?:\.([^.]+$))/)[2] || '';
|
|
|
+ const Attachment = this;
|
|
|
+ let ext = '';
|
|
|
+ const fnExt = fileName.match(/(.*)(?:\.([^.]+$))/);
|
|
|
+
|
|
|
+ if (fnExt) {
|
|
|
+ ext = '.' + fnExt[2];
|
|
|
+ } else {
|
|
|
+ ext = Attachment.guessExtByFileType(fileType);
|
|
|
+ if (ext !== '') {
|
|
|
+ ext = '.' + ext;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return 'attachment/' + pageId + '/' + generateFileHash(fileName) + ext;
|
|
|
};
|