diff --git a/bohe-uploader/src/index.js b/bohe-uploader/src/index.js index 3b5ea7a..1825f27 100644 --- a/bohe-uploader/src/index.js +++ b/bohe-uploader/src/index.js @@ -20,7 +20,9 @@ module.exports = (ctx) => { const uploadPath = userConfig.uploadPath || ''; const apiToken = userConfig.apiToken || ''; const enableCompression = userConfig.enableCompression || false; + const enablewatermark = userConfig.enablewatermark || false; const compressionLevel = enableCompression ? userConfig.compressionLevel || 80 : undefined; + const namingstyle = userConfig.namingstyle || ''; // 命名方式 try { let imgList = ctx.output; @@ -30,10 +32,10 @@ module.exports = (ctx) => { image = Buffer.from(imgList[i].base64Image, 'base64'); } - const postConfig = postOptions(image, url, uploadPath, apiToken, enableCompression, compressionLevel, imgList[i].fileName); + const postConfig = postOptions(image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, compressionLevel, imgList[i].fileName); // ctx.log.info('发送的JSON:', JSON.stringify(postConfig.formData)); let body = await ctx.Request.request(postConfig); - ctx.log.info('返回的JSON:', body); + // ctx.log.info('返回的JSON:', body); delete imgList[i].base64Image; delete imgList[i].buffer; @@ -54,7 +56,7 @@ module.exports = (ctx) => { }; - const postOptions = (image, url, uploadPath, apiToken, enableCompression, compressionLevel, fileName) => { + const postOptions = (image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, compressionLevel, fileName) => { let headers = { 'Content-Type': 'multipart/form-data', 'User-Agent': 'PicGo' @@ -72,9 +74,16 @@ module.exports = (ctx) => { uploadPath: uploadPath }; + if(enablewatermark === true){ + formData.watermark = '1'; + } + + if(namingstyle !== ''){ + formData.mode = namingstyle; + } + if (enableCompression === true) { formData.image_compress = '1'; - formData.mode = enableCompression ? '1' : '0'; formData.image_compress_level = compressionLevel.toString(); } @@ -113,6 +122,21 @@ module.exports = (ctx) => { message: 'API Token', alias: 'API Token' }, + { + name: 'namingstyle', + type: 'input', + default: userConfig.namingstyle, + required: false, + message: '命名方式', + alias: '命名方式' + }, + { + name: 'enablewatermark', + type: 'confirm', + default: userConfig.enablewatermark || false, + message: '是否启用水印', + alias: '是否启用水印' + }, { name: 'enableCompression', type: 'confirm',