Skip to content

Commit

Permalink
Merge pull request #35 from elsagranger/dev2
Browse files Browse the repository at this point in the history
Fix cookie and support to use base64 as file in upload to cloud
  • Loading branch information
s12mmm3 authored May 12, 2024
2 parents 2e25539 + c1e8afd commit 084dc1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions QCloudMusicApi/module.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <QJsonDocument>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QNetworkRequest>
Expand Down Expand Up @@ -779,7 +779,7 @@ QVariantMap Api::cloud_match(QVariantMap query) {
// 云盘上传
QVariantMap Api::cloud(QVariantMap query) {
QString ext = "mp3";
if (query["songFile"].toMap()["name"].toString().indexOf("flac") > -1) {
if (query["songFile"].toMap()["name"].toString().toLower().indexOf("flac") > -1) {
ext = "flac";
}
QString filename = query["songFile"].toMap()["name"].toString()
Expand All @@ -802,6 +802,13 @@ QVariantMap Api::cloud(QVariantMap query) {
}
};
}

if (query.contains("dataAsBase64")) {
auto songFile = query["songFile"].toMap();
songFile["data"] = QByteArray::fromBase64(songFile["data"].toByteArray());
query["songFile"] = songFile;
}

if (!query["songFile"].toMap().contains("md5")) {
auto songFile = query["songFile"].toMap();
auto data = songFile["data"].toByteArray();
Expand Down Expand Up @@ -831,6 +838,16 @@ QVariantMap Api::cloud(QVariantMap query) {
QString album = "";
QString songName = "";

if (query.contains("artist")) {
artist = query["artist"].toString();
}
if (query.contains("album")) {
album = query["album"].toString();
}
if (query.contains("songName")) {
songName = query["songName"].toString();
}

const auto tokenRes = request(
POST,
"https://music.163.com/weapi/nos/token/alloc",
Expand Down
4 changes: 2 additions & 2 deletions QCloudMusicApi/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Plugins::Plugins(QObject *parent)
QVariantMap Plugins::songUpload(QVariantMap query)
{
QString ext = "mp3";
if (query["songFile"].toMap()["name"].toString().indexOf("flac") > -1) {
if (query["songFile"].toMap()["name"].toString().toLower().indexOf("flac") > -1) {
ext = "flac";
}
QString filename = query["songFile"].toMap()["name"].toString()
Expand Down Expand Up @@ -65,7 +65,7 @@ QVariantMap Plugins::songUpload(QVariantMap query)
{ "Content-Type", "audio/mpeg" },
{ "Content-Length", query["songFile"].toMap()["size"] },
},
query["imgFile"].toMap()["data"].toByteArray());
query["songFile"].toMap()["data"].toByteArray());
reply->manager()->deleteLater();

return tokenRes;
Expand Down

0 comments on commit 084dc1d

Please sign in to comment.