某度的首页存在一个 bug,「自定义换肤」上传的图片会留在云端不删除,并且图片直链不会鉴定 cookie 和 referer。
可以直接使用百度来做图床存储图片 (安全性未知) 但是速度快啊:sunglasses:
思路
需要事先在浏览器登录百度账号
简单构建一个网页 模拟用户提交图片
<!DOCTYPE html><html><head>
<meta charset="utf-8">
<title>图片上传</title></head><body>
<form enctype="multipart/form-data" action="https://sp0.baidu.com/6_R1fD_bAAd3otqbppnN2DJv/Pic/upload?pid=super&app=skin&logid=2915142959" method="post">
<input type="file" name="file"><br/>
<input type="submit" value="上传">
</form></body></html>
需要携带 BDUSS 和 BAIDUID cookie。
返回的图片 URL 就在 JSON 中的 data.pic_water 值中
返回图片的地址不可以直接使用需要替换网址信息,将返回的json信息中的data.pic_water值提取出来进行更改
图片头部信息为:https://imgsrc.baidu.com/forum/pic/item/
改动之后
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>百度图床上传</title>
<style>
#outputBox {
width: 100%;
padding: 10px;
margin-top: 20px;
border: 1px solid #ccc;
background-color: #f0f0f0;
box-sizing: border-box;
cursor: text;
overflow: auto;
white-space: pre-wrap; /* 保持文本格式 */
}
</style>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data">
<input type="file" name="file" id="fileInput"><br/>
<input type="submit" value="上传">
</form>
<div id="result">
<p>处理后的文件名: (双击可复制)</p>
<div id="outputBox"></div>
<p>上传的图片:</p>
<img id="uploadedImage" src="" alt="" style="max-width: 100%; margin-top: 10px;">
</div>
<script>
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交
var formData = new FormData();
var fileInput = document.getElementById('fileInput');
formData.append('file', fileInput.files[0]);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://sp0.baidu.com/6_R1fD_bAAd3otqbppnN2DJv/Pic/upload?pid=super&app=skin&logid=2915142959', true);
// 携带 cookies
xhr.withCredentials = true;
xhr.onload = function () {
var data = JSON.parse(xhr.responseText);
// 提取 pic_water 字段的内容
var picWater = data.data.pic_water;
// 提取文件名
var fileName = picWater.split('/').pop();
// 添加特定内容
var prefix = "https://imgsrc.baidu.com/forum/pic/item/"; // 自定义的特定内容
var finalResult = prefix + fileName;
outputBox.innerText = finalResult;
// 显示图片
var uploadedImage = document.getElementById('uploadedImage');
uploadedImage.src =finalResult;
};
xhr.onerror = function () {
document.getElementById('result').innerHTML = `
<p>上传失败: ${xhr.statusText}</p>
`;
};
xhr.send(formData);
});
// 实现双击复制功能
document.getElementById('outputBox').addEventListener('dblclick', function() {
var range = document.createRange();
range.selectNodeContents(this);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
// 显示复制提示
var message = document.createElement('div');
message.innerText = '内容已复制到剪贴板';
message.style.position = 'fixed';
message.style.bottom = '10px';
message.style.right = '10px';
message.style.padding = '10px';
message.style.backgroundColor = '#dff0d8';
message.style.color = '#3c763d';
message.style.border = '1px solid #d6e9c6';
message.style.borderRadius = '5px';
document.body.appendChild(message);
setTimeout(function() {
document.body.removeChild(message);
}, 1000); // 2秒后隐藏消息
});
</script>
</body>
</html>
Typora 配合piclist使用
Typora配置 文件->偏好设置->图像->上传服务->自定义命令python pic.py
import sys
import requests
import json
def upload_image(image_path):
url = 'http://127.0.0.1:36677/upload'
# 打开并上传文件
with open(image_path, 'rb') as file:
files = {'file': (image_path, file, 'image/jpeg')}
response = requests.post(url, files=files)
responsetext = response.text
responsejson = json.loads(responsetext)
name = responsejson['result'][0]
name = str(name).split('/')[-1]
name = "https://imgsrc.baidu.com/forum/pic/item/"+str(name)
print(name)
if __name__ == "__main__":
image_paths = sys.argv[1:]
# 上传每个图片
for image_path in image_paths:
upload_image(image_path)
前提:piclist 配置自定义图床 设置
注:cookie易失效
参考链接白嫖某度CDN当博客图床
Comments NOTHING