|
|
|
@ -23,7 +23,7 @@ module.exports = (ctx) => {
|
|
|
|
|
const enablewatermark = userConfig.enablewatermark || false;
|
|
|
|
|
const compressionLevel = enableCompression ? userConfig.compressionLevel || 80 : undefined;
|
|
|
|
|
const namingstyle = userConfig.namingstyle || ''; // 命名方式
|
|
|
|
|
|
|
|
|
|
const enableUploadDate = userConfig.enableUploadDate || false; // 是否添加上传日期
|
|
|
|
|
try {
|
|
|
|
|
let imgList = ctx.output;
|
|
|
|
|
for (let i in imgList) {
|
|
|
|
@ -32,8 +32,19 @@ module.exports = (ctx) => {
|
|
|
|
|
image = Buffer.from(imgList[i].base64Image, 'base64');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const postConfig = postOptions(image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, compressionLevel, imgList[i].fileName);
|
|
|
|
|
const postConfig = postOptions(image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, enableUploadDate, compressionLevel, imgList[i].fileName);
|
|
|
|
|
// ctx.log.info('发送的JSON:', JSON.stringify(postConfig.formData));
|
|
|
|
|
|
|
|
|
|
// ctx.log.info('URL地址',url);
|
|
|
|
|
// ctx.log.info('上传路径',uploadPath);
|
|
|
|
|
// ctx.log.info('API令牌',apiToken);
|
|
|
|
|
// ctx.log.info('是否水印',enablewatermark);
|
|
|
|
|
// ctx.log.info('是否压缩',enableCompression);
|
|
|
|
|
// ctx.log.info('压缩等级',compressionLevel);
|
|
|
|
|
// ctx.log.info('命名规则',namingstyle);
|
|
|
|
|
// ctx.log.info('是否添加上传日期',enableUploadDate);
|
|
|
|
|
// ctx.log.info('文件名',imgList[i].fileName);
|
|
|
|
|
|
|
|
|
|
let body = await ctx.Request.request(postConfig);
|
|
|
|
|
// ctx.log.info('返回的JSON:', body);
|
|
|
|
|
|
|
|
|
@ -56,7 +67,7 @@ module.exports = (ctx) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const postOptions = (image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, compressionLevel, fileName) => {
|
|
|
|
|
const postOptions = (image, url, uploadPath, apiToken, namingstyle, enablewatermark, enableCompression, enableUploadDate, compressionLevel, fileName) => {
|
|
|
|
|
let headers = {
|
|
|
|
|
'Content-Type': 'multipart/form-data',
|
|
|
|
|
'User-Agent': 'PicGo'
|
|
|
|
@ -71,9 +82,25 @@ module.exports = (ctx) => {
|
|
|
|
|
},
|
|
|
|
|
api_token: apiToken,
|
|
|
|
|
upload_format: 'file',
|
|
|
|
|
uploadPath: uploadPath
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(enableUploadDate === true){
|
|
|
|
|
let Newdate = new Date();
|
|
|
|
|
let upLoaDYear = Newdate.getFullYear();
|
|
|
|
|
let upLoaDMonth = Newdate.getMonth() + 1; // 月份从0开始,所以要加1
|
|
|
|
|
let upLoaDDay = Newdate.getDate();
|
|
|
|
|
if(upLoaDMonth < 10){
|
|
|
|
|
upLoaDMonth = '0' + upLoaDMonth;
|
|
|
|
|
}
|
|
|
|
|
if(upLoaDDay < 10){
|
|
|
|
|
upLoaDDay = '0' + upLoaDDay;
|
|
|
|
|
}
|
|
|
|
|
// ctx.log.info('年月日',upLoaDYear,upLoaDMonth,upLoaDDay);
|
|
|
|
|
formData.uploadPath = uploadPath + '/' + upLoaDYear + '/' + upLoaDMonth + '/' + upLoaDDay;
|
|
|
|
|
}else{
|
|
|
|
|
formData.uploadPath = uploadPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(enablewatermark === true){
|
|
|
|
|
formData.watermark = '1';
|
|
|
|
|
}
|
|
|
|
@ -109,9 +136,9 @@ module.exports = (ctx) => {
|
|
|
|
|
{
|
|
|
|
|
name: 'uploadPath',
|
|
|
|
|
type: 'input',
|
|
|
|
|
default: userConfig.uploadPath,
|
|
|
|
|
default: userConfig.uploadPath || 'api/images',
|
|
|
|
|
required: true,
|
|
|
|
|
message: '上传路径',
|
|
|
|
|
message: '示例: api/images/Lucky-Star/posts',
|
|
|
|
|
alias: '上传路径'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -122,6 +149,13 @@ module.exports = (ctx) => {
|
|
|
|
|
message: 'API Token',
|
|
|
|
|
alias: 'API Token'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'enableUploadDate',
|
|
|
|
|
type: 'confirm',
|
|
|
|
|
default: userConfig.enableUploadDate || false,
|
|
|
|
|
message: '是否启用日期',
|
|
|
|
|
alias: '是否启用日期'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'namingstyle',
|
|
|
|
|
type: 'input',
|
|
|
|
|