@@ -4,10 +4,11 @@ var path = require('path');
4
4
var fs = require ( 'fs' ) ;
5
5
6
6
var formstream = require ( 'formstream' ) ;
7
+
7
8
var util = require ( './util' ) ;
8
9
var wrapper = util . wrapper ;
9
10
var postJSON = util . postJSON ;
10
-
11
+ var make = util . make ;
11
12
12
13
/**
13
14
* 上传永久素材,分别有图片(image)、语音(voice)、和缩略图(thumb)
@@ -35,14 +36,7 @@ var postJSON = util.postJSON;
35
36
* @param {String } type 媒体类型,可用值有image、voice、video、thumb
36
37
* @param {Function } callback 回调函数
37
38
*/
38
- exports . uploadMaterial = function ( filepath , type , callback ) {
39
- this . preRequest ( this . _uploadMaterial , arguments ) ;
40
- } ;
41
-
42
- /*!
43
- * 上传永久文件的未封装版本
44
- */
45
- exports . _uploadMaterial = function ( filepath , type , callback ) {
39
+ make ( exports , 'uploadMaterial' , function ( filepath , type , callback ) {
46
40
var that = this ;
47
41
fs . stat ( filepath , function ( err , stat ) {
48
42
if ( err ) {
@@ -60,7 +54,7 @@ exports._uploadMaterial = function (filepath, type, callback) {
60
54
} ;
61
55
that . request ( url , opts , wrapper ( callback ) ) ;
62
56
} ) ;
63
- } ;
57
+ } ) ;
64
58
65
59
[ 'image' , 'voice' , 'thumb' ] . forEach ( function ( type ) {
66
60
var method = 'upload' + type [ 0 ] . toUpperCase ( ) + type . substring ( 1 ) + 'Material' ;
@@ -94,14 +88,7 @@ exports._uploadMaterial = function (filepath, type, callback) {
94
88
* @param {Object } description 描述
95
89
* @param {Function } callback 回调函数
96
90
*/
97
- exports . uploadVideoMaterial = function ( filepath , description , callback ) {
98
- this . preRequest ( this . _uploadVideoMaterial , arguments ) ;
99
- } ;
100
-
101
- /*!
102
- * 上传永久文件(视频)的未封装版本
103
- */
104
- exports . _uploadVideoMaterial = function ( filepath , description , callback ) {
91
+ make ( exports , uploadVideoMaterial , function ( filepath , description , callback ) {
105
92
var that = this ;
106
93
fs . stat ( filepath , function ( err , stat ) {
107
94
if ( err ) {
@@ -120,7 +107,7 @@ exports._uploadVideoMaterial = function (filepath, description, callback) {
120
107
} ;
121
108
that . request ( url , opts , wrapper ( callback ) ) ;
122
109
} ) ;
123
- } ;
110
+ } ) ;
124
111
125
112
/**
126
113
* 新增永久图文素材
@@ -267,14 +254,12 @@ exports._getMaterial = function (mediaId, callback) {
267
254
err . name = 'WeChatAPIError' ;
268
255
}
269
256
} catch ( ex ) {
270
- callback ( ex , data , res ) ;
271
- return ;
257
+ return callback ( ex , data , res ) ;
272
258
}
273
- callback ( err , ret , res ) ;
274
- } else {
275
- // 输出Buffer对象
276
- callback ( null , data , res ) ;
259
+ return callback ( err , ret , res ) ;
277
260
}
261
+ // 输出Buffer对象
262
+ callback ( null , data , res ) ;
278
263
} ) ) ;
279
264
} ;
280
265
0 commit comments