Compare commits
No commits in common. "6a925bdad39d497b27e93bb9afec3c4d0d6714d6" and "3b2982a95e1b8ea03b89161cdd9f6913c3af3d53" have entirely different histories.
6a925bdad3
...
3b2982a95e
|
@ -2,8 +2,8 @@ import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Dialogs
|
||||||
import FluentUI
|
import FluentUI
|
||||||
import Qt.labs.platform
|
|
||||||
import "qrc:///example/qml/component"
|
import "qrc:///example/qml/component"
|
||||||
|
|
||||||
FluContentPage{
|
FluContentPage{
|
||||||
|
@ -348,32 +348,6 @@ FluContentPage{
|
||||||
file_dialog.open()
|
file_dialog.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
|
||||||
id:btn_download
|
|
||||||
implicitWidth: parent.width
|
|
||||||
implicitHeight: 36
|
|
||||||
text: "Download File"
|
|
||||||
onClicked: {
|
|
||||||
folder_dialog.showDialog(function(path){
|
|
||||||
FluNetwork.get("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
|
||||||
.toDownload(path)
|
|
||||||
.go(callable_download_file)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FluProgressButton{
|
|
||||||
id:btn_download_breakpoint
|
|
||||||
implicitWidth: parent.width
|
|
||||||
implicitHeight: 36
|
|
||||||
text: "Breakpoint Download File"
|
|
||||||
onClicked: {
|
|
||||||
folder_dialog.showDialog(function(path){
|
|
||||||
FluNetwork.get("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
|
||||||
.toDownload(path,true)
|
|
||||||
.go(callable_breakpoint_download_file)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,56 +375,6 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FluNetworkCallable{
|
|
||||||
id:callable_download_file
|
|
||||||
onStart: {
|
|
||||||
btn_download.progress = 0
|
|
||||||
btn_download.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_download.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_download.progress = 0
|
|
||||||
showError(errorString)
|
|
||||||
console.debug(status+";"+errorString+";"+result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
showSuccess(result)
|
|
||||||
}
|
|
||||||
onDownloadProgress:
|
|
||||||
(recv,total)=>{
|
|
||||||
btn_download.progress = recv/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FluNetworkCallable{
|
|
||||||
id:callable_breakpoint_download_file
|
|
||||||
onStart: {
|
|
||||||
btn_download_breakpoint.progress = 0
|
|
||||||
btn_download_breakpoint.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_download_breakpoint.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_download_breakpoint.progress = 0
|
|
||||||
showError(errorString)
|
|
||||||
console.debug(status+";"+errorString+";"+result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
showSuccess(result)
|
|
||||||
}
|
|
||||||
onDownloadProgress:
|
|
||||||
(recv,total)=>{
|
|
||||||
btn_download_breakpoint.progress = recv/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: file_dialog
|
id: file_dialog
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
|
@ -462,20 +386,6 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
property var onSelectListener
|
|
||||||
id: folder_dialog
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]+"/big_buck_bunny.mp4"
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
onAccepted: {
|
|
||||||
folder_dialog.onSelectListener(FluTools.toLocalPath(folder_dialog.currentFile))
|
|
||||||
}
|
|
||||||
function showDialog(listener){
|
|
||||||
folder_dialog.onSelectListener = listener
|
|
||||||
folder_dialog.open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FluArea{
|
FluArea{
|
||||||
anchors{
|
anchors{
|
||||||
top: layout_flick.top
|
top: layout_flick.top
|
||||||
|
|
|
@ -41,9 +41,6 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
FluNetwork.setInterceptor(function(param){
|
|
||||||
param.addHeader("Token","000000000000000000000")
|
|
||||||
})
|
|
||||||
FluApp.init(app)
|
FluApp.init(app)
|
||||||
FluApp.useSystemAppBar = SettingsHelper.getUseSystemAppBar()
|
FluApp.useSystemAppBar = SettingsHelper.getUseSystemAppBar()
|
||||||
FluApp.vsync = SettingsHelper.getVsync()
|
FluApp.vsync = SettingsHelper.getVsync()
|
||||||
|
|
|
@ -3,7 +3,6 @@ import QtQuick.Layouts 1.15
|
||||||
import QtQuick.Window 2.15
|
import QtQuick.Window 2.15
|
||||||
import QtQuick.Controls 2.15
|
import QtQuick.Controls 2.15
|
||||||
import FluentUI 1.0
|
import FluentUI 1.0
|
||||||
import Qt.labs.platform 1.0
|
|
||||||
import "qrc:///example/qml/component"
|
import "qrc:///example/qml/component"
|
||||||
import "../component"
|
import "../component"
|
||||||
|
|
||||||
|
@ -340,95 +339,6 @@ FluContentPage{
|
||||||
.go(callable)
|
.go(callable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
|
||||||
id:btn_upload
|
|
||||||
implicitWidth: parent.width
|
|
||||||
implicitHeight: 36
|
|
||||||
text: "Upload File"
|
|
||||||
onClicked: {
|
|
||||||
file_dialog.open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FluProgressButton{
|
|
||||||
id:btn_download
|
|
||||||
implicitWidth: parent.width
|
|
||||||
implicitHeight: 36
|
|
||||||
text: "Download File"
|
|
||||||
onClicked: {
|
|
||||||
folder_dialog.open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FluNetworkCallable{
|
|
||||||
id:callable_upload_file
|
|
||||||
onStart: {
|
|
||||||
btn_upload.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_upload.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_upload.progress = 0
|
|
||||||
text_info.text = result
|
|
||||||
console.debug(result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
text_info.text = result
|
|
||||||
}
|
|
||||||
onUploadProgress:
|
|
||||||
(sent,total)=>{
|
|
||||||
btn_upload.progress = sent/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FluNetworkCallable{
|
|
||||||
id:callable_download_file
|
|
||||||
onStart: {
|
|
||||||
btn_download.progress = 0
|
|
||||||
btn_download.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_download.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_download.progress = 0
|
|
||||||
showError(errorString)
|
|
||||||
console.debug(status+";"+errorString+";"+result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
showSuccess(result)
|
|
||||||
}
|
|
||||||
onDownloadProgress:
|
|
||||||
(recv,total)=>{
|
|
||||||
btn_download.progress = recv/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: file_dialog
|
|
||||||
onAccepted: {
|
|
||||||
FluNetwork.postForm("https://httpbingo.org/post")
|
|
||||||
.setRetry(0)//请求失败后不重复请求
|
|
||||||
.add("accessToken","12345678")
|
|
||||||
.addFile("file",FluTools.toLocalPath(file_dialog.selectedFile))
|
|
||||||
.go(callable_upload_file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: folder_dialog
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]+"/big_buck_bunny.mp4"
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
onAccepted: {
|
|
||||||
FluNetwork.get("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
|
||||||
.toDownload(FluTools.toLocalPath(folder_dialog.currentFile))
|
|
||||||
.go(callable_download_file)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,6 @@
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QNetworkDiskCache>
|
#include <QNetworkDiskCache>
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QQmlContext>
|
|
||||||
#include <QJSEngine>
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -130,22 +127,11 @@ QString NetworkParams::buildCacheKey(){
|
||||||
obj.insert("param",QString(QJsonDocument::fromVariant(_paramMap).toJson(QJsonDocument::Compact)));
|
obj.insert("param",QString(QJsonDocument::fromVariant(_paramMap).toJson(QJsonDocument::Compact)));
|
||||||
obj.insert("header",QString(QJsonDocument::fromVariant(_headerMap).toJson(QJsonDocument::Compact)));
|
obj.insert("header",QString(QJsonDocument::fromVariant(_headerMap).toJson(QJsonDocument::Compact)));
|
||||||
obj.insert("file",QString(QJsonDocument::fromVariant(_fileMap).toJson(QJsonDocument::Compact)));
|
obj.insert("file",QString(QJsonDocument::fromVariant(_fileMap).toJson(QJsonDocument::Compact)));
|
||||||
if(_downloadParam){
|
|
||||||
QJsonObject downObj;
|
|
||||||
QString _destPath;
|
|
||||||
bool _append;
|
|
||||||
downObj.insert("destPath",_downloadParam->_destPath);
|
|
||||||
downObj.insert("append",_downloadParam->_append);
|
|
||||||
obj.insert("download",downObj);
|
|
||||||
}
|
|
||||||
QByteArray data = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
QByteArray data = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||||
return QCryptographicHash::hash(data, QCryptographicHash::Sha256).toHex();
|
return QCryptographicHash::hash(data, QCryptographicHash::Sha256).toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkParams::go(NetworkCallable* callable){
|
void NetworkParams::go(NetworkCallable* callable){
|
||||||
QJSValueList data;
|
|
||||||
data<<qjsEngine(FluNetwork::getInstance())->newQObject(this);
|
|
||||||
FluNetwork::getInstance()->_interceptor.call(data);
|
|
||||||
if(_downloadParam){
|
if(_downloadParam){
|
||||||
FluNetwork::getInstance()->handleDownload(this,callable);
|
FluNetwork::getInstance()->handleDownload(this,callable);
|
||||||
}else{
|
}else{
|
||||||
|
@ -154,11 +140,11 @@ void NetworkParams::go(NetworkCallable* callable){
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluNetwork::handle(NetworkParams* params,NetworkCallable* c){
|
void FluNetwork::handle(NetworkParams* params,NetworkCallable* c){
|
||||||
|
QString cacheKey = params->buildCacheKey();
|
||||||
QPointer<NetworkCallable> callable(c);
|
QPointer<NetworkCallable> callable(c);
|
||||||
if(!callable.isNull()){
|
if(!callable.isNull()){
|
||||||
callable->start();
|
callable->start();
|
||||||
}
|
}
|
||||||
QString cacheKey = params->buildCacheKey();
|
|
||||||
if(params->_cacheMode == FluNetworkType::CacheMode::FirstCacheThenRequest && cacheExists(cacheKey)){
|
if(params->_cacheMode == FluNetworkType::CacheMode::FirstCacheThenRequest && cacheExists(cacheKey)){
|
||||||
if(!callable.isNull()){
|
if(!callable.isNull()){
|
||||||
callable->cache(readCache(cacheKey));
|
callable->cache(readCache(cacheKey));
|
||||||
|
@ -216,99 +202,8 @@ void FluNetwork::handle(NetworkParams* params,NetworkCallable* c){
|
||||||
sendRequest(manager,request,params,reply,callable);
|
sendRequest(manager,request,params,reply,callable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluNetwork::handleDownload(NetworkParams* params,NetworkCallable* c){
|
void FluNetwork::handleDownload(NetworkParams* params,NetworkCallable* result){
|
||||||
QString cacheKey = params->buildCacheKey();
|
|
||||||
QPointer<NetworkCallable> callable(c);
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->start();
|
|
||||||
}
|
|
||||||
QUrl url(params->_url);
|
|
||||||
QNetworkAccessManager* manager = new QNetworkAccessManager();
|
|
||||||
QNetworkReply *reply = nullptr;
|
|
||||||
manager->setTransferTimeout(params->getTimeout());
|
|
||||||
addQueryParam(&url,params->_queryMap);
|
|
||||||
QNetworkRequest request(url);
|
|
||||||
addHeaders(&request,params->_headerMap);
|
|
||||||
QString cachePath = getCacheFilePath(cacheKey);
|
|
||||||
QString destPath = params->_downloadParam->_destPath;
|
|
||||||
QFile* destFile = new QFile(destPath);
|
|
||||||
QFile* cacheFile = new QFile(cachePath);
|
|
||||||
bool isOpen = false;
|
|
||||||
qint64 seek = 0;
|
|
||||||
if(cacheFile->exists() && destFile->exists() && params->_downloadParam->_append){
|
|
||||||
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(cacheKey).toUtf8()).object();
|
|
||||||
qint64 fileSize = cacheInfo.value("fileSize").toDouble();
|
|
||||||
qint64 contentLength = cacheInfo.value("contentLength").toDouble();
|
|
||||||
if(fileSize == contentLength && destFile->size() == contentLength){
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->downloadProgress(fileSize,contentLength);
|
|
||||||
callable->success(destPath);
|
|
||||||
callable->finish();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(fileSize==destFile->size()){
|
|
||||||
request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
|
|
||||||
seek = fileSize;
|
|
||||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Append);
|
|
||||||
}else{
|
|
||||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
|
||||||
}
|
|
||||||
if(!isOpen){
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->error(-1,"device not open","");
|
|
||||||
callable->finish();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(params->_downloadParam->_append){
|
|
||||||
if (!cacheFile->open(QIODevice::WriteOnly|QIODevice::Truncate))
|
|
||||||
{
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->error(-1,"cache file device not open","");
|
|
||||||
callable->finish();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = manager->get(request);
|
|
||||||
destFile->setParent(reply);
|
|
||||||
cacheFile->setParent(reply);
|
|
||||||
connect(reply,&QNetworkReply::readyRead,reply,[reply,seek,destFile,cacheFile,callable]{
|
|
||||||
if (!reply || !destFile || reply->error() != QNetworkReply::NoError)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QMap<QString, QVariant> downInfo;
|
|
||||||
qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong()+seek;
|
|
||||||
downInfo.insert("contentLength",contentLength);
|
|
||||||
QString eTag = reply->header(QNetworkRequest::ETagHeader).toString();
|
|
||||||
downInfo.insert("eTag",eTag);
|
|
||||||
destFile->write(reply->readAll());
|
|
||||||
destFile->flush();
|
|
||||||
downInfo.insert("fileSize",destFile->size());
|
|
||||||
if(cacheFile->isOpen()){
|
|
||||||
cacheFile->resize(0);
|
|
||||||
cacheFile->write(QJsonDocument::fromVariant(QVariant(downInfo)).toJson().toBase64());
|
|
||||||
cacheFile->flush();
|
|
||||||
}
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->downloadProgress(destFile->size(),contentLength);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(manager,&QNetworkAccessManager::finished,this,[params,manager,callable](QNetworkReply *reply){
|
|
||||||
params->deleteLater();
|
|
||||||
reply->deleteLater();
|
|
||||||
manager->deleteLater();
|
|
||||||
if(!callable.isNull()){
|
|
||||||
callable->finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FluNetwork::readCache(const QString& key){
|
QString FluNetwork::readCache(const QString& key){
|
||||||
|
@ -451,77 +346,73 @@ FluNetwork::FluNetwork(QObject *parent): QObject{parent}
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::get(const QString& url){
|
NetworkParams* FluNetwork::get(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_GET,this);
|
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::head(const QString& url){
|
NetworkParams* FluNetwork::head(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_HEAD,this);
|
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_HEAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::postBody(const QString& url){
|
NetworkParams* FluNetwork::postBody(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_POST,this);
|
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::putBody(const QString& url){
|
NetworkParams* FluNetwork::putBody(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PUT,this);
|
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::patchBody(const QString& url){
|
NetworkParams* FluNetwork::patchBody(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PATCH,this);
|
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::deleteBody(const QString& url){
|
NetworkParams* FluNetwork::deleteBody(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_DELETE,this);
|
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::postForm(const QString& url){
|
NetworkParams* FluNetwork::postForm(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_POST,this);
|
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::putForm(const QString& url){
|
NetworkParams* FluNetwork::putForm(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PUT,this);
|
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::patchForm(const QString& url){
|
NetworkParams* FluNetwork::patchForm(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PATCH,this);
|
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::deleteForm(const QString& url){
|
NetworkParams* FluNetwork::deleteForm(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_DELETE,this);
|
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::postJson(const QString& url){
|
NetworkParams* FluNetwork::postJson(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_POST,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::putJson(const QString& url){
|
NetworkParams* FluNetwork::putJson(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PUT,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::patchJson(const QString& url){
|
NetworkParams* FluNetwork::patchJson(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PATCH,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::deleteJson(const QString& url){
|
NetworkParams* FluNetwork::deleteJson(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_DELETE,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::postJsonArray(const QString& url){
|
NetworkParams* FluNetwork::postJsonArray(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_POST,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::putJsonArray(const QString& url){
|
NetworkParams* FluNetwork::putJsonArray(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PUT,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::patchJsonArray(const QString& url){
|
NetworkParams* FluNetwork::patchJsonArray(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PATCH,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkParams* FluNetwork::deleteJsonArray(const QString& url){
|
NetworkParams* FluNetwork::deleteJsonArray(const QString& url){
|
||||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_DELETE,this);
|
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_DELETE);
|
||||||
}
|
|
||||||
|
|
||||||
void FluNetwork::setInterceptor(QJSValue interceptor){
|
|
||||||
this->_interceptor = interceptor;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QtQml/qqml.h>
|
#include <QtQml/qqml.h>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QJSValue>
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include "Def.h"
|
#include "Def.h"
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
@ -65,7 +64,7 @@ public:
|
||||||
Q_INVOKABLE NetworkParams* setTimeout(int val);
|
Q_INVOKABLE NetworkParams* setTimeout(int val);
|
||||||
Q_INVOKABLE NetworkParams* setRetry(int val);
|
Q_INVOKABLE NetworkParams* setRetry(int val);
|
||||||
Q_INVOKABLE NetworkParams* setCacheMode(int val);
|
Q_INVOKABLE NetworkParams* setCacheMode(int val);
|
||||||
Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append = false);
|
Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append);
|
||||||
Q_INVOKABLE void go(NetworkCallable* result);
|
Q_INVOKABLE void go(NetworkCallable* result);
|
||||||
QString buildCacheKey();
|
QString buildCacheKey();
|
||||||
QString method2String();
|
QString method2String();
|
||||||
|
@ -117,7 +116,6 @@ public:
|
||||||
Q_INVOKABLE NetworkParams* putJsonArray(const QString& url);
|
Q_INVOKABLE NetworkParams* putJsonArray(const QString& url);
|
||||||
Q_INVOKABLE NetworkParams* patchJsonArray(const QString& url);
|
Q_INVOKABLE NetworkParams* patchJsonArray(const QString& url);
|
||||||
Q_INVOKABLE NetworkParams* deleteJsonArray(const QString& url);
|
Q_INVOKABLE NetworkParams* deleteJsonArray(const QString& url);
|
||||||
Q_INVOKABLE void setInterceptor(QJSValue interceptor);
|
|
||||||
void handle(NetworkParams* params,NetworkCallable* result);
|
void handle(NetworkParams* params,NetworkCallable* result);
|
||||||
void handleDownload(NetworkParams* params,NetworkCallable* result);
|
void handleDownload(NetworkParams* params,NetworkCallable* result);
|
||||||
private:
|
private:
|
||||||
|
@ -128,8 +126,6 @@ private:
|
||||||
QString readCache(const QString& key);
|
QString readCache(const QString& key);
|
||||||
bool cacheExists(const QString& key);
|
bool cacheExists(const QString& key);
|
||||||
QString getCacheFilePath(const QString& key);
|
QString getCacheFilePath(const QString& key);
|
||||||
public:
|
|
||||||
QJSValue _interceptor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUNETWORK_H
|
#endif // FLUNETWORK_H
|
||||||
|
|
Loading…
Reference in New Issue