update<新增日期功能>

main
赤月未咲 9 months ago
parent 414e8b7311
commit 1134857184

@ -1,6 +1,6 @@
{ {
"name": "picgo-plugin-bohe-uploader", "name": "picgo-plugin-bohe-uploader",
"version": "1.0.0", "version": "1.0.1",
"description": "PicGo plugin for Bohe uploader", "description": "PicGo plugin for Bohe uploader",
"main": "src/index.js", "main": "src/index.js",
"publishConfig": { "publishConfig": {

@ -23,7 +23,7 @@ module.exports = (ctx) => {
const enablewatermark = userConfig.enablewatermark || false; const enablewatermark = userConfig.enablewatermark || false;
const compressionLevel = enableCompression ? userConfig.compressionLevel || 80 : undefined; const compressionLevel = enableCompression ? userConfig.compressionLevel || 80 : undefined;
const namingstyle = userConfig.namingstyle || ''; // 命名方式 const namingstyle = userConfig.namingstyle || ''; // 命名方式
const enableUploadDate = userConfig.enableUploadDate || false; // 是否添加上传日期
try { try {
let imgList = ctx.output; let imgList = ctx.output;
for (let i in imgList) { for (let i in imgList) {
@ -32,8 +32,19 @@ module.exports = (ctx) => {
image = Buffer.from(imgList[i].base64Image, 'base64'); 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('发送的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); let body = await ctx.Request.request(postConfig);
// ctx.log.info('返回的JSON', body); // 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 = { let headers = {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
'User-Agent': 'PicGo' 'User-Agent': 'PicGo'
@ -71,9 +82,25 @@ module.exports = (ctx) => {
}, },
api_token: apiToken, api_token: apiToken,
upload_format: 'file', 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){ if(enablewatermark === true){
formData.watermark = '1'; formData.watermark = '1';
} }
@ -109,9 +136,9 @@ module.exports = (ctx) => {
{ {
name: 'uploadPath', name: 'uploadPath',
type: 'input', type: 'input',
default: userConfig.uploadPath, default: userConfig.uploadPath || 'api/images',
required: true, required: true,
message: '上传路径', message: '示例: api/images/Lucky-Star/posts',
alias: '上传路径' alias: '上传路径'
}, },
{ {
@ -122,6 +149,13 @@ module.exports = (ctx) => {
message: 'API Token', message: 'API Token',
alias: 'API Token' alias: 'API Token'
}, },
{
name: 'enableUploadDate',
type: 'confirm',
default: userConfig.enableUploadDate || false,
message: '是否启用日期',
alias: '是否启用日期'
},
{ {
name: 'namingstyle', name: 'namingstyle',
type: 'input', type: 'input',

Loading…
Cancel
Save