Annotate unused code for now.

This commit is contained in:
2025-09-15 23:03:48 +08:00
parent aaf2f8dc36
commit 577990de69
2 changed files with 42 additions and 36 deletions

View File

@@ -571,7 +571,7 @@ config RECEIVE_CUSTOM_MESSAGE
help help
启用接收自定义消息功能,允许设备接收来自服务器的自定义消息(最好通过 MQTT 协议) 启用接收自定义消息功能,允许设备接收来自服务器的自定义消息(最好通过 MQTT 协议)
menu TAIJIPAI_S3_CONFIG menu "TAIJIPAI_S3_CONFIG"
depends on BOARD_TYPE_ESP32S3_Taiji_Pi depends on BOARD_TYPE_ESP32S3_Taiji_Pi
choice I2S_TYPE_TAIJIPI_S3 choice I2S_TYPE_TAIJIPI_S3
depends on BOARD_TYPE_ESP32S3_Taiji_Pi depends on BOARD_TYPE_ESP32S3_Taiji_Pi

View File

@@ -126,41 +126,41 @@ static std::string url_encode(const std::string& str) {
return encoded; return encoded;
} }
// 在文件开头添加一个辅助函数统一处理URL构建 //// 在文件开头添加一个辅助函数统一处理URL构建
static std::string buildUrlWithParams(const std::string& base_url, const std::string& path, const std::string& query) { //static std::string buildUrlWithParams(const std::string& base_url, const std::string& path, const std::string& query) {
std::string result_url = base_url + path + "?"; // std::string result_url = base_url + path + "?";
size_t pos = 0; // size_t pos = 0;
size_t amp_pos = 0; // size_t amp_pos = 0;
//
while ((amp_pos = query.find("&", pos)) != std::string::npos) { // while ((amp_pos = query.find("&", pos)) != std::string::npos) {
std::string param = query.substr(pos, amp_pos - pos); // std::string param = query.substr(pos, amp_pos - pos);
size_t eq_pos = param.find("="); // size_t eq_pos = param.find("=");
//
if (eq_pos != std::string::npos) { // if (eq_pos != std::string::npos) {
std::string key = param.substr(0, eq_pos); // std::string key = param.substr(0, eq_pos);
std::string value = param.substr(eq_pos + 1); // std::string value = param.substr(eq_pos + 1);
result_url += key + "=" + url_encode(value) + "&"; // result_url += key + "=" + url_encode(value) + "&";
} else { // } else {
result_url += param + "&"; // result_url += param + "&";
} // }
//
pos = amp_pos + 1; // pos = amp_pos + 1;
} // }
//
// 处理最后一个参数 // // 处理最后一个参数
std::string last_param = query.substr(pos); // std::string last_param = query.substr(pos);
size_t eq_pos = last_param.find("="); // size_t eq_pos = last_param.find("=");
//
if (eq_pos != std::string::npos) { // if (eq_pos != std::string::npos) {
std::string key = last_param.substr(0, eq_pos); // std::string key = last_param.substr(0, eq_pos);
std::string value = last_param.substr(eq_pos + 1); // std::string value = last_param.substr(eq_pos + 1);
result_url += key + "=" + url_encode(value); // result_url += key + "=" + url_encode(value);
} else { // } else {
result_url += last_param; // result_url += last_param;
} // }
//
return result_url; // return result_url;
} //}
Esp32Music::Esp32Music() : last_downloaded_data_(), current_music_url_(), current_song_name_(), Esp32Music::Esp32Music() : last_downloaded_data_(), current_music_url_(), current_song_name_(),
song_name_displayed_(false), current_lyric_url_(), lyrics_(), song_name_displayed_(false), current_lyric_url_(), lyrics_(),
@@ -302,6 +302,9 @@ bool Esp32Music::Download(const std::string& song_name, const std::string& artis
// 使用Board提供的HTTP客户端 // 使用Board提供的HTTP客户端
auto network = Board::GetInstance().GetNetwork(); auto network = Board::GetInstance().GetNetwork();
auto http = network->CreateHttp(0); auto http = network->CreateHttp(0);
// 复用连接(服务端支持 Keep-Alive
http->SetHeader("Connection", "keep-alive");
// 设置基本请求头 // 设置基本请求头
http->SetHeader("User-Agent", "ESP32-Music-Player/1.0"); http->SetHeader("User-Agent", "ESP32-Music-Player/1.0");
@@ -315,6 +318,9 @@ bool Esp32Music::Download(const std::string& song_name, const std::string& artis
ESP_LOGE(TAG, "Failed to connect to music API"); ESP_LOGE(TAG, "Failed to connect to music API");
return false; return false;
} }
// 添加超时
http->SetTimeout(15000);
// 检查响应状态码 // 检查响应状态码
int status_code = http->GetStatusCode(); int status_code = http->GetStatusCode();