@@ -9,11 +9,9 @@ import (
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/google"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/web/webg"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
@@ -78,8 +76,8 @@ func isCustomerServiceRole(ctx context.Context, acc *mwacc.MwAcc) bool {
|
||||
return strings.Contains(roleName, "客服")
|
||||
}
|
||||
|
||||
// 账号登录
|
||||
func AccLogin(ctx context.Context, acc string, pwd string, code string) (*mwacc.MwAcc, *srvdef.SrvErr) {
|
||||
// AccLogin 账号登录(已取消谷歌验证,密码正确即登录)
|
||||
func AccLogin(ctx context.Context, acc string, pwd string) (*mwacc.MwAcc, *srvdef.SrvErr) {
|
||||
var data *mwacc.MwAcc
|
||||
res, dataErr := mwacc.FindOneAccByFilter(ctx, bson.M{
|
||||
mwacc.FN.MwAcc.Acc: acc,
|
||||
@@ -93,49 +91,22 @@ func AccLogin(ctx context.Context, acc string, pwd string, code string) (*mwacc.
|
||||
return data, srvdef.New(srvdef.AccountErrAccessForbid, srvdef.AccountErrAccessForbid.Msg(), "")
|
||||
}
|
||||
|
||||
// 通过验证,再次验证密码是否正确
|
||||
md5pwd := crypt.StrToMd5(pwd)
|
||||
if res.Pwd != md5pwd {
|
||||
return data, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
||||
}
|
||||
|
||||
if !res.IsBase32 {
|
||||
// 谷歌绑定二维码
|
||||
googleUrl := google.NewGoogleAuth().GetQrcode(acc, res.Base32)
|
||||
qrCodePNG, _ := qrcode.Encode(googleUrl, qrcode.Medium, 256)
|
||||
|
||||
bq := &mwacc.MwAcc{}
|
||||
bq.Qurl = qrCodePNG
|
||||
data = bq
|
||||
} else {
|
||||
// hf屏蔽
|
||||
if webg.Conf.RunMod == "prod" && (res.RoleId != 46761 && res.RoleId != 29601) {
|
||||
if code == "" {
|
||||
return data, srvdef.New(srvdef.ErrCaptcha, srvdef.ErrCaptcha.Msg(), "")
|
||||
}
|
||||
result, Verr := google.NewGoogleAuth().VerifyCode(res.Base32, code)
|
||||
if Verr != nil || !result {
|
||||
return data, srvdef.New(srvdef.ErrCaptchaInvalid, srvdef.ErrCaptchaInvalid.Msg(), "")
|
||||
}
|
||||
}
|
||||
// 通过验证,再次验证密码是否正确
|
||||
pwd := crypt.StrToMd5(pwd)
|
||||
if res.Pwd != pwd {
|
||||
return data, srvdef.New(srvdef.AccountErrPasswordError, srvdef.AccountErrPasswordError.Msg(), "")
|
||||
}
|
||||
getToken, err := generateToken(res.Id)
|
||||
if err != nil {
|
||||
return data, srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
||||
}
|
||||
_ = mwacc.UpOneAccByFilter(ctx, bson.M{
|
||||
mwacc.FN.MwAcc.Id: res.Id,
|
||||
}, bson.M{
|
||||
mwacc.FN.MwAcc.LastTime: time.Now(),
|
||||
})
|
||||
// 更新最近登录时间
|
||||
data = res
|
||||
data.Token = getToken
|
||||
getToken, err := generateToken(res.Id)
|
||||
if err != nil {
|
||||
return data, srvdef.New(srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg(), "")
|
||||
}
|
||||
_ = mwacc.UpOneAccByFilter(ctx, bson.M{
|
||||
mwacc.FN.MwAcc.Id: res.Id,
|
||||
}, bson.M{
|
||||
mwacc.FN.MwAcc.LastTime: time.Now(),
|
||||
})
|
||||
data = res
|
||||
data.Token = getToken
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package srv_seopush
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/models/playletthememod"
|
||||
seoindexnow "videoweb/pub/seo/indexnow"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// BulkIndexNowResult 批量提交结果,包含提交的 URL 列表和 IndexNow 原始回执。
|
||||
type BulkIndexNowResult struct {
|
||||
URLs []string `json:"urls"`
|
||||
SubmitInfo *seoindexnow.BatchResult `json:"submitInfo"`
|
||||
}
|
||||
|
||||
// SubmitHomeAndThemes 组装主页 + 前 N 个专题(按 Rank 降序)URL,批量提交 IndexNow。
|
||||
// limit 为 URL 总数(包含主页),默认 10;小于等于 1 时视为仅主页。
|
||||
// hostOverride 非空时覆盖 sys_cfg.webAddr,用于把同一批内容推到新域名(支持带 scheme 或裸域名)。
|
||||
func SubmitHomeAndThemes(ctx context.Context, limit int, hostOverride string) (*BulkIndexNowResult, *srvdef.SrvErr) {
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
webAddr := strings.TrimRight(strings.TrimSpace(hostOverride), "/")
|
||||
if webAddr == "" {
|
||||
webAddr = SEOBaseURL(ctx)
|
||||
} else if !strings.HasPrefix(webAddr, "http://") && !strings.HasPrefix(webAddr, "https://") {
|
||||
webAddr = "https://" + webAddr
|
||||
}
|
||||
if webAddr == "" {
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "WebAddr 未配置", "")
|
||||
}
|
||||
|
||||
root := strings.TrimRight(webAddr, "/")
|
||||
|
||||
urls := make([]string, 0, limit)
|
||||
urls = append(urls, root+"/")
|
||||
if remain := limit - 1; remain > 0 {
|
||||
themes, err := playletthememod.FindManyPlayletTheme(ctx,
|
||||
bson.M{playletthememod.FN.PlayletTheme.Status: true},
|
||||
options.Find().
|
||||
SetSort(bson.M{playletthememod.FN.PlayletTheme.Rank: -1}).
|
||||
SetLimit(int64(remain)))
|
||||
if err == nil {
|
||||
for _, t := range themes {
|
||||
if t == nil || t.Id <= 0 {
|
||||
continue
|
||||
}
|
||||
seg := url.PathEscape(utils.PathSegment(t.Slug, t.Id))
|
||||
if seg == "" {
|
||||
continue
|
||||
}
|
||||
urls = append(urls, root+"/collection/"+seg)
|
||||
}
|
||||
} else {
|
||||
log.Warn("seopush bulk: list themes failed", log.Any("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
config, cerr := seoindexnow.BuildConfig(webAddr)
|
||||
if cerr != nil {
|
||||
return nil, srvdef.New(srvdef.Failure, fmt.Sprintf("构造 IndexNow 配置失败: %v", cerr), "")
|
||||
}
|
||||
result := seoindexnow.NewBatchIndexNowSubmitter(config).SubmitBatch(urls)
|
||||
log.Info("seopush bulk: indexnow submitted",
|
||||
log.Any("urls", urls),
|
||||
log.Any("statusCodes", result.StatusCodes),
|
||||
log.Any("success", result.SuccessCount),
|
||||
log.Any("fail", result.FailCount))
|
||||
return &BulkIndexNowResult{URLs: urls, SubmitInfo: result}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user