Browse Source

新增 feedback 接口

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
91b599cdc8

+ 13 - 0
pkg/subtitle_best_api/media_info.go

@@ -65,3 +65,16 @@ type IdConvertReply struct {
 	IMDBId  string `json:"imdb_id,omitempty"`
 	IMDBId  string `json:"imdb_id,omitempty"`
 	TVDBId  string `json:"tvdb_id,omitempty"`
 	TVDBId  string `json:"tvdb_id,omitempty"`
 }
 }
+
+type FeedReq struct {
+	Id           string `json:"id"`             // 当前用户的id,这个需要在用户缓存中随机生成
+	Version      string `json:"version"`        // 当前版本号
+	MediaServer  string `json:"media_server"`   // 媒体服务的名称,没有使用则是 None
+	EnableShare  bool   `json:"enable_share"`   // 是否开启了共享功能
+	EnableApiKey bool   `json:"enable_api_key"` // 是否开启本地 http api 功能
+}
+
+type FeedReply struct {
+	Status  int    `json:"status"` // 0 失败,1 成功
+	Message string `json:"message"`
+}

+ 48 - 1
pkg/subtitle_best_api/subtitle_best_api.go

@@ -608,7 +608,54 @@ func (s SubtitleBestApi) ConvertId(id, source, videoType string) (*IdConvertRepl
 	return &idConvertReply, nil
 	return &idConvertReply, nil
 }
 }
 
 
+func (s SubtitleBestApi) FeedBack(id, version, MediaServer string, EnableShare, EnableApiKey bool) (*FeedReply, error) {
+
+	if s.authKey.BaseKey == random_auth_key.BaseKey || s.authKey.AESKey16 == random_auth_key.AESKey16 || s.authKey.AESIv16 == random_auth_key.AESIv16 {
+		return nil, errors.New("auth key is not set")
+	}
+	if len(s.authKey.AESKey16) != 16 {
+		return nil, errors.New(fmt.Sprintf("AESKey16 is not set, %s", s.authKey.AESKey16))
+	}
+	if len(s.authKey.AESIv16) != 16 {
+		return nil, errors.New(fmt.Sprintf("AESIv16 is not set, %s", s.authKey.AESIv16))
+	}
+
+	postUrl := webUrlBase + "/v1/feedback"
+	httpClient, err := my_util.NewHttpClient(s.proxySettings)
+	if err != nil {
+		return nil, err
+	}
+
+	authKey, err := s.randomAuthKey.GetAuthKey()
+	if err != nil {
+		return nil, err
+	}
+
+	formData := make(map[string]string)
+	formData["id"] = id
+	formData["version"] = version
+	formData["media_server"] = MediaServer
+	formData["enable_share"] = strconv.FormatBool(EnableShare)
+	formData["enable_api_key"] = strconv.FormatBool(EnableApiKey)
+	var feedReply FeedReply
+	resp, err := httpClient.R().
+		SetHeader("Authorization", "beer "+authKey).
+		SetFormData(formData).
+		SetResult(&feedReply).
+		Post(postUrl)
+	if err != nil {
+		s.log.Errorln("feedback error, status code:", resp.StatusCode(), "Error:", err)
+		return nil, err
+	}
+
+	if feedReply.Status == 0 {
+		s.log.Warningln("status code:", resp.StatusCode())
+	}
+
+	return &feedReply, nil
+}
+
 const (
 const (
 	webUrlBase = "https://api.subtitle.best"
 	webUrlBase = "https://api.subtitle.best"
-	//webUrlBase = "http://127.0.0.1:8890"
+	//webUrlBase = "http://127.0.0.1:8893"
 )
 )

+ 6 - 0
pkg/subtitle_best_api/subtitle_best_api_test.go

@@ -23,6 +23,12 @@ func TestSubtitleBestApi_GetMediaInfo(t *testing.T) {
 			AESIv16:  global_value.AESIv16(),
 			AESIv16:  global_value.AESIv16(),
 		}, settings.GetSettings().AdvancedSettings.ProxySettings)
 		}, settings.GetSettings().AdvancedSettings.ProxySettings)
 
 
+	feedReply, err := bapi.FeedBack(my_util.RandStringBytesMaskImprSrcSB(64), "1.0.0", "None", true, true)
+	if err != nil {
+		t.Fatal(err)
+	}
+	println("FeedBack:", feedReply.Status, feedReply.Message)
+
 	mediaInfo, err := bapi.GetMediaInfo("tt7278862", "imdb", "series")
 	mediaInfo, err := bapi.GetMediaInfo("tt7278862", "imdb", "series")
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)