File tree Expand file tree Collapse file tree 3 files changed +16
-16
lines changed
Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -7,8 +7,6 @@ const fs = require('fs');
77const awaitWriteStream = require ( 'await-stream-ready' ) . write ;
88const sendToWormhole = require ( 'stream-wormhole' ) ;
99
10- const qnUpload = require ( '../common/upload' ) ;
11-
1210class TopicController extends Controller {
1311 /**
1412 * Topic page
@@ -427,7 +425,7 @@ class TopicController extends Controller {
427425 // 如果有七牛云的配置,优先上传七牛云
428426 if ( config . qn_access ) {
429427 try {
430- const upload = qnUpload ( config . qn_access ) ;
428+ const upload = this . ctx . helper . qnUpload ( config . qn_access ) ;
431429 const result = await upload ( stream ) ;
432430 ctx . body = {
433431 success : true ,
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ const validator = require('validator');
55const jsxss = require ( 'xss' ) ;
66const moment = require ( 'moment' ) ;
77const bcrypt = require ( 'bcryptjs' ) ;
8+ const util = require ( 'util' ) ;
9+ const qn = require ( 'qn' ) ;
810
911moment . locale ( 'zh-cn' ) ; // 使用中文
1012
@@ -112,3 +114,16 @@ exports.bhash = str => {
112114exports . bcompare = ( str , hash ) => {
113115 return bcrypt . compareSync ( str , hash ) ;
114116} ;
117+
118+ let qnClientUpload ;
119+
120+ exports . qnUpload = options => {
121+ // 7牛 client
122+ if ( qnClientUpload ) return qnClientUpload ;
123+ let qnClient ;
124+ if ( options . qn_access && options . qn_access . secretKey !== 'your secret key' ) {
125+ qnClient = qn . create ( options . qn_access ) ;
126+ }
127+ qnClientUpload = util . promisify ( qnClient . upload ) ;
128+ return qnClientUpload ;
129+ } ;
You can’t perform that action at this time.
0 commit comments