mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-02-02 11:17:39 +08:00
update
This commit is contained in:
parent
ed5956d824
commit
ad79480345
@ -132,16 +132,53 @@ FluContentPage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
|
property bool downloading: false
|
||||||
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
||||||
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
||||||
id:btn_breakpoint_download
|
id:btn_breakpoint_download
|
||||||
implicitWidth: parent.width
|
implicitWidth: parent.width
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: progress === 1 ? "打开文件" : "断点下载文件"
|
text: {
|
||||||
|
if(downloading){
|
||||||
|
return "暂停下载"
|
||||||
|
}
|
||||||
|
if(progress === 0){
|
||||||
|
return "断点下载文件"
|
||||||
|
}else if(progress === 1){
|
||||||
|
return "打开文件"
|
||||||
|
}else{
|
||||||
|
return "继续下载"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HttpCallable{
|
||||||
|
id:callable_breakpoint_download
|
||||||
|
onStart: {
|
||||||
|
btn_breakpoint_download.downloading = true
|
||||||
|
}
|
||||||
|
onFinish: {
|
||||||
|
btn_breakpoint_download.downloading = false
|
||||||
|
}
|
||||||
|
onError:
|
||||||
|
(status,errorString,result)=>{
|
||||||
|
console.debug(status+";"+errorString+";"+result)
|
||||||
|
}
|
||||||
|
onSuccess:
|
||||||
|
(result)=>{
|
||||||
|
showSuccess(result)
|
||||||
|
}
|
||||||
|
onDownloadProgress:
|
||||||
|
(recv,total)=>{
|
||||||
|
btn_breakpoint_download.progress = recv/total
|
||||||
|
}
|
||||||
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
if(downloading){
|
||||||
|
http_breakpoint_download.cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
if(progress === 1){
|
if(progress === 1){
|
||||||
FluTools.showFileInFolder(saveFilePath)
|
FluTools.showFileInFolder(saveFilePath)
|
||||||
}else{
|
}else{
|
||||||
@ -260,7 +297,6 @@ FluContentPage{
|
|||||||
btn_upload.progress = sent/total
|
btn_upload.progress = sent/total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: file_dialog
|
id: file_dialog
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
@ -275,30 +311,6 @@ FluContentPage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpCallable{
|
|
||||||
id:callable_breakpoint_download
|
|
||||||
onStart: {
|
|
||||||
btn_breakpoint_download.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_breakpoint_download.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_breakpoint_download.progress = 0
|
|
||||||
showError(errorString)
|
|
||||||
console.debug(status+";"+errorString+";"+result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
showSuccess(result)
|
|
||||||
}
|
|
||||||
onDownloadProgress:
|
|
||||||
(recv,total)=>{
|
|
||||||
btn_breakpoint_download.progress = recv/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpCallable{
|
HttpCallable{
|
||||||
id:callable_download
|
id:callable_download
|
||||||
onStart: {
|
onStart: {
|
||||||
@ -323,7 +335,6 @@ FluContentPage{
|
|||||||
btn_download.progress = recv/total
|
btn_download.progress = recv/total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderDialog {
|
FolderDialog {
|
||||||
id: folder_dialog
|
id: folder_dialog
|
||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||||
|
@ -133,16 +133,53 @@ FluContentPage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
|
property bool downloading: false
|
||||||
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
||||||
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
||||||
id:btn_breakpoint_download
|
id:btn_breakpoint_download
|
||||||
implicitWidth: parent.width
|
implicitWidth: parent.width
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: progress === 1 ? "打开文件" : "断点下载文件"
|
text: {
|
||||||
|
if(downloading){
|
||||||
|
return "暂停下载"
|
||||||
|
}
|
||||||
|
if(progress === 0){
|
||||||
|
return "断点下载文件"
|
||||||
|
}else if(progress === 1){
|
||||||
|
return "打开文件"
|
||||||
|
}else{
|
||||||
|
return "继续下载"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HttpCallable{
|
||||||
|
id:callable_breakpoint_download
|
||||||
|
onStart: {
|
||||||
|
btn_breakpoint_download.downloading = true
|
||||||
|
}
|
||||||
|
onFinish: {
|
||||||
|
btn_breakpoint_download.downloading = false
|
||||||
|
}
|
||||||
|
onError:
|
||||||
|
(status,errorString,result)=>{
|
||||||
|
console.debug(status+";"+errorString+";"+result)
|
||||||
|
}
|
||||||
|
onSuccess:
|
||||||
|
(result)=>{
|
||||||
|
showSuccess(result)
|
||||||
|
}
|
||||||
|
onDownloadProgress:
|
||||||
|
(recv,total)=>{
|
||||||
|
btn_breakpoint_download.progress = recv/total
|
||||||
|
}
|
||||||
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
if(downloading){
|
||||||
|
http_breakpoint_download.cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
if(progress === 1){
|
if(progress === 1){
|
||||||
FluTools.showFileInFolder(saveFilePath)
|
FluTools.showFileInFolder(saveFilePath)
|
||||||
}else{
|
}else{
|
||||||
@ -261,7 +298,6 @@ FluContentPage{
|
|||||||
btn_upload.progress = sent/total
|
btn_upload.progress = sent/total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: file_dialog
|
id: file_dialog
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
@ -276,30 +312,6 @@ FluContentPage{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpCallable{
|
|
||||||
id:callable_breakpoint_download
|
|
||||||
onStart: {
|
|
||||||
btn_breakpoint_download.disabled = true
|
|
||||||
}
|
|
||||||
onFinish: {
|
|
||||||
btn_breakpoint_download.disabled = false
|
|
||||||
}
|
|
||||||
onError:
|
|
||||||
(status,errorString,result)=>{
|
|
||||||
btn_breakpoint_download.progress = 0
|
|
||||||
showError(errorString)
|
|
||||||
console.debug(status+";"+errorString+";"+result)
|
|
||||||
}
|
|
||||||
onSuccess:
|
|
||||||
(result)=>{
|
|
||||||
showSuccess(result)
|
|
||||||
}
|
|
||||||
onDownloadProgress:
|
|
||||||
(recv,total)=>{
|
|
||||||
btn_breakpoint_download.progress = recv/total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpCallable{
|
HttpCallable{
|
||||||
id:callable_download
|
id:callable_download
|
||||||
onStart: {
|
onStart: {
|
||||||
@ -324,7 +336,6 @@ FluContentPage{
|
|||||||
btn_download.progress = recv/total
|
btn_download.progress = recv/total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderDialog {
|
FolderDialog {
|
||||||
id: folder_dialog
|
id: folder_dialog
|
||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||||
|
@ -43,15 +43,16 @@ void FluHttp::cancel(){
|
|||||||
void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
auto requestMap = toRequest(url,params,headers,"post");
|
auto requestMap = toRequest(url,params,headers,"post");
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
Q_EMIT callable->finish();
|
Q_EMIT callable->finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -84,13 +85,13 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
handleCache(requestMap,result);
|
handleCache(httpId,result);
|
||||||
Q_EMIT callable->success(result);
|
Q_EMIT callable->success(result);
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
if(i == retry()-1){
|
if(i == retry()-1){
|
||||||
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
Q_EMIT callable->error(status,errorString,result);
|
Q_EMIT callable->error(status,errorString,result);
|
||||||
}
|
}
|
||||||
@ -103,15 +104,16 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
|
|||||||
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> headers){
|
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> headers){
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
auto requestMap = toRequest(url,params,headers,"postString");
|
auto requestMap = toRequest(url,params,headers,"postString");
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
Q_EMIT callable->finish();
|
Q_EMIT callable->finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -135,13 +137,13 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
handleCache(requestMap,result);
|
handleCache(httpId,result);
|
||||||
Q_EMIT callable->success(result);
|
Q_EMIT callable->success(result);
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
if(i == retry()-1){
|
if(i == retry()-1){
|
||||||
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
Q_EMIT callable->error(status,errorString,result);
|
Q_EMIT callable->error(status,errorString,result);
|
||||||
}
|
}
|
||||||
@ -154,15 +156,16 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<
|
|||||||
void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
auto requestMap = toRequest(url,params,headers,"postJson");
|
auto requestMap = toRequest(url,params,headers,"postJson");
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
Q_EMIT callable->finish();
|
Q_EMIT callable->finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -186,13 +189,13 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
handleCache(requestMap,result);
|
handleCache(httpId,result);
|
||||||
Q_EMIT callable->success(result);
|
Q_EMIT callable->success(result);
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
if(i == retry()-1){
|
if(i == retry()-1){
|
||||||
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
Q_EMIT callable->error(status,errorString,result);
|
Q_EMIT callable->error(status,errorString,result);
|
||||||
}
|
}
|
||||||
@ -205,13 +208,14 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant
|
|||||||
void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
auto requestMap = toRequest(url,params,headers,"get");
|
auto requestMap = toRequest(url,params,headers,"get");
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
Q_EMIT callable->finish();
|
Q_EMIT callable->finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -236,13 +240,13 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> par
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
handleCache(requestMap,result);
|
handleCache(httpId,result);
|
||||||
Q_EMIT callable->success(result);
|
Q_EMIT callable->success(result);
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
if(i == retry()-1){
|
if(i == retry()-1){
|
||||||
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
|
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(httpId)){
|
||||||
Q_EMIT callable->cache(readCache(requestMap));
|
Q_EMIT callable->cache(readCache(httpId));
|
||||||
}
|
}
|
||||||
Q_EMIT callable->error(status,errorString,result);
|
Q_EMIT callable->error(status,errorString,result);
|
||||||
}
|
}
|
||||||
@ -256,6 +260,7 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<
|
|||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
auto requestMap = toRequest(url,params,headers,"download");
|
auto requestMap = toRequest(url,params,headers,"download");
|
||||||
requestMap.insert("savePath",savePath);
|
requestMap.insert("savePath",savePath);
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -273,10 +278,10 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<
|
|||||||
loop.quit();
|
loop.quit();
|
||||||
});
|
});
|
||||||
qint64 seek = 0;
|
qint64 seek = 0;
|
||||||
auto filePath = getCacheFilePath(requestMap);
|
auto filePath = getCacheFilePath(httpId);
|
||||||
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
||||||
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
||||||
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(requestMap).toUtf8()).object();
|
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(httpId).toUtf8()).object();
|
||||||
qint64 fileSize = cacheInfo.value("fileSize").toDouble();
|
qint64 fileSize = cacheInfo.value("fileSize").toDouble();
|
||||||
qint64 contentLength = cacheInfo.value("contentLength").toDouble();
|
qint64 contentLength = cacheInfo.value("contentLength").toDouble();
|
||||||
if(fileSize == contentLength && file->size() == contentLength){
|
if(fileSize == contentLength && file->size() == contentLength){
|
||||||
@ -420,8 +425,8 @@ void FluHttp::addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FluHttp::readCache(const QMap<QString, QVariant>& request){
|
QString FluHttp::readCache(const QString& httpId){
|
||||||
auto filePath = getCacheFilePath(request);
|
auto filePath = getCacheFilePath(httpId);
|
||||||
QString result;
|
QString result;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if(!file.exists()){
|
if(!file.exists()){
|
||||||
@ -434,25 +439,24 @@ QString FluHttp::readCache(const QMap<QString, QVariant>& request){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FluHttp::cacheExists(const QMap<QString, QVariant>& request){
|
bool FluHttp::cacheExists(const QString& httpId){
|
||||||
return QFile(getCacheFilePath(request)).exists();
|
return QFile(getCacheFilePath(httpId)).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FluHttp::getCacheFilePath(const QMap<QString, QVariant>& request){
|
QString FluHttp::getCacheFilePath(const QString& httpId){
|
||||||
auto fileName = FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(request)).toJson());
|
|
||||||
QDir dir = _cacheDir;
|
QDir dir = _cacheDir;
|
||||||
if (!dir.exists(_cacheDir)){
|
if (!dir.exists(_cacheDir)){
|
||||||
dir.mkpath(_cacheDir);
|
dir.mkpath(_cacheDir);
|
||||||
}
|
}
|
||||||
auto filePath = _cacheDir+"/"+fileName;
|
auto filePath = _cacheDir+"/"+httpId;
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::handleCache(QMap<QString, QVariant> request,const QString& result){
|
void FluHttp::handleCache(const QString& httpId,const QString& result){
|
||||||
if(_cacheMode==FluHttpType::CacheMode::NoCache){
|
if(_cacheMode==FluHttpType::CacheMode::NoCache){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto filePath = getCacheFilePath(request);
|
auto filePath = getCacheFilePath(httpId);
|
||||||
QSharedPointer<QFile> file(new QFile(filePath));
|
QSharedPointer<QFile> file(new QFile(filePath));
|
||||||
QIODevice::OpenMode mode = QIODevice::WriteOnly|QIODevice::Truncate;
|
QIODevice::OpenMode mode = QIODevice::WriteOnly|QIODevice::Truncate;
|
||||||
if (!file->open(mode))
|
if (!file->open(mode))
|
||||||
@ -465,11 +469,12 @@ void FluHttp::handleCache(QMap<QString, QVariant> request,const QString& result)
|
|||||||
qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
auto requestMap = toRequest(url,params,headers,"download");
|
auto requestMap = toRequest(url,params,headers,"download");
|
||||||
requestMap.insert("savePath",savePath);
|
requestMap.insert("savePath",savePath);
|
||||||
|
auto httpId = toHttpId(requestMap);
|
||||||
QSharedPointer<QFile> file(new QFile(savePath));
|
QSharedPointer<QFile> file(new QFile(savePath));
|
||||||
auto filePath = getCacheFilePath(requestMap);
|
auto filePath = getCacheFilePath(httpId);
|
||||||
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
||||||
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
||||||
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(requestMap).toUtf8()).object();
|
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(httpId).toUtf8()).object();
|
||||||
double fileSize = cacheInfo.value("fileSize").toDouble();
|
double fileSize = cacheInfo.value("fileSize").toDouble();
|
||||||
double contentLength = cacheInfo.value("contentLength").toDouble();
|
double contentLength = cacheInfo.value("contentLength").toDouble();
|
||||||
if(fileSize == contentLength && file->size() == contentLength){
|
if(fileSize == contentLength && file->size() == contentLength){
|
||||||
@ -484,3 +489,7 @@ qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QStr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FluHttp::toHttpId(const QMap<QString, QVariant>& map){
|
||||||
|
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(map)).toJson());
|
||||||
|
}
|
||||||
|
@ -34,12 +34,13 @@ class FluHttp : public QObject
|
|||||||
private:
|
private:
|
||||||
QVariant invokeIntercept(QMap<QString, QVariant> request,Qt::ConnectionType type = Qt::BlockingQueuedConnection);
|
QVariant invokeIntercept(QMap<QString, QVariant> request,Qt::ConnectionType type = Qt::BlockingQueuedConnection);
|
||||||
QMap<QString, QVariant> toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method);
|
QMap<QString, QVariant> toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method);
|
||||||
|
QString toHttpId(const QMap<QString, QVariant>& map);
|
||||||
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
||||||
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
||||||
void handleCache(QMap<QString, QVariant> request, const QString& result);
|
void handleCache(const QString& httpId, const QString& result);
|
||||||
QString readCache(const QMap<QString, QVariant>& request);
|
QString readCache(const QString& httpId);
|
||||||
bool cacheExists(const QMap<QString, QVariant>& request);
|
bool cacheExists(const QString& httpId);
|
||||||
QString getCacheFilePath(const QMap<QString, QVariant>& request);
|
QString getCacheFilePath(const QString& httpId);
|
||||||
public:
|
public:
|
||||||
explicit FluHttp(QObject *parent = nullptr);
|
explicit FluHttp(QObject *parent = nullptr);
|
||||||
~FluHttp();
|
~FluHttp();
|
||||||
|
Loading…
Reference in New Issue
Block a user