Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fixNoteContentForSend: function(content) {
if(!content) {
return content;
}
// console.log(Evt.localUrl + '/api/file/getImage');
// console.log(content);
var reg = new RegExp(Evt.getImageLocalUrlPrefix(), 'g');
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getImage');
var reg2 = new RegExp(Evt.getAttachLocalUrlPrefix(), 'g');
content = content.replace(reg2, Evt.leanoteUrl + '/api/file/getAttach');
var reg3 = new RegExp(Evt.getAllAttachsLocalUrlPrefix(), 'g');
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttachs');
return content;
},
// 1. 先得到附件
var attachs = note.Attachs || [];
for(var i in attachs) {
var attach = attachs[i];
attach.IsAttach = true;
}
// 1. 先得到图片
// 得到图片信息, 通过内容
// http://localhost:8002/api/file/getImage?fileId=xxxxxx, 得到fileId, 查询数据库, 得到图片
// console.log(content);
// console.log(Evt.localUrl + '/api/file/getImage?fileId=([0-9a-zA-Z]{24})');
// var reg = new RegExp(Evt.localUrl + "/api/file/getImage\\?fileId=([0-9a-zA-Z]{24})", 'g');
var reg = new RegExp(Evt.getImageLocalUrlPrefix() + "\\?fileId=([0-9a-zA-Z]{24})", 'g');
var fileIds = [];
// var fileIdsMap = {}; // 防止多个
while((result = reg.exec(content)) != null) {
// result = [所有, 子表达式1, 子表达式2]
if(result && result.length > 1) {
// console.log(result);
var fileId = result[1];
fileIds.push(fileId);
}
}
var files = []; // {localFileId: "must", fileId: "", hasBody: true, filename: "xx.png"}
if(fileIds.length > 0) {
// 得到所有的图片
File.getAllImages(fileIds, function(images) {
// attach与图片结合
if(images) {
fixNoteContent: function(content) {
if(!content) {
return content;
}
// https, http都行
var url = Evt.leanoteUrl.replace('https', 'https*');
// http://leanote.com/file/outputImage?fileId=54f9079f38f4115c0200001b
var reg0 = new RegExp(url + '/file/outputImage', 'g');
content = content.replace(reg0, Evt.getImageLocalUrlPrefix());
var reg = new RegExp(url + '/api/file/getImage', 'g');
content = content.replace(reg, Evt.getImageLocalUrlPrefix());
var reg2 = new RegExp(url + '/api/file/getAttach', 'g');
content = content.replace(reg2, Evt.getAttachLocalUrlPrefix());
var reg3 = new RegExp(url + '/attach/download?attachId', 'g');
content = content.replace(reg3, Evt.getAttachLocalUrlPrefix() + '?fileId');
// 无用
// api/file/getAllAttachs?noteId=xxxxxxxxx, 这里的noteId是服务器上的noteId啊
var reg4 = new RegExp(url + '/api/file/getAllAttachs', 'g');
content = content.replace(reg4, Evt.getAllAttachsLocalUrlPrefix());
return content;