parent
11897d0e1a
commit
47672c586d
@ -10,9 +10,12 @@ linters:
|
|||||||
- gocritic
|
- gocritic
|
||||||
# Complains about main() lengths, which isn't an issue.
|
# Complains about main() lengths, which isn't an issue.
|
||||||
- funlen
|
- funlen
|
||||||
|
# Magic numbers everywhere and we can't get rid of them.
|
||||||
|
- gomnd
|
||||||
linters-settings:
|
linters-settings:
|
||||||
lll:
|
lll:
|
||||||
line-length: 420
|
line-length: 420
|
||||||
|
gocognit:
|
||||||
|
min-complexity: 50
|
||||||
gocyclo:
|
gocyclo:
|
||||||
min-complexity: 40
|
min-complexity: 40
|
||||||
|
|
@ -232,7 +232,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
|
|||||||
func pastePasswordedVerifyPost(ec echo.Context) error {
|
func pastePasswordedVerifyPost(ec echo.Context) error {
|
||||||
// We should check if database connection available.
|
// We should check if database connection available.
|
||||||
dbConn := c.Database.GetDatabaseConnection()
|
dbConn := c.Database.GetDatabaseConnection()
|
||||||
// nolint
|
|
||||||
if c.Config.Database.Type != "flatfiles" && dbConn == nil {
|
if c.Config.Database.Type != "flatfiles" && dbConn == nil {
|
||||||
return ec.Redirect(http.StatusFound, "/database_not_available")
|
return ec.Redirect(http.StatusFound, "/database_not_available")
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,9 @@ func pastePOSTWebInterface(ec echo.Context) error {
|
|||||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
|
||||||
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != "forever" {
|
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != "forever" {
|
||||||
c.Logger.Debug().Str("field value", params["paste-keep-for"][0]).Msg("'Keep paste for' field have invalid value")
|
c.Logger.Debug().Str("field value", params["paste-keep-for"][0]).Msg("'Keep paste for' field have invalid value")
|
||||||
|
|
||||||
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||||
|
|
||||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
|
@ -96,8 +96,7 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
|
|||||||
c.Logger.Debug().Msgf("%+v", publicPastes)
|
c.Logger.Debug().Msgf("%+v", publicPastes)
|
||||||
|
|
||||||
// Iteration two - get paginated pastes.
|
// Iteration two - get paginated pastes.
|
||||||
// nolint
|
pastesData := make([]structs.Paste, 0)
|
||||||
var pastesData []structs.Paste
|
|
||||||
|
|
||||||
for idx, paste := range publicPastes {
|
for idx, paste := range publicPastes {
|
||||||
if len(pastesData) == c.Config.Pastes.Pagination {
|
if len(pastesData) == c.Config.Pastes.Pagination {
|
||||||
|
@ -30,8 +30,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func InitialUp(tx *sql.Tx) error {
|
func InitialUp(tx *sql.Tx) error {
|
||||||
// nolint
|
_, err := tx.Exec(`CREATE TABLE pastes (
|
||||||
_, err := tx.Exec("CREATE TABLE `pastes` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Paste ID', `title` text NOT NULL COMMENT 'Paste title', `data` longtext NOT NULL COMMENT 'Paste data', `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Paste creation timestamp', `keep_for` int(4) NOT NULL DEFAULT 1 COMMENT 'Keep for integer. 0 - forever.', `keep_for_unit_type` int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';")
|
id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Paste ID',
|
||||||
|
title text NOT NULL COMMENT 'Paste title',
|
||||||
|
data longtext NOT NULL COMMENT 'Paste data',
|
||||||
|
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Paste creation timestamp',
|
||||||
|
keep_for int(4) NOT NULL DEFAULT 1 COMMENT 'Keep for integer. 0 - forever.',
|
||||||
|
keep_for_unit_type int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.',
|
||||||
|
PRIMARY KEY (id), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CreateHTML creates pagination HTML based on passed parameters.
|
// CreateHTML creates pagination HTML based on passed parameters.
|
||||||
// nolint
|
|
||||||
func CreateHTML(currentPage int, pages int, linksBase string) string {
|
func CreateHTML(currentPage int, pages int, linksBase string) string {
|
||||||
// Load templates.
|
// Load templates.
|
||||||
paginationHTMLRaw, err := static.ReadFile("pagination.html")
|
paginationHTMLRaw, err := static.ReadFile("pagination.html")
|
||||||
@ -55,6 +54,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
|
|||||||
if i == currentPage {
|
if i == currentPage {
|
||||||
paginationItemRaw = string(paginationLinkCurrentRaw)
|
paginationItemRaw = string(paginationLinkCurrentRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationItem := strings.Replace(paginationItemRaw, "{pageNum}", strconv.Itoa(i), -1)
|
paginationItem := strings.Replace(paginationItemRaw, "{pageNum}", strconv.Itoa(i), -1)
|
||||||
paginationItem = strings.Replace(paginationItem, "{paginationLink}", linksBase+strconv.Itoa(i), 1)
|
paginationItem = strings.Replace(paginationItem, "{paginationLink}", linksBase+strconv.Itoa(i), 1)
|
||||||
paginationString += paginationItem
|
paginationString += paginationItem
|
||||||
@ -77,7 +77,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
|
|||||||
paginationString += paginationItem
|
paginationString += paginationItem
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
pagination := strings.Replace(string(paginationHTMLRaw), "{paginationLinks}", paginationString, 1)
|
pagination := strings.Replace(string(paginationHTMLRaw), "{paginationLinks}", paginationString, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user