Browse Source

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

- 移除私有方法_genAuthorization,直接使用generateAuthorization函数
- 在各API请求头中显式传入appId和appCertificate参数
- 简化授权生成流程,减少中间层调用
yourname 2 tháng trước cách đây
mục cha
commit
ed3e8d4ef7
1 tập tin đã thay đổi với 18 bổ sung18 xóa
  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',
       headers: {
         '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),
     })
@@ -436,7 +441,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           channel,
         }),
@@ -459,7 +466,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'DELETE',
       headers: {
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           channel,
         }),
@@ -479,7 +488,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'GET',
       headers: {
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           channel,
         }),
@@ -502,7 +513,9 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
       method: 'PATCH',
       headers: {
         'Content-Type': 'application/json',
-        Authorization: await this._genAuthorization({
+        Authorization: await generateAuthorization({
+          appId: this._appId,
+          appCertificate: this._certificate,
           uid,
           channel,
         }),
@@ -512,17 +525,4 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
 
     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,
-    })
-  }
 }