图片同步

未解决: 从本地获取
This commit is contained in:
life
2015-01-23 20:43:21 +08:00
parent f6cc411735
commit 245bbb0236
13 changed files with 306 additions and 71 deletions

35
node_modules/api.js generated vendored
View File

@@ -11,6 +11,7 @@ function log(o) {
// 远程数据服务
var Api = {
leanoteUrl: 'http://localhost:9000',
baseUrl: 'http://localhost:9000/api',
getUrl: function(url, param) {
var url = this.baseUrl + '/' + url;
@@ -131,7 +132,10 @@ var Api = {
// 将https://leanote.com/api/resource/getImage?imageId=xx
// 转成app://leanote/public/files, 内部可以是个服务器吗? 请求内部的controller
getImage: function(fileId, callback) {
needle.get('http://localhost:9000/images/logo.png', function(err, resp) {
var me = this;
var url = me.getUrl('file/getImage', {fileId: fileId});
log(url);
needle.get(url, function(err, resp) {
// log(resp.body);
/*
{ 'accept-ranges': 'bytes',
@@ -141,7 +145,34 @@ var Api = {
date: 'Mon, 19 Jan 2015 15:01:47 GMT',
*/
// log(resp.headers);
fs.writeFile('/Users/life/Desktop/aa.png', resp.body);
if(err) {
callback(false);
} else {
var typeStr = resp.headers['content-type'];
log(resp.headers);
log(typeStr);
var type = 'png';
if(typeStr) {
var typeArr = typeStr.split('/');
if(typeStr.length > 1) {
type = typeArr[1];
}
}
var filename = Common.uuid() + '.' + type;
var imagePath = User.getCurUserImagesPath();
var imagePathAll = imagePath + '/' + filename;
log(imagePathAll);
fs.writeFile(imagePathAll, resp.body, function(err) {
if(err) {
log(err);
log('local save image failed 本地保存失败');
callback(false);
} else {
callback(imagePathAll, filename);
}
});
}
});
},
};