Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0a845ae6
authored
Dec 31, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: try to fix pgsql #682
parent
e0b73002
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
18 deletions
+2
-18
model/ability.go
+0
-8
model/channel.go
+0
-8
model/log.go
+1
-1
model/token.go
+1
-1
No files found.
model/ability.go
View file @
0a845ae6
...
@@ -23,10 +23,6 @@ type Ability struct {
...
@@ -23,10 +23,6 @@ type Ability struct {
func
GetGroupModels
(
group
string
)
[]
string
{
func
GetGroupModels
(
group
string
)
[]
string
{
var
models
[]
string
var
models
[]
string
// Find distinct models
// Find distinct models
groupCol
:=
"`group`"
if
common
.
UsingPostgreSQL
{
groupCol
=
`"group"`
}
DB
.
Table
(
"abilities"
)
.
Where
(
groupCol
+
" = ? and enabled = ?"
,
group
,
true
)
.
Distinct
(
"model"
)
.
Pluck
(
"model"
,
&
models
)
DB
.
Table
(
"abilities"
)
.
Where
(
groupCol
+
" = ? and enabled = ?"
,
group
,
true
)
.
Distinct
(
"model"
)
.
Pluck
(
"model"
,
&
models
)
return
models
return
models
}
}
...
@@ -45,10 +41,8 @@ func GetAllEnableAbilities() []Ability {
...
@@ -45,10 +41,8 @@ func GetAllEnableAbilities() []Ability {
}
}
func
getPriority
(
group
string
,
model
string
,
retry
int
)
(
int
,
error
)
{
func
getPriority
(
group
string
,
model
string
,
retry
int
)
(
int
,
error
)
{
groupCol
:=
"`group`"
trueVal
:=
"1"
trueVal
:=
"1"
if
common
.
UsingPostgreSQL
{
if
common
.
UsingPostgreSQL
{
groupCol
=
`"group"`
trueVal
=
"true"
trueVal
=
"true"
}
}
...
@@ -81,10 +75,8 @@ func getPriority(group string, model string, retry int) (int, error) {
...
@@ -81,10 +75,8 @@ func getPriority(group string, model string, retry int) (int, error) {
}
}
func
getChannelQuery
(
group
string
,
model
string
,
retry
int
)
*
gorm
.
DB
{
func
getChannelQuery
(
group
string
,
model
string
,
retry
int
)
*
gorm
.
DB
{
groupCol
:=
"`group`"
trueVal
:=
"1"
trueVal
:=
"1"
if
common
.
UsingPostgreSQL
{
if
common
.
UsingPostgreSQL
{
groupCol
=
`"group"`
trueVal
=
"true"
trueVal
=
"true"
}
}
maxPrioritySubQuery
:=
DB
.
Model
(
&
Ability
{})
.
Select
(
"MAX(priority)"
)
.
Where
(
groupCol
+
" = ? and model = ? and enabled = "
+
trueVal
,
group
,
model
)
maxPrioritySubQuery
:=
DB
.
Model
(
&
Ability
{})
.
Select
(
"MAX(priority)"
)
.
Where
(
groupCol
+
" = ? and model = ? and enabled = "
+
trueVal
,
group
,
model
)
...
...
model/channel.go
View file @
0a845ae6
...
@@ -114,15 +114,11 @@ func GetChannelsByTag(tag string, idSort bool) ([]*Channel, error) {
...
@@ -114,15 +114,11 @@ func GetChannelsByTag(tag string, idSort bool) ([]*Channel, error) {
func
SearchChannels
(
keyword
string
,
group
string
,
model
string
,
idSort
bool
)
([]
*
Channel
,
error
)
{
func
SearchChannels
(
keyword
string
,
group
string
,
model
string
,
idSort
bool
)
([]
*
Channel
,
error
)
{
var
channels
[]
*
Channel
var
channels
[]
*
Channel
keyCol
:=
"`key`"
groupCol
:=
"`group`"
modelsCol
:=
"`models`"
modelsCol
:=
"`models`"
// 如果是 PostgreSQL,使用双引号
// 如果是 PostgreSQL,使用双引号
if
common
.
UsingPostgreSQL
{
if
common
.
UsingPostgreSQL
{
keyCol
=
`"key"`
keyCol
=
`"key"`
groupCol
=
`"group"`
modelsCol
=
`"models"`
}
}
order
:=
"priority desc"
order
:=
"priority desc"
...
@@ -437,14 +433,10 @@ func GetPaginatedTags(offset int, limit int) ([]*string, error) {
...
@@ -437,14 +433,10 @@ func GetPaginatedTags(offset int, limit int) ([]*string, error) {
func
SearchTags
(
keyword
string
,
group
string
,
model
string
,
idSort
bool
)
([]
*
string
,
error
)
{
func
SearchTags
(
keyword
string
,
group
string
,
model
string
,
idSort
bool
)
([]
*
string
,
error
)
{
var
tags
[]
*
string
var
tags
[]
*
string
keyCol
:=
"`key`"
groupCol
:=
"`group`"
modelsCol
:=
"`models`"
modelsCol
:=
"`models`"
// 如果是 PostgreSQL,使用双引号
// 如果是 PostgreSQL,使用双引号
if
common
.
UsingPostgreSQL
{
if
common
.
UsingPostgreSQL
{
keyCol
=
`"key"`
groupCol
=
`"group"`
modelsCol
=
`"models"`
modelsCol
=
`"models"`
}
}
...
...
model/log.go
View file @
0a845ae6
...
@@ -56,7 +56,7 @@ func formatUserLogs(logs []*Log) {
...
@@ -56,7 +56,7 @@ func formatUserLogs(logs []*Log) {
func
GetLogByKey
(
key
string
)
(
logs
[]
*
Log
,
err
error
)
{
func
GetLogByKey
(
key
string
)
(
logs
[]
*
Log
,
err
error
)
{
if
os
.
Getenv
(
"LOG_SQL_DSN"
)
!=
""
{
if
os
.
Getenv
(
"LOG_SQL_DSN"
)
!=
""
{
var
tk
Token
var
tk
Token
if
err
=
DB
.
Model
(
&
Token
{})
.
Where
(
"`key`
=?"
,
strings
.
TrimPrefix
(
key
,
"sk-"
))
.
First
(
&
tk
)
.
Error
;
err
!=
nil
{
if
err
=
DB
.
Model
(
&
Token
{})
.
Where
(
keyCol
+
"
=?"
,
strings
.
TrimPrefix
(
key
,
"sk-"
))
.
First
(
&
tk
)
.
Error
;
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
err
=
LOG_DB
.
Model
(
&
Log
{})
.
Where
(
"token_id=?"
,
tk
.
Id
)
.
Find
(
&
logs
)
.
Error
err
=
LOG_DB
.
Model
(
&
Log
{})
.
Where
(
"token_id=?"
,
tk
.
Id
)
.
Find
(
&
logs
)
.
Error
...
...
model/token.go
View file @
0a845ae6
...
@@ -68,7 +68,7 @@ func SearchUserTokens(userId int, keyword string, token string) (tokens []*Token
...
@@ -68,7 +68,7 @@ func SearchUserTokens(userId int, keyword string, token string) (tokens []*Token
if
token
!=
""
{
if
token
!=
""
{
token
=
strings
.
Trim
(
token
,
"sk-"
)
token
=
strings
.
Trim
(
token
,
"sk-"
)
}
}
err
=
DB
.
Where
(
"user_id = ?"
,
userId
)
.
Where
(
"name LIKE ?"
,
"%"
+
keyword
+
"%"
)
.
Where
(
"`key`
LIKE ?"
,
"%"
+
token
+
"%"
)
.
Find
(
&
tokens
)
.
Error
err
=
DB
.
Where
(
"user_id = ?"
,
userId
)
.
Where
(
"name LIKE ?"
,
"%"
+
keyword
+
"%"
)
.
Where
(
keyCol
+
"
LIKE ?"
,
"%"
+
token
+
"%"
)
.
Find
(
&
tokens
)
.
Error
return
tokens
,
err
return
tokens
,
err
}
}
...
...
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