Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
litcc committed Sep 24, 2022
1 parent d80d6a2 commit e8f7575
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
24 changes: 20 additions & 4 deletions src/web/controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{info, random_string};
use crate::{AppArgs, info, random_string};
use actix_web::http::{StatusCode};
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
use fancy_regex::Regex;
Expand All @@ -10,6 +10,7 @@ use actix_web::body::BoxBody;
use itertools::Itertools;
use crate::ms_tts::{MsTtsMsgResponse};
use urlencoding::decode as url_decode;
use crate::error::TTSServerError;
use crate::utils::azure_api::{AzureApiEdgeFree, AzureApiPreviewFreeToken, AzureApiSpeakerList, AzureApiSubscribeToken, MS_TTS_QUALITY_LIST, MsApiOrigin, MsTtsMsgRequest};
use crate::web::entity::ApiBaseResponse;
use crate::web::error::ControllerError;
Expand Down Expand Up @@ -43,6 +44,7 @@ impl MsTtsMsgRequestJson {
api_name: MsApiOrigin,
request_id_value: String,
) -> Result<MsTtsMsgRequest, ControllerError> {
let args = AppArgs::parse_macro();
let text_value: String = {
let mut text_tmp1 = self.text.as_str().to_string();
// url 解码
Expand Down Expand Up @@ -103,13 +105,27 @@ impl MsTtsMsgRequestJson {

let ms_informant_list = match api_name {
MsApiOrigin::EdgeFree => {
AzureApiEdgeFree::new().get_vices_list().await
if !args.close_edge_free_api{
AzureApiEdgeFree::new().get_vices_list().await
}else {
Err(TTSServerError::ProgramError("未开启 ms-tts-edge 接口,请勿调用".to_owned()))
}
}
MsApiOrigin::OfficialPreview => {
AzureApiPreviewFreeToken::new().get_vices_list().await
if !args.close_official_preview_api{
AzureApiPreviewFreeToken::new().get_vices_list().await
}else {
Err(TTSServerError::ProgramError("未开启 ms-tts-preview 接口,请勿调用".to_owned()))
}

}
MsApiOrigin::Subscription => {
AzureApiSubscribeToken::get_vices_mixed_list().await
if !args.close_official_subscribe_api{
AzureApiSubscribeToken::get_vices_mixed_list().await
}else {
Err(TTSServerError::ProgramError("未开启 ms-tts-subscribe 接口,请勿调用".to_owned()))
}

}
}.map_err(|e| {
let err = ControllerError::new(format!("获取发音人数据错误 {:?}", e));
Expand Down
45 changes: 28 additions & 17 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,34 @@ pub(crate) async fn register_service() {
let mut app = app.wrap(Compress::default());

// 微软 TTS 文本转语音 相关接口
app = app.service(
// 新版本网页接口地址 (使用api收费访问)
web::resource("/api/tts-ms-subscribe-api")
.wrap(Condition::new(args.subscribe_api_auth_token.is_some(), TokenAuthentication::<MsTtsMsgRequestJson>::default()))
.route(web::get().to(tts_ms_subscribe_api_get_controller))
.route(web::post().to(tts_ms_subscribe_api_post_controller)),
).service(
// 新版本网页接口地址 (免费预览)
web::resource("/api/tts-ms-official-preview")
.route(web::get().to(tts_ms_official_preview_get_controller))
.route(web::post().to(tts_ms_official_preview_post_controller)),
).service(
// 旧版本 edge 预览接口
web::resource("/api/tts-ms-edge")
.route(web::get().to(tts_ms_get_controller))
.route(web::post().to(tts_ms_post_controller)),
);

if !args.close_official_subscribe_api{
app = app.service(
// 新版本网页接口地址 (使用api收费访问)
web::resource("/api/tts-ms-subscribe-api")
.wrap(Condition::new(args.subscribe_api_auth_token.is_some(), TokenAuthentication::<MsTtsMsgRequestJson>::default()))
.route(web::get().to(tts_ms_subscribe_api_get_controller))
.route(web::post().to(tts_ms_subscribe_api_post_controller)),
)
}

if !args.close_official_preview_api{
app = app.service(
// 新版本网页接口地址 (免费预览)
web::resource("/api/tts-ms-official-preview")
.route(web::get().to(tts_ms_official_preview_get_controller))
.route(web::post().to(tts_ms_official_preview_post_controller)),
)
}

if !args.close_edge_free_api{
app = app.service(
// 旧版本 edge 预览接口
web::resource("/api/tts-ms-edge")
.route(web::get().to(tts_ms_get_controller))
.route(web::post().to(tts_ms_post_controller)),
);
}

// 根据功能
// #[cfg(feature = "web-entrance")]
Expand Down

0 comments on commit e8f7575

Please sign in to comment.