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.2 KiB

package service
import (
"github.com/rocboss/paopao-ce/internal/conf"
"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"
)
var (
ds core.DataService
ts core.TweetSearchService
oss core.ObjectStorageService
DisablePhoneVerify bool
)
func Initialize() {
ds = dao.DataService()
ts = dao.TweetSearchService()
oss = dao.ObjectStorageService()
DisablePhoneVerify = !conf.CfgIf("Sms")
}
// 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
}