This commit is contained in:
@@ -6,16 +6,15 @@ package v1_19
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/secret"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/secret"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func batchProcess[T any](x *xorm.Engine, buf []T, query func(limit, start int) *xorm.Session, process func(*xorm.Session, T) error) error {
|
||||
func batchProcess[T any](x db.EngineMigration, buf []T, query func(limit, start int) db.Session, process func(db.Session, T) error) error {
|
||||
size := cap(buf)
|
||||
start := 0
|
||||
for {
|
||||
@@ -52,7 +51,7 @@ func batchProcess[T any](x *xorm.Engine, buf []T, query func(limit, start int) *
|
||||
}
|
||||
}
|
||||
|
||||
func AddHeaderAuthorizationEncryptedColWebhook(x *xorm.Engine) error {
|
||||
func AddHeaderAuthorizationEncryptedColWebhook(x db.EngineMigration) error {
|
||||
// Add the column to the table
|
||||
type Webhook struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
@@ -81,10 +80,10 @@ func AddHeaderAuthorizationEncryptedColWebhook(x *xorm.Engine) error {
|
||||
|
||||
err = batchProcess(x,
|
||||
make([]*Webhook, 0, 50),
|
||||
func(limit, start int) *xorm.Session {
|
||||
func(limit, start int) db.Session {
|
||||
return x.Where("type=?", "matrix").OrderBy("id").Limit(limit, start)
|
||||
},
|
||||
func(sess *xorm.Session, hook *Webhook) error {
|
||||
func(sess db.Session, hook *Webhook) error {
|
||||
// retrieve token from meta
|
||||
var withToken MatrixMetaWithAccessToken
|
||||
err := json.Unmarshal([]byte(hook.Meta), &withToken)
|
||||
@@ -129,11 +128,11 @@ func AddHeaderAuthorizationEncryptedColWebhook(x *xorm.Engine) error {
|
||||
}
|
||||
|
||||
type MatrixPayloadSafe struct {
|
||||
Body string `json:"body"`
|
||||
MsgType string `json:"msgtype"`
|
||||
Format string `json:"format"`
|
||||
FormattedBody string `json:"formatted_body"`
|
||||
Commits []*api.PayloadCommit `json:"io.gitea.commits,omitempty"`
|
||||
Body string `json:"body"`
|
||||
MsgType string `json:"msgtype"`
|
||||
Format string `json:"format"`
|
||||
FormattedBody string `json:"formatted_body"`
|
||||
Commits json.Value `json:"io.gitea.commits,omitempty"`
|
||||
}
|
||||
type MatrixPayloadUnsafe struct {
|
||||
MatrixPayloadSafe
|
||||
@@ -142,13 +141,13 @@ func AddHeaderAuthorizationEncryptedColWebhook(x *xorm.Engine) error {
|
||||
|
||||
err = batchProcess(x,
|
||||
make([]*HookTask, 0, 50),
|
||||
func(limit, start int) *xorm.Session {
|
||||
func(limit, start int) db.Session {
|
||||
return x.Where(builder.And(
|
||||
builder.In("hook_id", builder.Select("id").From("webhook").Where(builder.Eq{"type": "matrix"})),
|
||||
builder.Like{"payload_content", "access_token"},
|
||||
)).OrderBy("id").Limit(limit, 0) // ignore the provided "start", since other payload were already converted and don't contain 'payload_content' anymore
|
||||
},
|
||||
func(sess *xorm.Session, hookTask *HookTask) error {
|
||||
func(sess db.Session, hookTask *HookTask) error {
|
||||
// retrieve token from payload_content
|
||||
var withToken MatrixPayloadUnsafe
|
||||
err := json.Unmarshal([]byte(hookTask.PayloadContent), &withToken)
|
||||
|
||||
Reference in New Issue
Block a user