core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MarkBegin = ""
	MarkEnd   = "eof"
)
View Source
const PublicAuthKey = "communityPublicAuth"

Variables

View Source
var (
	ErrNotExist   = os.ErrNotExist
	ErrPermission = os.ErrPermission
	Twitter       = "twitter"
	FaceBook      = "facebook"
	WeChat        = "wechat"
)
View Source
var (
	ErrTimeout = errors.New("timeout")
)

Functions

func CasdoorConfigInit added in v1.0.0

func CasdoorConfigInit()

Init casdoor parser

Types

type Account added in v1.0.0

type Account struct {
}

type AppConfig added in v1.0.0

type AppConfig struct {
	EndPoint string
	Debug    bool
}

type Article

type Article struct {
	ArticleEntry
	Content string // in markdown
	Trans   bool
	VttId   string
}

type ArticleEntry

type ArticleEntry struct {
	ID            string
	Title         string
	UId           string
	Cover         string
	Tags          string
	User          User
	Abstract      string
	Label         string
	Ctime         time.Time
	Mtime         time.Time
	ViewCount     int
	LikeCount     int
	PlatformCount []PlatformCount
}

type ArticleLike added in v1.0.0

type ArticleLike struct {
	Id        int
	ArticleId int
	UserId    int
}

type CasdoorConfig added in v1.0.0

type CasdoorConfig struct {
	EndPoint         string
	ClientId         string
	ClientSecret     string
	Certificate      string
	OrganizationName string
	ApplicationName  string
}

type CasdoorSDKService added in v1.0.0

type CasdoorSDKService interface {
	GetUser(name string) (user *casdoorsdk.User, err error)
	GetUsers() ([]*casdoorsdk.User, error)
	ParseJwtToken(token string) (claims *casdoorsdk.Claims, err error)
	GetUserClaim(uid string) (claim *casdoorsdk.User, err error)
	GetUserById(uid string) (user *casdoorsdk.User, err error)
	UpdateUserById(uid string, user *UserInfo) (res bool, err error)
	UpdateCasdoorUserById(uid string, user *casdoorsdk.User) (res bool, err error)
	UpdateUser(user *UserInfo) (res bool, err error)
	GetUserByUserId(uid string) (user *casdoorsdk.User, err error)
	GetOAuthToken(code string, state string) (token *oauth2.Token, err error)
	GetApplication(name string) (*casdoorsdk.Application, error)
}

CasdoorSDKService is the interface for casdoor sdk and easy to mock

type CasdoorSDKServiceAdapter added in v1.0.0

type CasdoorSDKServiceAdapter struct{}

Adapter for mock

func (*CasdoorSDKServiceAdapter) GetApplication added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetApplication(name string) (*casdoorsdk.Application, error)

func (*CasdoorSDKServiceAdapter) GetOAuthToken added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetOAuthToken(code string, state string) (token *oauth2.Token, err error)

func (*CasdoorSDKServiceAdapter) GetUser added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetUser(name string) (user *casdoorsdk.User, err error)

func (*CasdoorSDKServiceAdapter) GetUserById added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetUserById(uid string) (user *casdoorsdk.User, err error)

func (*CasdoorSDKServiceAdapter) GetUserByUserId added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetUserByUserId(uid string) (user *casdoorsdk.User, err error)

func (*CasdoorSDKServiceAdapter) GetUserClaim added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetUserClaim(uid string) (claim *casdoorsdk.User, err error)

func (*CasdoorSDKServiceAdapter) GetUsers added in v1.0.0

func (c *CasdoorSDKServiceAdapter) GetUsers() ([]*casdoorsdk.User, error)

func (*CasdoorSDKServiceAdapter) ParseJwtToken added in v1.0.0

func (c *CasdoorSDKServiceAdapter) ParseJwtToken(token string) (claims *casdoorsdk.Claims, err error)

func (*CasdoorSDKServiceAdapter) UpdateCasdoorUserById added in v1.0.0

func (c *CasdoorSDKServiceAdapter) UpdateCasdoorUserById(uid string, user *casdoorsdk.User) (res bool, err error)

func (*CasdoorSDKServiceAdapter) UpdateUser added in v1.0.0

func (c *CasdoorSDKServiceAdapter) UpdateUser(user *UserInfo) (res bool, err error)

func (*CasdoorSDKServiceAdapter) UpdateUserById added in v1.0.0

func (c *CasdoorSDKServiceAdapter) UpdateUserById(uid string, user *UserInfo) (res bool, err error)

type Community

type Community struct {

	// Casdoor Service for mock
	CasdoorSDKService CasdoorSDKService
	S3Service         S3Service
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, conf *Config) (ret *Community, err error)

func (*Community) Article

func (p *Community) Article(ctx context.Context, id string) (article *Article, err error)

Article returns an article.

func (*Community) ArticleLView added in v1.0.0

func (a *Community) ArticleLView(ctx context.Context, articleId, ip, userId, platform string)

func (*Community) ArticleLike added in v1.0.0

func (p *Community) ArticleLike(ctx context.Context, articleId int, userId string) (bool, error)

func (*Community) ArticleLikeState added in v1.0.0

func (p *Community) ArticleLikeState(ctx context.Context, userId, articleId string) (bool, error)

func (*Community) CanEditable

func (p *Community) CanEditable(ctx context.Context, uid, id string) (editable bool, err error)

CanEditable determine whether the user has the permission to operate.

func (*Community) DelMedia added in v1.0.0

func (c *Community) DelMedia(ctx context.Context, userId, mediaId string) error

func (*Community) DelMedias added in v1.0.0

func (c *Community) DelMedias(ctx context.Context, userId string, ids []string) error

func (*Community) DeleteArticle

func (p *Community) DeleteArticle(ctx context.Context, uid, id string) (err error)

DeleteArticle delete the article.

func (*Community) GetAccessToken added in v1.0.0

func (p *Community) GetAccessToken(code, state string) (token *oauth2.Token, err error)

func (*Community) GetApplicationInfo added in v1.0.0

func (p *Community) GetApplicationInfo() (*casdoorsdk.Application, error)

get community application information

func (*Community) GetArticlesByUid added in v1.0.0

func (p *Community) GetArticlesByUid(ctx context.Context, uid string, page string, limit int) (items []*ArticleEntry, next string, err error)

GetArticlesByUid get articles by user id.

func (*Community) GetClientIP added in v1.0.0

func (p *Community) GetClientIP(r *http.Request) string

func (*Community) GetMediaType added in v1.0.0

func (c *Community) GetMediaType(ctx context.Context, mediaId string) (string, error)

func (*Community) GetMediaUrl added in v1.0.0

func (c *Community) GetMediaUrl(ctx context.Context, mediaId string) (string, error)

get file key

func (*Community) GetOAuthToken added in v1.0.0

func (p *Community) GetOAuthToken(code string, state string) (token *oauth2.Token, err error)

func (*Community) GetTranslateArticle added in v1.0.0

func (p *Community) GetTranslateArticle(ctx context.Context, id string) (article *Article, err error)

func (*Community) GetUser added in v1.0.0

func (p *Community) GetUser(token string) (user *User, err error)

GetUser return author by token

func (*Community) GetUserAuthById added in v1.0.0

func (p *Community) GetUserAuthById(uid string) (user *UserAuth, err error)

GetUserAuthById get userAuth by uid

func (*Community) GetUserById added in v1.0.0

func (p *Community) GetUserById(uid string) (user *User, err error)

GetUserById get user by uid

func (*Community) GetUserClaim added in v1.0.0

func (p *Community) GetUserClaim(uid string) (claim *casdoorsdk.User, err error)

GetUserClaim get user(full) by token

func (*Community) GetVideoDuration added in v1.0.0

func (c *Community) GetVideoDuration(url string) (duration string, err error)

func (*Community) GetVideoSubtitle added in v1.0.0

func (c *Community) GetVideoSubtitle(ctx context.Context, mediaId string) (string, string, error)

func (*Community) IsAdmin added in v1.0.0

func (p *Community) IsAdmin(uid string) (res bool, err error)

IsAdmin check admin permission

func (*Community) ListArticle

func (p *Community) ListArticle(ctx context.Context, from string, limit int, searchValue string, label string) (items []*ArticleEntry, next string, err error)

ListArticle lists articles from a position.

func (*Community) ListMediaByUserId added in v1.0.0

func (c *Community) ListMediaByUserId(ctx context.Context, userId string, format string, page, limitInt int) ([]File, int, error)

func (c *Community) ListMediaByUserId(ctx context.Context, userId string, format string) ([]File, error) {

func (*Community) ListPageUsers added in v1.0.0

func (p *Community) ListPageUsers(from, limit int) (users []*UserAuth, next int, err error)

ListUser get all users

func (*Community) NewVideoTask added in v1.0.0

func (c *Community) NewVideoTask(ctx context.Context, userId, resourceId string) error

NewVideoTask create new video task

func (*Community) ParseJwtToken added in v1.0.0

func (p *Community) ParseJwtToken(token string) (userId string, err error)

ParseJwtToken return user id by token

func (*Community) PutArticle

func (p *Community) PutArticle(ctx context.Context, uid string, article *Article) (id string, err error)

PutArticle adds new article (ID == "") or edits an existing article (ID != "").

func (*Community) RedirectToCasdoor added in v1.0.0

func (p *Community) RedirectToCasdoor(redirect string) (loginURL string)

func (*Community) RetryCaptionGenerate added in v1.0.0

func (c *Community) RetryCaptionGenerate(ctx context.Context, userId, videoId string) error

func (*Community) SaveMedia added in v1.0.0

func (c *Community) SaveMedia(ctx context.Context, userId string, data []byte, fileExt string) (int64, error)

func (*Community) SetVideoTaskCache added in v1.0.0

func (c *Community) SetVideoTaskCache(key string, value VideoTaskTimestamp)

SetVideoTaskCache set video task cache

func (*Community) SetVideoTaskFailed added in v1.0.0

func (c *Community) SetVideoTaskFailed(ctx context.Context, resourceId string) error

SetVideoTaskFailed set video task failed

func (*Community) SetVideoTaskOutput added in v1.0.0

func (c *Community) SetVideoTaskOutput(ctx context.Context, resourceId string, output string) error

SetVideoTaskOutput set video task output link

func (*Community) SetVideoTaskSuccess added in v1.0.0

func (c *Community) SetVideoTaskSuccess(ctx context.Context, resourceId string) error

SetVideoTaskSuccess set video task success

func (*Community) Share added in v1.0.0

func (p *Community) Share(ip, platform, userId, articleId string)

share count

func (*Community) TimedCheckVideoTask added in v1.0.0

func (c *Community) TimedCheckVideoTask(ctx context.Context, timeout time.Duration)

Timed check status of video task with timeout

func (*Community) TranslateArticle added in v1.0.0

func (p *Community) TranslateArticle(ctx context.Context, inputArticle *Article) (translatedArticle *Article, err error)

func (*Community) TranslateMarkdownText added in v1.0.0

func (p *Community) TranslateMarkdownText(ctx context.Context, src string, from string, to language.Tag) (string, error)

func (*Community) UpdateUser added in v1.0.0

func (p *Community) UpdateUser(user *UserInfo) (res bool, err error)

func (*Community) UpdateUserById added in v1.0.0

func (p *Community) UpdateUserById(uid string, user *UserInfo) (res bool, err error)

UpdateUserById update user by uid

func (*Community) UpdateUserPublicAuth added in v1.0.0

func (p *Community) UpdateUserPublicAuth(uid string, publicAuth bool) (res bool, err error)

type Config

type Config struct {
	AppConfig     AppConfig
	DBConfig      DBConfig
	QiNiuConfig   QiNiuConfig
	CasdoorConfig CasdoorConfig
}

func NewConfigFromEnv added in v1.0.0

func NewConfigFromEnv() *Config

type DBConfig added in v1.0.0

type DBConfig struct {
	Driver string
	DSN    string
}

type File added in v1.0.0

type File struct {
	Id       int
	FileKey  string
	Format   string
	UserId   string
	Size     int64
	CreateAt time.Time
	UpdateAt time.Time
	Duration *string
	Vtt      string
}

type PlatformCount added in v1.0.0

type PlatformCount struct {
	ArticleId string
	Platform  string
	ViewCount string
}

type QiNiuConfig added in v1.0.0

type QiNiuConfig struct {
	AccessKey      string
	SecretKey      string
	BlobUS         string
	Domain         string
	TranslationKey string
}

type S3Reader added in v1.0.0

type S3Reader interface {
	Close() error
	Read(p []byte) (int, error)
	ContentType() string
	Size() int64
}

type S3Service added in v1.0.0

type S3Service interface {
	NewReader(ctx context.Context, key string, opts *blob.ReaderOptions) (_ S3Reader, err error)
	NewWriter(ctx context.Context, key string, opts *blob.WriterOptions) (_ S3Writer, err error)
	Delete(ctx context.Context, key string) (err error)
}

S3Service is the interface for s3 service and easy to mock

type S3ServiceAdapter added in v1.0.0

type S3ServiceAdapter struct {
	// contains filtered or unexported fields
}

func (*S3ServiceAdapter) Delete added in v1.0.0

func (s *S3ServiceAdapter) Delete(ctx context.Context, key string) (err error)

func (*S3ServiceAdapter) NewReader added in v1.0.0

func (s *S3ServiceAdapter) NewReader(ctx context.Context, key string, opts *blob.ReaderOptions) (_ S3Reader, err error)

func (*S3ServiceAdapter) NewWriter added in v1.0.0

func (s *S3ServiceAdapter) NewWriter(ctx context.Context, key string, opts *blob.WriterOptions) (_ S3Writer, err error)

type S3Writer added in v1.0.0

type S3Writer interface {
	Close() error
	Write(p []byte) (n int, err error)
}

type Translation added in v1.0.0

type Translation struct {
	Engine         *translation.Engine
	VideoTaskCache *VideoTaskCache
}

type User deprecated added in v1.0.0

type User struct {
	Id       string
	Name     string
	Password string
	Avatar   string
}

Deprecated: use casdoorsdk instead

type UserAuth added in v1.0.0

type UserAuth struct {
	Id     string
	Owner  string
	Name   string
	Avatar string
	Status bool
}

type UserClaim added in v1.0.0

type UserClaim casdoorsdk.Claims

type UserInfo added in v1.0.0

type UserInfo casdoorsdk.User

type VideoSubtitle added in v1.0.0

type VideoSubtitle struct {
	VideoId    int
	SubtitleId int
	UserId     int
	Language   string
}

todo

type VideoTask added in v1.0.0

type VideoTask struct {
	Id         int
	ResourceId string
	UserId     string // User id
	TaskId     string // ASR task id
	Output     string // Recognition result link
	Status     int    // 0: progress, -1: failed, 1: ok
	CreateAt   time.Time
	UpdateAt   time.Time
}

VideoTask video task define

type VideoTaskCache added in v1.0.0

type VideoTaskCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

VideoTaskCache video task cache Simple cache, no expiration

func NewVideoTaskCache added in v1.0.0

func NewVideoTaskCache() *VideoTaskCache

NewVideoTaskCache create new video task cache

func (*VideoTaskCache) Clear added in v1.0.0

func (c *VideoTaskCache) Clear()

Clear clear video task cache

func (*VideoTaskCache) Delete added in v1.0.0

func (c *VideoTaskCache) Delete(key string)

Delete delete video task

func (*VideoTaskCache) Get added in v1.0.0

Get get video task timestamp

func (*VideoTaskCache) Set added in v1.0.0

func (c *VideoTaskCache) Set(key string, value VideoTaskTimestamp)

Set set video task timestamp

type VideoTaskMap added in v1.0.0

type VideoTaskMap map[string]VideoTaskTimestamp

type VideoTaskTimestamp added in v1.0.0

type VideoTaskTimestamp int64

Jump to

Keyboard shortcuts

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