You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/service/service.go

46 lines
1.1 KiB

3 years ago
package service
import (
"github.com/alimy/cfg"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/dao"
"github.com/rocboss/paopao-ce/internal/model"
"github.com/sirupsen/logrus"
3 years ago
)
var (
ds core.DataService
ts core.TweetSearchService
oss core.ObjectStorageService
DisablePhoneVerify bool
)
3 years ago
func Initialize() {
ds = dao.DataService()
ts = dao.TweetSearchService()
oss = dao.ObjectStorageService()
DisablePhoneVerify = !cfg.If("Sms")
3 years ago
}
// persistMediaContents 获取媒体内容并持久化
func persistMediaContents(contents []*PostContentItem) (items []string, err error) {
items = make([]string, 0, len(contents))
for _, item := range contents {
switch item.Type {
case model.CONTENT_TYPE_IMAGE,
model.CONTENT_TYPE_VIDEO,
model.CONTENT_TYPE_AUDIO,
model.CONTENT_TYPE_ATTACHMENT,
model.CONTENT_TYPE_CHARGE_ATTACHMENT:
items = append(items, item.Content)
if err != nil {
continue
}
if err = oss.PersistObject(oss.ObjectKey(item.Content)); err != nil {
logrus.Errorf("service.persistMediaContents failed: %s", err)
}
}
}
return
}