Skip to content

Commit

Permalink
新增 feedback 接口
Browse files Browse the repository at this point in the history
Signed-off-by: allan716 <525223688@qq.com>
  • Loading branch information
allanpk716 committed Jul 14, 2022
1 parent f1df710 commit 91b599c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/subtitle_best_api/media_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ type IdConvertReply struct {
IMDBId string `json:"imdb_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"`
}
49 changes: 48 additions & 1 deletion pkg/subtitle_best_api/subtitle_best_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,54 @@ func (s SubtitleBestApi) ConvertId(id, source, videoType string) (*IdConvertRepl
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 (
webUrlBase = "https://api.subtitle.best"
//webUrlBase = "http://127.0.0.1:8890"
//webUrlBase = "http://127.0.0.1:8893"
)
6 changes: 6 additions & 0 deletions pkg/subtitle_best_api/subtitle_best_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func TestSubtitleBestApi_GetMediaInfo(t *testing.T) {
AESIv16: global_value.AESIv16(),
}, 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")
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 91b599c

Please sign in to comment.