Browse Source

调整 HTTP API 细节

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

+ 1 - 0
.gitignore

@@ -121,3 +121,4 @@ ChineseSubFinderSettings.json
 /CustomAuth
 /internal/logic/sub_supplier/assrt/CustomAuth
 /internal/logic/sub_supplier/subhd/CustomAuth
+/internal/pkg/subtitle_best_api/CustomAuth

+ 13 - 1
internal/pkg/subtitle_best_api/subtitle_best_api.go

@@ -4,12 +4,13 @@ import (
 	"bytes"
 	"errors"
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/models"
 	"io/ioutil"
 	"os"
 	"path/filepath"
 	"strconv"
 
+	"github.com/allanpk716/ChineseSubFinder/internal/models"
+
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/random_auth_key"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
@@ -70,6 +71,9 @@ func (s *SubtitleBestApi) GetMediaInfo(id, source, videoType string, _proxySetti
 // AskFroUpload 在使用这个接口前,需要从 IMDB ID 获取到 TMDB ID
 func (s *SubtitleBestApi) AskFroUpload(subSha256 string, trusted bool, ImdbId, TmdbId string, Season, Episode int, _proxySettings ...*settings.ProxySettings) (*AskForUploadReply, 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")
+	}
 	postUrl := webUrlBase + "/v1/ask-for-upload"
 	httpClient, err := my_util.NewHttpClient(_proxySettings...)
 	if err != nil {
@@ -114,6 +118,10 @@ func (s *SubtitleBestApi) AskFroUpload(subSha256 string, trusted bool, ImdbId, T
 // year 这个也是从之前的接口拿到, 2019  or  2022
 func (s *SubtitleBestApi) UploadSub(videoSubInfo *models.VideoSubInfo, subSaveRootDirPath string, tmdbId, year string, _proxySettings ...*settings.ProxySettings) (*UploadSubReply, 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")
+	}
+
 	postUrl := webUrlBase + "/v1/upload-sub"
 	httpClient, err := my_util.NewHttpClient(_proxySettings...)
 	if err != nil {
@@ -175,6 +183,10 @@ func (s *SubtitleBestApi) UploadSub(videoSubInfo *models.VideoSubInfo, subSaveRo
 
 func (s *SubtitleBestApi) UploadLowTrustSub(lowTrustVideoSubInfo *models.LowVideoSubInfo, subSaveRootDirPath string, tmdbId, year string, _proxySettings ...*settings.ProxySettings) (*UploadSubReply, 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")
+	}
+
 	postUrl := webUrlBase + "/v1/upload-sub"
 	httpClient, err := my_util.NewHttpClient(_proxySettings...)
 	if err != nil {

+ 8 - 3
internal/pkg/subtitle_best_api/subtitle_best_api_test.go

@@ -3,15 +3,20 @@ package subtitle_best_api
 import (
 	"testing"
 
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/random_auth_key"
 )
 
 func TestSubtitleBestApi_GetMediaInfo(t *testing.T) {
 
+	my_util.ReadCustomAuthFile(log_helper.GetLogger4Tester())
 	bapi := NewSubtitleBestApi(random_auth_key.AuthKey{
-		BaseKey:  "xx",
-		AESKey16: "xx",
-		AESIv16:  "xx",
+		BaseKey:  global_value.BaseKey(),
+		AESKey16: global_value.AESKey16(),
+		AESIv16:  global_value.AESIv16(),
 	})
 
 	mediaInfo, err := bapi.GetMediaInfo("tt7278862", "imdb", "series")