瀏覽代碼

♻️ refactor(stt-manager): 重构授权生成逻辑

- 移除私有方法_genAuthorization,直接使用generateAuthorization函数
- 在各API请求头中显式传入appId和appCertificate参数
- 简化授权生成流程,减少中间层调用
yourname 2 月之前
父節點
當前提交
ed3e8d4ef7
共有 1 個文件被更改,包括 18 次插入18 次删除
  1. 18 18
      packages/stt-sdk-core/src/managers/stt-manager-adapter.ts

+ 18 - 18
packages/stt-sdk-core/src/managers/stt-manager-adapter.ts

@@ -376,7 +376,12 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'POST',
       method: 'POST',
       headers: {
       headers: {
         'Content-Type': 'application/json',
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({ uid, channel }),
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
+          uid,
+          channel,
+        }),
       },
       },
       body: JSON.stringify(data),
       body: JSON.stringify(data),
     })
     })
@@ -436,7 +441,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'POST',
       method: 'POST',
       headers: {
       headers: {
         'Content-Type': 'application/json',
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           uid,
           channel,
           channel,
         }),
         }),
@@ -459,7 +466,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'DELETE',
       method: 'DELETE',
       headers: {
       headers: {
         'Content-Type': 'application/json',
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           uid,
           channel,
           channel,
         }),
         }),
@@ -479,7 +488,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'GET',
       method: 'GET',
       headers: {
       headers: {
         'Content-Type': 'application/json',
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           uid,
           channel,
           channel,
         }),
         }),
@@ -502,7 +513,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'PATCH',
       method: 'PATCH',
       headers: {
       headers: {
         'Content-Type': 'application/json',
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           uid,
           channel,
           channel,
         }),
         }),
@@ -512,17 +525,4 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
 
 
     return await response.json()
     return await response.json()
   }
   }
-
-  private async _genAuthorization(config: {
-    uid: string | number
-    channel: string
-  }): Promise<string> {
-    // 使用工具函数生成Authorization头(带缓存机制)
-    return await generateAuthorization({
-      appId: this._appId,
-      appCertificate: this._certificate,
-      uid: config.uid,
-      channel: config.channel,
-    })
-  }
 }
 }