-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当zbp和gocq(实际上是openshamrock)不处于同一服务器时,无法发送本地图片 #840
Labels
documentation
Improvements or additions to documentation
Comments
其实也就签到是本地图片? |
那么可以试试这个方案 const WebSocket = require('ws');
const server = new WebSocket.WebSocketServer({ port: 8280 });
server.on('connection', function connection(ws) {
const client = new WebSocket('ws://bbbb:6700');
client.on('message', function message(data) {
let datax = new TextDecoder("utf-8").decode(new Uint8Array(data));
const regex = /{"type":"image","data":{"file":"file:\/\/\/([^"]+)"}}/;
const match = datax.match(regex);
if (match) {
ws.send(datax.replace("aaaa","http://bbbb:8080/image/"));
}
ws.send(datax);
});
ws.on('message', function message(data) {
let datax = new TextDecoder("utf-8").decode(new Uint8Array(data));
client.send(datax);
});
}); 通过将本地地址映射为能访问的图床地址(当然此处可以选择更复杂的方案),然后让openshamrock指向8280端口即可 调用Cheverto图床 const WebSocket = require('ws');
const FormData = require('form-data');
const fs = require('fs');
const http = require('http');
const server = new WebSocket.WebSocketServer({ port: 监听端口 });
server.on('connection', function connection(ws) {
const client = new WebSocket('真实的zbp地址');
client.on('message', function message(data) {
let datax = new TextDecoder("utf-8").decode(new Uint8Array(data));
const regex = /{"type":"image","data":{"file":"file:\/\/\/([^"]+)"}}/;
const match = datax.match(regex);
if (match) {
upimg(match[1],datax,ws);
} else {
ws.send(datax);
}
});
ws.on('message', function message(data) {
let datax = new TextDecoder("utf-8").decode(new Uint8Array(data));
client.send(datax);
});
});
function upimg(file,datax,ws) {
let form = new FormData();
form.append('source', fs.createReadStream(file)); //可以加个replace映射或者直接在docker上处理
let request = http.request({
method: 'post',
host: 'Cheverto图床地址',
port: 图床端口,
path: '/api/1/upload/?key=你的apikey&format=json',
headers: form.getHeaders()
}, function (res) {
let str = '';
res.on('data', function (buffer) {
str += buffer;
}
);
res.on('end', () => {
let result = JSON.parse(str);
ws.send(datax.replace("file:///"+file, result.image.url));
});
});
form.pipe(request);
} 懒得写异步,直接传了 |
我尝试一下 |
还有 |
我的方案是直接加个中转把所有本地图片都丢图床去了,虽然原则上修改插件会好一点 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个是abq的发送:向服务器发送请求: &{send_group_msg map[group_id:364328619 message:[CQ:image,file=file:////home/zbp/data/score/cache/103438060820240103signin.png]] 2}"
但是openshamrock会报错,找不到/home/zbp/data/score/cache这个地方图片,因为没在同一服务器上,请教如何解决
The text was updated successfully, but these errors were encountered: