Skip to content

Commit

Permalink
refactor:代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
overwriter committed Jan 10, 2024
1 parent 6c92cd6 commit 383b228
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
10 changes: 4 additions & 6 deletions QCloudMusicApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ find_package(OpenSSL REQUIRED)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)

FILE(GLOB HEADERS ./*.h ./util/*.h)
FILE(GLOB SOURCES ./*.cpp ./util/*.cpp)
add_library(QCloudMusicApi SHARED
./util/crypto.h
./util/config.h
./util/index.h
module.h
module.cpp
request.hpp
${HEADERS}
${SOURCES}
)

target_link_libraries(QCloudMusicApi Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network OpenSSL::SSL OpenSSL::Crypto)
Expand Down
3 changes: 2 additions & 1 deletion QCloudMusicApi/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include <QNetworkInterface>
#include <QVariantMap>
#include <QRegularExpression>
#include <QRandomGenerator>

#include "request.hpp"
#include "request.h"

//入参与返回值类型为QVariantMap
#define APICPP(FUNCNAME) \
Expand Down
11 changes: 6 additions & 5 deletions QCloudMusicApi/request.hpp → QCloudMusicApi/request.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once

#include <iostream>
#include <iostream>
#include <QObject>
#include <QEventLoop>
#include <QJsonDocument>
Expand All @@ -26,7 +24,7 @@

namespace Request {

static QString chooseUserAgent(QString ua = "") {
QString chooseUserAgent(QString ua = "") {
const QVariantMap userAgentList {
{
"mobile",
Expand Down Expand Up @@ -66,7 +64,10 @@ static QString chooseUserAgent(QString ua = "") {
: ua;
}

static auto createRequest(QNetworkAccessManager::Operation method, QString urlStr, QVariantMap data, QVariantMap options) {
QVariantMap createRequest(QNetworkAccessManager::Operation method,
QString urlStr,
QVariantMap data,
QVariantMap options) {
QUrl url(urlStr);
qDebug().noquote() <<
QJsonDocument::fromVariant(
Expand Down
13 changes: 13 additions & 0 deletions QCloudMusicApi/request.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <QObject>
#include <QNetworkAccessManager>

namespace Request {

QString chooseUserAgent(QString ua = "");

QVariantMap createRequest(QNetworkAccessManager::Operation method,
QString urlStr,
QVariantMap data,
QVariantMap options);

}

0 comments on commit 383b228

Please sign in to comment.