controller_base.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package base
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/pkg/cache_center"
  4. "github.com/allanpk716/ChineseSubFinder/pkg/global_value"
  5. "github.com/allanpk716/ChineseSubFinder/pkg/random_auth_key"
  6. "github.com/allanpk716/ChineseSubFinder/pkg/settings"
  7. "github.com/sirupsen/logrus"
  8. "net/http"
  9. "github.com/allanpk716/ChineseSubFinder/pkg/types/backend"
  10. "github.com/allanpk716/ChineseSubFinder/pkg/logic/file_downloader"
  11. "github.com/gin-gonic/gin"
  12. )
  13. type ControllerBase struct {
  14. fileDownloader *file_downloader.FileDownloader
  15. }
  16. func NewControllerBase(loggerBase *logrus.Logger) *ControllerBase {
  17. return &ControllerBase{
  18. fileDownloader: file_downloader.NewFileDownloader(
  19. cache_center.NewCacheCenter("local_task_queue", settings.GetSettings(), loggerBase),
  20. random_auth_key.AuthKey{
  21. BaseKey: global_value.BaseKey(),
  22. AESKey16: global_value.AESKey16(),
  23. AESIv16: global_value.AESIv16(),
  24. }),
  25. }
  26. }
  27. func (cb *ControllerBase) ErrorProcess(c *gin.Context, funcName string, err error) {
  28. if err != nil {
  29. cb.fileDownloader.Log.Errorln(funcName, err.Error())
  30. c.JSON(http.StatusInternalServerError, backend.ReplyCommon{Message: err.Error()})
  31. }
  32. }