Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskcenter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
taskcenter
Commits
6c179463
Commit
6c179463
authored
Oct 11, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
c93edda8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
60 additions
and
41 deletions
+60
-41
db.go
dao/db.go
+3
-3
tg_task.go
dao/tg_task.go
+4
-4
jwt.go
middleware/jwt.go
+11
-1
api.go
model/api/api.go
+12
-11
taskcenter.go
model/db/taskcenter.go
+17
-16
router.go
server/router.go
+4
-4
group.go
service/group.go
+3
-0
task.go
sync/task.go
+3
-1
jwt.go
util/jwt.go
+3
-1
No files found.
dao/db.go
View file @
6c179463
...
...
@@ -129,16 +129,16 @@ func (d *Dao) GetTaskResult(tid int, userId string) (status string, err error) {
return
""
,
err
}
temp
:=
&
dbModel
.
TaskHistory
{}
tx
:=
d
.
db
.
Session
(
&
gorm
.
Session
{
Logger
:
logger
.
Default
.
LogMode
(
logger
.
Silent
)})
if
!
isDailyTask
{
err
=
d
.
db
.
Model
(
&
dbModel
.
TaskHistory
{})
.
Where
(
"task_id = ? and user_id = ?"
,
tid
,
userId
)
.
First
(
temp
)
.
Error
err
=
tx
.
Model
(
&
dbModel
.
TaskHistory
{})
.
Where
(
"task_id = ? and user_id = ?"
,
tid
,
userId
)
.
First
(
temp
)
.
Error
if
err
==
gorm
.
ErrRecordNotFound
{
return
constant
.
TaskHistoryStatusTodo
,
nil
}
return
temp
.
Status
,
err
}
err
=
d
.
db
.
Model
(
&
dbModel
.
TaskHistory
{})
.
err
=
tx
.
Model
(
&
dbModel
.
TaskHistory
{})
.
Where
(
"task_id = ? and user_id = ? and created_at >= ?"
,
tid
,
userId
,
time
.
Now
()
.
UTC
()
.
Truncate
(
24
*
time
.
Hour
))
.
First
(
temp
)
.
Error
if
err
==
gorm
.
ErrRecordNotFound
{
...
...
dao/tg_task.go
View file @
6c179463
...
...
@@ -45,20 +45,20 @@ func (d *Dao) CheckTGJoin(userId string, chatId int) (ok bool, err error) {
return
gjson
.
Get
(
string
(
data
),
"data.joined"
)
.
Bool
(),
nil
}
func
(
d
*
Dao
)
CheckTGActive
(
userId
string
,
chatId
int
)
(
ok
bool
,
err
error
)
{
func
(
d
*
Dao
)
CheckTGActive
(
userId
string
,
chatId
int
)
(
msgCount
int
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/api/v1/user/active?chatId=%d&userId=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
TGTask
.
URL
,
"/"
),
chatId
,
userId
)
log
.
WithField
(
"url"
,
url
)
.
Debug
(
"check tg active"
)
data
,
err
:=
httpGet
(
url
)
if
err
!=
nil
{
return
false
,
err
return
0
,
err
}
retCode
:=
gjson
.
Get
(
string
(
data
),
"code"
)
.
Int
()
if
retCode
==
1
{
return
false
,
errors
.
New
(
string
(
data
))
return
0
,
errors
.
New
(
string
(
data
))
}
return
gjson
.
Get
(
string
(
data
),
"data.msgCount"
)
.
Int
()
>
0
,
nil
return
int
(
gjson
.
Get
(
string
(
data
),
"data.msgCount"
)
.
Int
())
,
nil
}
func
httpGet
(
url
string
)
([]
byte
,
error
)
{
...
...
middleware/jwt.go
View file @
6c179463
...
...
@@ -20,7 +20,7 @@ func JWTMiddleware(secret string, needAdmin bool) gin.HandlerFunc {
return
}
ok
,
expired
,
uid
:=
util
.
ParseJWT
(
secret
,
tokenString
[
7
:
])
ok
,
expired
,
uid
,
role
:=
util
.
ParseJWT
(
secret
,
tokenString
[
7
:
])
if
!
ok
{
c
.
JSON
(
200
,
gin
.
H
{
"code"
:
1
,
...
...
@@ -41,6 +41,16 @@ func JWTMiddleware(secret string, needAdmin bool) gin.HandlerFunc {
return
}
if
needAdmin
&&
role
!=
"admin"
{
c
.
JSON
(
200
,
gin
.
H
{
"code"
:
1
,
"msg"
:
"permission denied"
,
"data"
:
""
,
})
c
.
Abort
()
return
}
log
.
WithField
(
"userId"
,
uid
)
.
Debug
(
"jwt uid"
)
c
.
Set
(
"userId"
,
uid
)
c
.
Next
()
...
...
model/api/api.go
View file @
6c179463
...
...
@@ -47,17 +47,18 @@ type CreateGroupRequest struct {
}
type
Task
struct
{
TaskId
int
`json:"taskId,omitempty"`
Platform
string
`json:"platform" binding:"required"`
Action
string
`json:"action" binding:"required"`
Url
string
`json:"url"`
TweetId
int
`json:"tweetId"`
Description
string
`json:"description" binding:"required"`
Reward
int
`json:"reward" binding:"required"`
Start
int
`json:"start" binding:"required"`
End
int
`json:"end" binding:"required"`
Daily
bool
`json:"daily" binding:"required"`
Status
string
`json:"status"`
TaskId
int
`json:"taskId,omitempty"`
Platform
string
`json:"platform" binding:"required"`
Action
string
`json:"action" binding:"required"`
Url
string
`json:"url"`
TweetId
int
`json:"tweetId"`
Description
string
`json:"description" binding:"required"`
Reward
int
`json:"reward" binding:"required"`
Start
int
`json:"start" binding:"required"`
End
int
`json:"end" binding:"required"`
Daily
bool
`json:"daily" binding:"required"`
Status
string
`json:"status"`
TelegramActiveThreshold
int
`json:"telegramActiveThreshold"`
// 仅电报活跃可用
}
type
GetGroupResponse
CreateGroupRequest
...
...
model/db/taskcenter.go
View file @
6c179463
...
...
@@ -56,22 +56,23 @@ func (t *TaskGroup) TableName() string {
}
type
Task
struct
{
Id
int
`gorm:"primaryKey;autoIncrement:false"`
GroupId
int
`gorm:"type:int;index;not null;comment:任务组id"`
Platform
string
`gorm:"type:text;not null;comment:任务平台"`
Action
string
`gorm:"type:text;not null;comment:任务动作"`
Url
string
`gorm:"type:text;not null;comment:任务链接"`
TwitterUserId
int
`gorm:"type:int;not null;comment:tweet user id,用于关注"`
TwitterHandle
string
`gorm:"type:text;not null;comment:tweet handle,用于关注"`
TweetId
int
`gorm:"type:int;not null;comment:推文id,用于转发点赞"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram群id"`
TelegramChatUsername
string
`gorm:"type:text;not null;comment:telegram群用户名"`
Description
string
`gorm:"type:text;not null;comment:任务描述"`
Reward
int
`gorm:"type:int;not null;comment:任务奖励"`
Start
int
`gorm:"type:int;not null;comment:任务开始时间"`
End
int
`gorm:"type:int;index;not null;comment:任务结束时间"`
Daily
bool
`gorm:"type:bool;not null;comment:是否是每日任务"`
TwitterTaskEndAt
sql
.
NullTime
`gorm:"index;comment:推特可用,推特任务中心已停止"`
Id
int
`gorm:"primaryKey;autoIncrement:false"`
GroupId
int
`gorm:"type:int;index;not null;comment:任务组id"`
Platform
string
`gorm:"type:text;not null;comment:任务平台"`
Action
string
`gorm:"type:text;not null;comment:任务动作"`
Url
string
`gorm:"type:text;not null;comment:任务链接"`
TwitterUserId
int
`gorm:"type:int;not null;comment:tweet user id,用于关注"`
TwitterHandle
string
`gorm:"type:text;not null;comment:tweet handle,用于关注"`
TweetId
int
`gorm:"type:int;not null;comment:推文id,用于转发点赞"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram群id"`
TelegramChatUsername
string
`gorm:"type:text;not null;comment:telegram群用户名"`
Description
string
`gorm:"type:text;not null;comment:任务描述"`
Reward
int
`gorm:"type:int;not null;comment:任务奖励"`
Start
int
`gorm:"type:int;not null;comment:任务开始时间"`
End
int
`gorm:"type:int;index;not null;comment:任务结束时间"`
Daily
bool
`gorm:"type:bool;not null;comment:是否是每日任务"`
TwitterTaskEndAt
sql
.
NullTime
`gorm:"index;comment:推特可用,推特任务中心已停止"`
TelegramActiveThreshold
int
`gorm:"type:int;not null;comment:telegram群活跃阈值"`
gorm
.
Model
}
...
...
server/router.go
View file @
6c179463
...
...
@@ -19,10 +19,10 @@ func initRouter(e *gin.Engine) {
}
{
group
:=
v1
.
Group
(
"/group"
,
middleware
.
JWTMiddleware
(
conf
.
Supabase
.
JWTSecret
,
false
)
)
group
.
GET
(
"/:gid"
,
getGroup
)
// 获取任务组任务详情
group
.
GET
(
"/list"
,
listGroup
)
// 获取任务组任务详情
group
.
POST
(
"/create"
,
createGroup
)
// 创建任务组
group
:=
v1
.
Group
(
"/group"
)
group
.
GET
(
"/:gid"
,
getGroup
,
middleware
.
JWTMiddleware
(
conf
.
Supabase
.
JWTSecret
,
false
))
// 获取任务组任务详情
group
.
GET
(
"/list"
,
listGroup
,
middleware
.
JWTMiddleware
(
conf
.
Supabase
.
JWTSecret
,
true
)
)
// 获取任务组任务详情
group
.
POST
(
"/create"
,
createGroup
,
middleware
.
JWTMiddleware
(
conf
.
Supabase
.
JWTSecret
,
true
)
)
// 创建任务组
}
{
...
...
service/group.go
View file @
6c179463
...
...
@@ -75,6 +75,9 @@ func (s *Service) CreateGroup(req *apiModel.CreateGroupRequest) (gid int, err er
gt
.
TelegramChatId
=
project
.
TelegramChatId
gt
.
TelegramChatUsername
=
project
.
TelegramChatUsername
gt
.
Url
=
fmt
.
Sprintf
(
"https://t.me/%s"
,
project
.
TelegramChatUsername
)
if
task
.
Action
==
constant
.
TaskActionActive
{
gt
.
TelegramActiveThreshold
=
task
.
TelegramActiveThreshold
}
}
err
=
s
.
d
.
CreateGroupTask
(
gt
)
...
...
sync/task.go
View file @
6c179463
...
...
@@ -68,7 +68,9 @@ func (s *Sync) SyncTask(taskId int, userId string) (ok bool, err error) {
if
task
.
Action
==
constant
.
TaskActionJoin
{
taskDone
,
err
=
s
.
d
.
CheckTGJoin
(
telegramUserId
,
task
.
TelegramChatId
)
}
else
{
taskDone
,
err
=
s
.
d
.
CheckTGActive
(
telegramUserId
,
task
.
TelegramChatId
)
var
msgCount
int
msgCount
,
err
=
s
.
d
.
CheckTGActive
(
telegramUserId
,
task
.
TelegramChatId
)
taskDone
=
msgCount
>=
task
.
TelegramActiveThreshold
}
if
err
!=
nil
{
...
...
util/jwt.go
View file @
6c179463
...
...
@@ -6,7 +6,7 @@ import (
"github.com/golang-jwt/jwt/v5"
)
func
ParseJWT
(
secret
,
token
string
)
(
ok
,
expired
bool
,
uid
string
)
{
func
ParseJWT
(
secret
,
token
string
)
(
ok
,
expired
bool
,
uid
,
role
string
)
{
claims
:=
jwt
.
MapClaims
{}
tk
,
err
:=
jwt
.
ParseWithClaims
(
token
,
claims
,
func
(
t
*
jwt
.
Token
)
(
interface
{},
error
)
{
return
[]
byte
(
secret
),
nil
...
...
@@ -29,6 +29,8 @@ func ParseJWT(secret, token string) (ok, expired bool, uid string) {
// return
}
role
=
claims
[
"role"
]
.
(
string
)
uid
=
claims
[
"sub"
]
.
(
string
)
if
uid
==
""
{
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment