logic

package
v0.0.0-...-426e299 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPMetadataKeyContentType    = "Content-Type"
	HTTPResponseHeaderContentType = "Content-Type"
)
View Source
const (
	DownloadTaskMetadataKeyFileName = "file-name"
)

Variables

View Source
var (
	ErrPermissionDenied         = status.Error(codes.PermissionDenied, "permission denied")
	ErrDownloadTaskNotCompleted = status.Error(codes.FailedPrecondition, "download task not completed")
)

Functions

This section is empty.

Types

type AccountLogic

type AccountLogic interface {
	CreateAccount(ctx context.Context, in CreateAccountInput) (CreateAccountOutput, error)
	CreateSession(ctx context.Context, in CreateSessionInput) (CreateSessionOutput, error)
	DeleteSession(ctx context.Context, in DeleteSessionInput) error
}

func NewAccountLogic

func NewAccountLogic(
	database database.Database,
	accountDataAccessor database.AccountDataAccessor,
	passwordDataAccessor database.AccountPasswordDataAccessor,
	hashLogic HashLogic,
	tokenLogic TokenLogic,
	takenAccountNameCache cache.TakenAccountName,
	logger *zap.Logger,
) AccountLogic

type CreateAccountInput

type CreateAccountInput struct {
	AccountName string
	Password    string
}

type CreateAccountOutput

type CreateAccountOutput struct {
	ID          uint64
	AccountName string
}

type CreateDownloadTaskInput

type CreateDownloadTaskInput struct {
	Token string
	Type  idm.DownloadType
	URL   string
}

type CreateDownloadTaskOutput

type CreateDownloadTaskOutput struct {
	DownloadTask idm.DownloadTask
}

type CreateSessionInput

type CreateSessionInput struct {
	AccountName string
	Password    string
}

type CreateSessionOutput

type CreateSessionOutput struct {
	Token       string
	ExpiresAt   time.Time
	AccountID   uint64
	AccountName string
}

type DeleteDownloadTaskInput

type DeleteDownloadTaskInput struct {
	Token          string
	DownloadTaskID uint64
}

type DeleteSessionInput

type DeleteSessionInput struct {
	Token string
}

type DeleteSessionOutput

type DeleteSessionOutput struct {
	ExpiredToken string
}

type DownloadTaskLogic

type DownloadTaskLogic interface {
	CreateDownloadTask(ctx context.Context, in CreateDownloadTaskInput) (CreateDownloadTaskOutput, error)
	GetDownloadTaskList(ctx context.Context, in GetDownloadTaskListInput) (GetDownloadTaskListOutput, error)
	UpdateDownloadTask(ctx context.Context, in UpdateDownloadTaskInput) (UpdateDownloadTaskOutput, error)
	UpdateFailedDownloadTaskStatusToPending(ctx context.Context) error
	DeleteDownloadTask(ctx context.Context, in DeleteDownloadTaskInput) error

	ExecuteDownloadTask(ctx context.Context, in ExecuteDownloadTaskInput) error
	ExecuteAllPendingDownloadTask(ctx context.Context) error

	GetDownloadTaskFile(ctx context.Context, in GetDownloadTaskFileInput) (GetDownloadTaskFileOutput, error)
}

func NewDownloadTaskLogic

func NewDownloadTaskLogic(
	tokenLogic TokenLogic,
	accountDataAccessor database.AccountDataAccessor,
	downloadTaskDataAccessor database.DownloadTaskDataAccessor,
	downloadTaskCreatedProducer producer.DownloadTaskCreatedProducer,
	fileClient file.Client,
	database database.Database,
	logger *zap.Logger,
	cronConfig configs.Cron,
) (DownloadTaskLogic, error)

type Downloader

type Downloader interface {
	Download(ctx context.Context, writer io.Writer) (map[string]any, error)
}

func NewFTPDownloader

func NewFTPDownloader() (Downloader, error)

func NewHTTPDownloader

func NewHTTPDownloader(
	url string,
	logger *zap.Logger,
) (Downloader, error)

type ExecuteDownloadTaskInput

type ExecuteDownloadTaskInput struct {
	DownloadTaskID uint64
}

type GetDownloadTaskFileInput

type GetDownloadTaskFileInput struct {
	Token          string
	DownloadTaskID uint64
}

type GetDownloadTaskFileOutput

type GetDownloadTaskFileOutput struct {
	Reader io.ReadCloser
}

type GetDownloadTaskListInput

type GetDownloadTaskListInput struct {
	Token  string
	Offset uint64
	Limit  uint64
}

type GetDownloadTaskListOutput

type GetDownloadTaskListOutput struct {
	DownloadTaskList       []*idm.DownloadTask
	TotalDownloadTaskCount uint64
}

type HashLogic

type HashLogic interface {
	HashPassword(ctx context.Context, plainPassword string) (string, error)
	IsHashEqual(ctx context.Context, plainPassword string, hashedPassword string) (bool, error)
}

func NewHashLogic

func NewHashLogic() HashLogic

type TokenLogic

type TokenLogic interface {
	CreateTokenString(ctx context.Context, accountID uint64) (string, time.Time, error)
	GetAccountIDAndExpireTime(ctx context.Context, token string) (uint64, time.Time, error)
	WithDatabase(database database.Database) TokenLogic
}

func NewTokenLogic

func NewTokenLogic(
	accountDataAccessor database.AccountDataAccessor,
	tokenPublicKeyDataAccessor database.TokenPublicKeyDataAccessor,
	logger *zap.Logger,
	authConfig configs.Auth,
	tokenPublicKeyCache cache.TokenPublicKey,
) (TokenLogic, error)

type UpdateDownloadTaskInput

type UpdateDownloadTaskInput struct {
	Token          string
	DownloadTaskID uint64
	DownloadStatus uint16
	Metadata       string
}

type UpdateDownloadTaskOutput

type UpdateDownloadTaskOutput struct {
	DownloadTask idm.DownloadTask
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL