mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-14 23:22:40 +00:00
switch account
This commit is contained in:
20
node_modules/common.js
generated
vendored
20
node_modules/common.js
generated
vendored
@@ -60,6 +60,26 @@ var Common = {
|
||||
callback && callback(false);
|
||||
});
|
||||
},
|
||||
inArray: function(arr, item) {
|
||||
var me = this;
|
||||
if(!arr) {
|
||||
return false;
|
||||
}
|
||||
for(var i = 0; i < arr.length; i++) {
|
||||
if(arr[i] == item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isImageExt: function(ext) {
|
||||
var me = this;
|
||||
if(!ext) {
|
||||
return false;
|
||||
}
|
||||
ext = ext.toLowerCase();
|
||||
return me.inArray(['jpg', 'jpeg', 'bmp', 'png', 'gif'], ext);
|
||||
},
|
||||
// 拆分filePath的各个部分
|
||||
splitFile: function(fullFilePath) {
|
||||
var ret = {
|
||||
|
25
node_modules/file.js
generated
vendored
25
node_modules/file.js
generated
vendored
@@ -180,6 +180,31 @@ var File = {
|
||||
}
|
||||
},
|
||||
|
||||
// tinymce 或 mceeditor上传图片
|
||||
// callback({FileId: "xx"})
|
||||
uploadImage: function(imagePath, callback) {
|
||||
var me = this;
|
||||
// 读取文件, 查看是否是图片
|
||||
var filePathAttr = Common.splitFile(imagePath);
|
||||
var ext = filePathAttr.ext;
|
||||
if(!Common.isImageExt(ext)) {
|
||||
return callback(false, 'Please select a image');
|
||||
}
|
||||
var fileId = Common.objectId();
|
||||
// 复制到图片文件夹
|
||||
filePathAttr.nameNotExt = fileId + '_cp_';
|
||||
var newFilename = fileId + '.' + ext;
|
||||
var newFilePath = User.getCurUserImagesPath() + '/' + newFilename;
|
||||
// 复制之, 并写入到数据库中
|
||||
Common.copyFile(imagePath, newFilePath, function(ret) {
|
||||
if(ret) {
|
||||
me._addImage(fileId, newFilePath, callback);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 附件操作
|
||||
addAttach: function(filePaths, noteId, callback) {
|
||||
if(!noteId || !filePaths) {
|
||||
|
Reference in New Issue
Block a user