From b2e863947939dd0ac35b4ca8c732deecfa61b1f4 Mon Sep 17 00:00:00 2001 From: Qihua Pan Date: Thu, 26 May 2022 23:15:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B8=85=E7=90=86oss?= =?UTF-8?q?=E8=80=81=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pixiv/config.json.example | 3 ++- pixiv/pixiv.sh | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pixiv/config.json.example b/pixiv/config.json.example index 3211b9a..bbf51f7 100644 --- a/pixiv/config.json.example +++ b/pixiv/config.json.example @@ -17,7 +17,8 @@ "AccessKeyId":"OpenAPI AccessKey ID", "AccessKeySecret":"OpenAPI AccessKey Secret", "db":"文件上传成功记录数据库", - "imageParam":"阿里云图片处理参数 比如:?x-oss-process=image/format,webp/resize,w_2560,h_2560" + "imageParam":"阿里云图片处理参数 比如:?x-oss-process=image/format,webp/resize,w_2560,h_2560", + "deleteApi":"删除老图片的接口地址" }, "convertio":{ "apikey":"https://developers.convertio.co/zh/ 申请的API密钥", diff --git a/pixiv/pixiv.sh b/pixiv/pixiv.sh index 55be675..20cf6d0 100644 --- a/pixiv/pixiv.sh +++ b/pixiv/pixiv.sh @@ -29,6 +29,7 @@ AccessKeySecret=`cat $config_file | jq -r .aliyun_oss.AccessKeySecret` db_file=`cat $config_file | jq -r .aliyun_oss.db` db_file_err=$db_file.err imageParam=`cat $config_file | jq -r .aliyun_oss.imageParam` +deleteApi=`cat $config_file | jq -r .aliyun_oss.deleteApi` convertio_apikey=`cat $config_file | jq -r .convertio.apikey` @@ -41,12 +42,10 @@ then touch $db_file fi -function upload(){ +function PutObject(){ VERB="PUT" file=$1 Content_MD5="" - Content_Type="application/x-www-form-urlencoded" - Content_Type="text/plain" Content_Type=`file -b --mime-type $file` Date=`TZ=GMT env LANG=en_US.UTF-8 date +'%a, %d %b %Y %H:%M:%S GMT'` CanonicalizedOSSHeaders="x-oss-object-acl:public-read\n" @@ -54,7 +53,7 @@ function upload(){ stringToSign="$VERB\n$Content_MD5\n$Content_Type\n$Date\n$CanonicalizedOSSHeaders$CanonicalizedResource" Signature=`echo -en $stringToSign | openssl sha1 -hmac $AccessKeySecret -binary | base64` Authorization="OSS $AccessKeyId:$Signature" - http_code=`curl -v -w "%{http_code}" -X PUT -H "HOST:$bucketname.$Host" -H "x-oss-object-acl:public-read" -H "Date:$Date" -H "Content-Type:$Content_Type" -H "Authorization:$Authorization" --data-binary "@$file" "https://$bucketname.$Host/$file"` + http_code=`curl -v -w "%{http_code}" -X $VERB -H "HOST:$bucketname.$Host" -H "x-oss-object-acl:public-read" -H "Date:$Date" -H "Content-Type:$Content_Type" -H "Authorization:$Authorization" --data-binary "@$file" "https://$bucketname.$Host/$file"` if [ $http_code -eq "200" ] then echo $file>>$db_file @@ -64,6 +63,30 @@ function upload(){ fi } +function DeleteMultipleObjects(){ + temp_file=DeleteMultipleObjects.json + while true + do + curl -v -d "AccessKeyId=$AccessKeyId&AccessKeySecret=$AccessKeySecret&host=$Host&bucketname=$bucketname&max=50" $deleteApi > $temp_file + cat $temp_file + count=`cat $temp_file|jq -r .count` + echo "剩余需要清理文件个数:$count" + if [ $count == 0 ] + then + echo "delete finish" + break + fi + for item in `cat $temp_file|jq -r ".delete_files[]"` + do + sed -i "/$item/g" $db_file + done + sed -i "/^\s*$/d" $db_file + sleep 1m + done + rm -f $temp_file +} + + function fileSizeStr(){ fileSize=$1 if [[ $fileSize -gt 1048576 ]] @@ -224,7 +247,7 @@ do if [[ `echo $result|jq -r .status` = ok && `echo $result|jq -r .data.step` = finish ]] then echo $result|jq .data.output.url|xargs curl -v -o $original_file_name - upload $original_file_name + PutObject $original_file_name break elif [ `echo $result|jq -r .status` = error ] then @@ -240,7 +263,7 @@ do echo "Start a New Conversion error!!!" fi else - upload $original_file_name + PutObject $original_file_name fi fi @@ -296,4 +319,5 @@ curl -v -d chat_id=$chat_id -d text="以上就是$today日榜前${length}名作 find -type f -mtime +7|grep html find -type f -mtime +7|grep json -find -type f -mtime +7|grep webp \ No newline at end of file +find -type f -mtime +7|grep webp +DeleteMultipleObjects \ No newline at end of file