mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Local API binary output support + qml image example
This commit is contained in:
parent
e59366d0fd
commit
db3dad3e23
@ -105,9 +105,17 @@ readPath:
|
|||||||
resource_api::Request req(reqJson);
|
resource_api::Request req(reqJson);
|
||||||
req.mMethod = reqMeth;
|
req.mMethod = reqMeth;
|
||||||
req.setPath(reqPath);
|
req.setPath(reqPath);
|
||||||
std::string resultString = mApiServer->handleRequest(req);
|
|
||||||
mLocalSocket->write(resultString.c_str(), resultString.length());
|
// Need this idiom because binary result may contains \0
|
||||||
|
std::string&& resultString = mApiServer->handleRequest(req);
|
||||||
|
QByteArray rB(resultString.data(), resultString.length());
|
||||||
|
|
||||||
|
// Dirty trick to support avatars answers
|
||||||
|
if(rB.contains("\n") || !rB.startsWith("{") || !rB.endsWith("}"))
|
||||||
|
mLocalSocket->write(rB.toBase64());
|
||||||
|
else mLocalSocket->write(rB);
|
||||||
mLocalSocket->write("\n\0");
|
mLocalSocket->write("\n\0");
|
||||||
|
|
||||||
mState = WAITING_PATH;
|
mState = WAITING_PATH;
|
||||||
|
|
||||||
/* Because QLocalSocket is SOCK_STREAM some clients implementations
|
/* Because QLocalSocket is SOCK_STREAM some clients implementations
|
||||||
|
43
retroshare-qml-app/src/ApiImageExample.qml
Normal file
43
retroshare-qml-app/src/ApiImageExample.qml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* RetroShare Android QML App
|
||||||
|
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick 2.7
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
color: "red"
|
||||||
|
|
||||||
|
Image
|
||||||
|
{
|
||||||
|
id: testImg
|
||||||
|
height: 300
|
||||||
|
width: 300
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted:
|
||||||
|
{
|
||||||
|
rsApi.request(
|
||||||
|
"/peers/d441e8890164a0f335ad75acc59b5a49/avatar_image",
|
||||||
|
"", setImgCallback )
|
||||||
|
}
|
||||||
|
function setImgCallback(par)
|
||||||
|
{
|
||||||
|
testImg.source = "data:image/png;base64," + par.response
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user