mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-30 09:56:23 -07:00
Refactor, replace use of interface{} with any, fix register_handler args not being usd
This commit is contained in:
parent
5bc47e003d
commit
d5ac9bff11
27 changed files with 103 additions and 103 deletions
|
@ -70,7 +70,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
"systemCritical": config.GetSystemCriticalConfig(),
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
|
@ -101,7 +101,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
errEv.Err(err).Caller().
|
||||
Str("postid", postIDstr).
|
||||
Msg("Invalid form data")
|
||||
server.ServeError(writer, "Invalid form data: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Invalid form data: "+err.Error(), wantsJSON, map[string]any{
|
||||
"postid": postid,
|
||||
})
|
||||
return
|
||||
|
@ -110,7 +110,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
post, err := gcsql.GetPostFromID(postid, true)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Unable to find post")
|
||||
server.ServeError(writer, "Unable to find post", wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Unable to find post", wantsJSON, map[string]any{
|
||||
"postid": postid,
|
||||
})
|
||||
return
|
||||
|
@ -135,7 +135,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
|
||||
board, err := gcsql.GetBoardFromID(boardid)
|
||||
if err != nil {
|
||||
server.ServeError(writer, "Invalid form data: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Invalid form data: "+err.Error(), wantsJSON, map[string]any{
|
||||
"boardid": boardid,
|
||||
})
|
||||
errEv.Err(err).Caller().Msg("Invalid form data")
|
||||
|
@ -184,7 +184,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
Str("newFilename", upload.Filename).
|
||||
Str("newOriginalFilename", upload.OriginalFilename).
|
||||
Send()
|
||||
server.ServeError(writer, "Error attaching new upload: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Error attaching new upload: "+err.Error(), wantsJSON, map[string]any{
|
||||
"filename": upload.OriginalFilename,
|
||||
})
|
||||
filePath = path.Join(documentRoot, board.Dir, "src", upload.Filename)
|
||||
|
@ -201,7 +201,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
_, err, recovered = events.TriggerEvent("message-pre-format", post, request)
|
||||
if recovered {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Recovered from a panic in an event handler (message-pre-format)", wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Recovered from a panic in an event handler (message-pre-format)", wantsJSON, map[string]any{
|
||||
"postid": post.ID,
|
||||
})
|
||||
return
|
||||
|
@ -210,7 +210,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
errEv.Err(err).Caller().
|
||||
Str("triggeredEvent", "message-pre-format").
|
||||
Send()
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]any{
|
||||
"postid": post.ID,
|
||||
})
|
||||
return
|
||||
|
@ -259,7 +259,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Msg("Unable to edit post")
|
||||
server.ServeError(writer, "Unable to edit post: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Unable to edit post: "+err.Error(), wantsJSON, map[string]any{
|
||||
"postid": post.ID,
|
||||
})
|
||||
return
|
||||
|
|
|
@ -78,7 +78,7 @@ func main() {
|
|||
gcutil.LogFatal().Err(err).Msg("Failed to initialize the database")
|
||||
}
|
||||
events.TriggerEvent("db-initialized")
|
||||
events.RegisterEvent([]string{"db-views-reset"}, func(trigger string, i ...interface{}) error {
|
||||
events.RegisterEvent([]string{"db-views-reset"}, func(trigger string, i ...any) error {
|
||||
gcutil.LogInfo().Msg("SQL views reset")
|
||||
return nil
|
||||
})
|
||||
|
|
|
@ -59,7 +59,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
return
|
||||
}
|
||||
if !post.IsTopPost {
|
||||
server.ServeError(writer, "You appear to be trying to move a post that is not the top post in the thread", wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "You appear to be trying to move a post that is not the top post in the thread", wantsJSON, map[string]any{
|
||||
"postid": checkedPosts[0],
|
||||
})
|
||||
return
|
||||
|
@ -69,7 +69,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("srcBoardIDstr", request.PostFormValue("boardid")).Send()
|
||||
server.ServeError(writer, fmt.Sprintf("Invalid or missing boarid: %q", request.PostFormValue("boardid")), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, fmt.Sprintf("Invalid or missing boarid: %q", request.PostFormValue("boardid")), wantsJSON, map[string]any{
|
||||
"boardid": srcBoardID,
|
||||
})
|
||||
return
|
||||
|
@ -85,7 +85,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
}
|
||||
gcutil.LogStr("srcBoard", srcBoard.Dir, errEv, infoEv)
|
||||
buf := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.MoveThreadPage, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.MoveThreadPage, map[string]any{
|
||||
"boardConfig": config.GetBoardConfig(srcBoard.Dir),
|
||||
"postid": post.ID,
|
||||
"destBoards": destBoards,
|
||||
|
@ -106,7 +106,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Str("postIDstr", postIDstr).Send()
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing postid value: %q: %s", postIDstr, err.Error()), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing postid value: %q: %s", postIDstr, err.Error()), wantsJSON, map[string]any{
|
||||
"postid": postIDstr,
|
||||
})
|
||||
return
|
||||
|
@ -119,7 +119,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Str("srcBoardIDstr", srcBoardIDstr).Send()
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing srcboardid value: %q: %s", srcBoardIDstr, err.Error()), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing srcboardid value: %q: %s", srcBoardIDstr, err.Error()), wantsJSON, map[string]any{
|
||||
"srcboardid": srcBoardIDstr,
|
||||
})
|
||||
return
|
||||
|
@ -129,7 +129,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Int("srcBoardID", srcBoardID).Send()
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]any{
|
||||
"srcboardid": srcBoardID,
|
||||
})
|
||||
return
|
||||
|
@ -142,7 +142,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Str("destBoardIDstr", destBoardIDstr).Send()
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing destboardid value: %q: %s", destBoardIDstr, err.Error()), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, fmt.Sprintf("Error parsing destboardid value: %q: %s", destBoardIDstr, err.Error()), wantsJSON, map[string]any{
|
||||
"destboardid": destBoardIDstr,
|
||||
})
|
||||
return
|
||||
|
@ -153,7 +153,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Int("destBoardID", destBoardID).Send()
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]any{
|
||||
"destboardid": destBoardID,
|
||||
})
|
||||
return
|
||||
|
@ -164,7 +164,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]any{
|
||||
"postid": postID,
|
||||
})
|
||||
return
|
||||
|
@ -178,7 +178,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
|
||||
if err = post.ChangeBoardID(destBoardID); err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed changing thread board ID")
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]any{
|
||||
"postID": postID,
|
||||
"destBoardID": destBoardID,
|
||||
})
|
||||
|
@ -189,7 +189,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Unable to get upload info")
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Error getting list of files in thread", wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Error getting list of files in thread", wantsJSON, map[string]any{
|
||||
"postid": post.ID,
|
||||
})
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
if err != nil {
|
||||
// got at least one error while trying to move files (if there were any)
|
||||
server.ServeError(writer, "Error while moving post upload: "+err.Error(), wantsJSON,
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"postID": postID,
|
||||
"srcBoard": srcBoard.Dir,
|
||||
"destBoard": destBoard.Dir,
|
||||
|
@ -258,7 +258,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Msg("Failed deleting thread page")
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Failed deleting thread page: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Failed deleting thread page: "+err.Error(), wantsJSON, map[string]any{
|
||||
"postID": postID,
|
||||
"srcBoard": srcBoard.Dir,
|
||||
})
|
||||
|
@ -269,7 +269,7 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
errEv.Err(err).Caller().
|
||||
Msg("Failed deleting thread JSON file")
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Failed deleting thread JSON file: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Failed deleting thread JSON file: "+err.Error(), wantsJSON, map[string]any{
|
||||
"postID": postID,
|
||||
"srcBoard": srcBoard.Dir,
|
||||
})
|
||||
|
@ -278,27 +278,27 @@ func moveThread(checkedPosts []int, moveBtn string, doMove string, writer http.R
|
|||
|
||||
if err = building.BuildThreadPages(post); err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Failed building thread page: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Failed building thread page: "+err.Error(), wantsJSON, map[string]any{
|
||||
"postid": postID,
|
||||
})
|
||||
return
|
||||
}
|
||||
if err = building.BuildBoardPages(srcBoard, errEv); err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Failed building board page: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Failed building board page: "+err.Error(), wantsJSON, map[string]any{
|
||||
"srcBoardID": srcBoardID,
|
||||
})
|
||||
return
|
||||
}
|
||||
if err = building.BuildBoardPages(destBoard, errEv); err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Failed building destination board page: "+err.Error(), wantsJSON, map[string]interface{}{
|
||||
server.ServeError(writer, "Failed building destination board page: "+err.Error(), wantsJSON, map[string]any{
|
||||
"destBoardID": destBoardID,
|
||||
})
|
||||
return
|
||||
}
|
||||
if wantsJSON {
|
||||
server.ServeJSON(writer, map[string]interface{}{
|
||||
server.ServeJSON(writer, map[string]any{
|
||||
"status": "success",
|
||||
"postID": postID,
|
||||
"srcBoard": srcBoard.Dir,
|
||||
|
|
|
@ -169,7 +169,7 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
// Render board page template to the file,
|
||||
// packaging the board/section list, threads, and board info
|
||||
captchaCfg := config.GetSiteConfig().Captcha
|
||||
if err = serverutil.MinifyTemplate(gctemplates.BoardPage, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.BoardPage, map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
"sections": gcsql.AllSections,
|
||||
"threads": threads,
|
||||
|
@ -243,7 +243,7 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
if (numThreads % boardConfig.ThreadsPerPage) > 0 {
|
||||
numPages++
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
"sections": gcsql.AllSections,
|
||||
"threads": page.Threads,
|
||||
|
|
|
@ -104,7 +104,7 @@ func BuildFrontPage() error {
|
|||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("failed loading recent posts: %w", err)
|
||||
}
|
||||
if err = serverutil.MinifyTemplate(gctemplates.FrontPage, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.FrontPage, map[string]any{
|
||||
"siteConfig": siteCfg,
|
||||
"sections": gcsql.AllSections,
|
||||
"boards": gcsql.AllBoards,
|
||||
|
@ -119,8 +119,8 @@ func BuildFrontPage() error {
|
|||
|
||||
// BuildPageHeader is a convenience function for automatically generating the top part
|
||||
// of every normal HTML page
|
||||
func BuildPageHeader(writer io.Writer, pageTitle string, board string, misc map[string]interface{}) error {
|
||||
phMap := map[string]interface{}{
|
||||
func BuildPageHeader(writer io.Writer, pageTitle string, board string, misc map[string]any) error {
|
||||
phMap := map[string]any{
|
||||
"pageTitle": pageTitle,
|
||||
"documentTitle": pageTitle + " - " + config.GetSiteConfig().SiteName,
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
|
|
|
@ -113,7 +113,7 @@ func BuildCatalog(boardID int) error {
|
|||
}
|
||||
boardConfig := config.GetBoardConfig(board.Dir)
|
||||
|
||||
if err = serverutil.MinifyTemplate(gctemplates.Catalog, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.Catalog, map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
"board": board,
|
||||
"boardConfig": boardConfig,
|
||||
|
|
|
@ -95,7 +95,7 @@ func BuildThreadPages(op *gcsql.Post) error {
|
|||
|
||||
// render thread page
|
||||
captchaCfg := config.GetSiteConfig().Captcha
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ThreadPage, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ThreadPage, map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
"board": board,
|
||||
"boardConfig": config.GetBoardConfig(board.Dir),
|
||||
|
|
|
@ -13,18 +13,18 @@ var (
|
|||
InvalidArgumentErrorStr = "invalid argument(s) passed to event %q"
|
||||
)
|
||||
|
||||
type EventHandler func(string, ...interface{}) error
|
||||
type EventHandler func(string, ...any) error
|
||||
|
||||
// RegisterEvent registers a new event handler to be called when any of the elements of triggers are passed
|
||||
// to TriggerEvent
|
||||
func RegisterEvent(triggers []string, handler func(trigger string, i ...interface{}) error) {
|
||||
func RegisterEvent(triggers []string, handler func(trigger string, i ...any) error) {
|
||||
for _, t := range triggers {
|
||||
registeredEvents[t] = append(registeredEvents[t], handler)
|
||||
}
|
||||
}
|
||||
|
||||
// TriggerEvent triggers the event handler registered to trigger
|
||||
func TriggerEvent(trigger string, data ...interface{}) (handled bool, err error, recovered bool) {
|
||||
func TriggerEvent(trigger string, data ...any) (handled bool, err error, recovered bool) {
|
||||
errEv := gcutil.LogError(nil).Caller(1)
|
||||
defer func() {
|
||||
if a := recover(); a != nil {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPanicRecover(t *testing.T) {
|
||||
RegisterEvent([]string{"TestPanicRecoverEvt"}, func(tr string, i ...interface{}) error {
|
||||
RegisterEvent([]string{"TestPanicRecoverEvt"}, func(tr string, i ...any) error {
|
||||
t.Log("Testing panic recover")
|
||||
t.Log(i[0])
|
||||
return nil
|
||||
|
@ -21,7 +21,7 @@ func TestPanicRecover(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEventEditValue(t *testing.T) {
|
||||
RegisterEvent([]string{"TestEventEditValue"}, func(tr string, i ...interface{}) error {
|
||||
RegisterEvent([]string{"TestEventEditValue"}, func(tr string, i ...any) error {
|
||||
p := i[0].(*int)
|
||||
*p += 1
|
||||
return nil
|
||||
|
@ -35,7 +35,7 @@ func TestEventEditValue(t *testing.T) {
|
|||
|
||||
func TestMultipleEventTriggers(t *testing.T) {
|
||||
triggered := map[string]bool{}
|
||||
RegisterEvent([]string{"a", "b"}, func(tr string, i ...interface{}) error {
|
||||
RegisterEvent([]string{"a", "b"}, func(tr string, i ...any) error {
|
||||
triggered[tr] = true
|
||||
return nil
|
||||
})
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func luaEventRegisterHandlerAdapter(l *lua.LState, fn *lua.LFunction) EventHandler {
|
||||
return func(trigger string, data ...interface{}) error {
|
||||
return func(trigger string, data ...any) error {
|
||||
args := []lua.LValue{
|
||||
luar.New(l, trigger),
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func PreloadModule(l *lua.LState) int {
|
|||
"register_event": func(l *lua.LState) int {
|
||||
table := l.CheckTable(-2)
|
||||
var triggers []string
|
||||
table.ForEach(func(i, val lua.LValue) {
|
||||
table.ForEach(func(_, val lua.LValue) {
|
||||
triggers = append(triggers, val.String())
|
||||
})
|
||||
fn := l.CheckFunction(-1)
|
||||
|
@ -45,7 +45,7 @@ func PreloadModule(l *lua.LState) int {
|
|||
"trigger_event": func(l *lua.LState) int {
|
||||
trigger := l.CheckString(1)
|
||||
numArgs := l.GetTop()
|
||||
var data []interface{}
|
||||
var data []any
|
||||
for i := 2; i <= numArgs; i++ {
|
||||
v := l.CheckAny(i)
|
||||
data = append(data, luautil.LValueToInterface(l, v))
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func LValueToInterface(l *lua.LState, v lua.LValue) interface{} {
|
||||
func LValueToInterface(l *lua.LState, v lua.LValue) any {
|
||||
lt := v.Type()
|
||||
switch lt {
|
||||
case lua.LTNil:
|
||||
|
|
|
@ -339,7 +339,7 @@ func (board *Board) DeleteOldThreads() ([]int, error) {
|
|||
rows.Close()
|
||||
}()
|
||||
|
||||
var threadIDs []interface{}
|
||||
var threadIDs []any
|
||||
var id int
|
||||
var threadsProccessed int
|
||||
for rows.Next() {
|
||||
|
|
|
@ -119,7 +119,7 @@ func sectionBoardsTmplFunc(sectionID int) []gcsql.Board {
|
|||
}
|
||||
|
||||
func init() {
|
||||
events.RegisterEvent([]string{"reset-boards-sections"}, func(_ string, _ ...interface{}) error {
|
||||
events.RegisterEvent([]string{"reset-boards-sections"}, func(_ string, _ ...any) error {
|
||||
return gcsql.ResetBoardSectionArrays()
|
||||
})
|
||||
gctemplates.AddTemplateFuncs(template.FuncMap{
|
||||
|
|
|
@ -86,7 +86,7 @@ func CheckPostReports(postID int, reason string) (bool, bool, error) {
|
|||
sql := `SELECT COUNT(*), MAX(is_cleared) FROM DBPREFIXreports
|
||||
WHERE post_id = ? AND (reason = ? OR is_cleared = 2)`
|
||||
var num int
|
||||
var isCleared interface{}
|
||||
var isCleared any
|
||||
err := QueryRowTimeoutSQL(nil, sql, []any{postID, reason}, []any{&num, &isCleared})
|
||||
isClearedInt, _ := isCleared.(int64)
|
||||
return num > 0, isClearedInt == 2, err
|
||||
|
@ -111,7 +111,7 @@ func GetReports(includeCleared bool) ([]Report, error) {
|
|||
var reports []Report
|
||||
for rows.Next() {
|
||||
var report Report
|
||||
var staffID interface{}
|
||||
var staffID any
|
||||
err = rows.Scan(&report.ID, &staffID, &report.PostID, &report.IP, &report.Reason, &report.IsCleared)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -131,7 +131,7 @@ func HackyStringToInt(text string) int {
|
|||
}
|
||||
|
||||
// MarshalJSON creates a JSON string with the given data and returns the string and any errors
|
||||
func MarshalJSON(data interface{}, indent bool) (string, error) {
|
||||
func MarshalJSON(data any, indent bool) (string, error) {
|
||||
var jsonBytes []byte
|
||||
var err error
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ const (
|
|||
AlwaysJSON
|
||||
)
|
||||
|
||||
type CallbackFunction func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error)
|
||||
type CallbackFunction func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error)
|
||||
|
||||
// Action represents the functions accessed by staff members at /manage/<functionname>.
|
||||
type Action struct {
|
||||
|
@ -105,7 +105,7 @@ func getPageTitle(actionID string, staff *gcsql.Staff) string {
|
|||
return useAction.Title
|
||||
}
|
||||
|
||||
func getStaffActions(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (interface{}, error) {
|
||||
func getStaffActions(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (any, error) {
|
||||
availableActions := getAvailableActions(staff.Rank, false)
|
||||
return availableActions, nil
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ type uploadInfo struct {
|
|||
|
||||
// manage actions that require admin-level permission go here
|
||||
|
||||
func updateAnnouncementsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (interface{}, error) {
|
||||
func updateAnnouncementsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (any, error) {
|
||||
announcements, err := getAllAnnouncements()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Unable to get staff announcements")
|
||||
|
@ -122,7 +122,7 @@ func updateAnnouncementsCallback(_ http.ResponseWriter, request *http.Request, s
|
|||
return pageBuffer.String(), err
|
||||
}
|
||||
|
||||
func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
board := &gcsql.Board{
|
||||
MaxFilesize: 1000 * 1000 * 15,
|
||||
AnonymousName: "Anonymous",
|
||||
|
@ -212,7 +212,7 @@ func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.S
|
|||
}
|
||||
pageBuffer := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageBoards,
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
"sections": gcsql.AllSections,
|
||||
"boards": gcsql.AllBoards,
|
||||
|
@ -227,7 +227,7 @@ func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.S
|
|||
return pageBuffer.String(), nil
|
||||
}
|
||||
|
||||
func boardSectionsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func boardSectionsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
section := &gcsql.Section{}
|
||||
editID := request.Form.Get("edit")
|
||||
updateID := request.Form.Get("updatesection")
|
||||
|
@ -308,7 +308,7 @@ func boardSectionsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsq
|
|||
return "", err
|
||||
}
|
||||
pageBuffer := bytes.NewBufferString("")
|
||||
pageMap := map[string]interface{}{
|
||||
pageMap := map[string]any{
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
"sections": sections,
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ func boardSectionsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsq
|
|||
return
|
||||
}
|
||||
|
||||
func cleanupCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func cleanupCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
outputStr := ""
|
||||
if request.FormValue("run") == "Run Cleanup" {
|
||||
outputStr += "Removing deleted posts from the database.<hr />"
|
||||
|
@ -352,7 +352,7 @@ func cleanupCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staf
|
|||
return outputStr, nil
|
||||
}
|
||||
|
||||
func fixThumbnailsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func fixThumbnailsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output any, err error) {
|
||||
board := request.FormValue("board")
|
||||
var uploads []uploadInfo
|
||||
if board != "" {
|
||||
|
@ -388,7 +388,7 @@ func fixThumbnailsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsq
|
|||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
func templatesCallback(writer http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, infoEv, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func templatesCallback(writer http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, infoEv, errEv *zerolog.Event) (output any, err error) {
|
||||
buf := bytes.NewBufferString("")
|
||||
|
||||
selectedTemplate := request.FormValue("override")
|
||||
|
@ -513,7 +513,7 @@ func templatesCallback(writer http.ResponseWriter, request *http.Request, _ *gcs
|
|||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func rebuildFrontCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
func rebuildFrontCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, _ *zerolog.Event) (output any, err error) {
|
||||
if err = gctemplates.InitTemplates(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ func rebuildFrontCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff
|
|||
return "Built front page successfully", err
|
||||
}
|
||||
|
||||
func rebuildAllCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func rebuildAllCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
gctemplates.InitTemplates()
|
||||
if err = gcsql.ResetBoardSectionArrays(); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
|
@ -581,7 +581,7 @@ func rebuildAllCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff,
|
|||
return buildStr, nil
|
||||
}
|
||||
|
||||
func rebuildBoardsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func rebuildBoardsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
if err = gctemplates.InitTemplates(); err != nil {
|
||||
errEv.Err(err).Caller().Msg("Unable to initialize templates")
|
||||
return "", err
|
||||
|
@ -592,7 +592,7 @@ func rebuildBoardsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staf
|
|||
return "", err
|
||||
}
|
||||
if wantsJSON {
|
||||
return map[string]interface{}{
|
||||
return map[string]any{
|
||||
"success": true,
|
||||
"message": "Boards built successfully",
|
||||
}, nil
|
||||
|
@ -600,7 +600,7 @@ func rebuildBoardsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staf
|
|||
return "Boards built successfully", nil
|
||||
}
|
||||
|
||||
func reparseHTMLCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func reparseHTMLCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
var outputStr string
|
||||
tx, err := gcsql.BeginTx()
|
||||
if err != nil {
|
||||
|
@ -662,7 +662,7 @@ func reparseHTMLCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff,
|
|||
}
|
||||
|
||||
func viewLogCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event,
|
||||
errEv *zerolog.Event) (output interface{}, err error) {
|
||||
errEv *zerolog.Event) (output any, err error) {
|
||||
logPath := path.Join(config.GetSystemCriticalConfig().LogDir, "gochan.log")
|
||||
logBytes, err := os.ReadFile(logPath)
|
||||
if err != nil {
|
||||
|
@ -670,7 +670,7 @@ func viewLogCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ b
|
|||
return "", errors.New("unable to open log file")
|
||||
}
|
||||
buf := bytes.NewBufferString("")
|
||||
err = serverutil.MinifyTemplate(gctemplates.ManageViewLog, map[string]interface{}{
|
||||
err = serverutil.MinifyTemplate(gctemplates.ManageViewLog, map[string]any{
|
||||
"logText": string(logBytes),
|
||||
}, buf, "text/html")
|
||||
return buf.String(), err
|
||||
|
|
|
@ -23,7 +23,7 @@ var (
|
|||
|
||||
// manage actions that require at least janitor-level permission go here
|
||||
|
||||
func logoutCallback(writer http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
func logoutCallback(writer http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output any, err error) {
|
||||
if err = gcsql.EndStaffSession(writer, request); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func logoutCallback(writer http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return "Logged out successfully", nil
|
||||
}
|
||||
|
||||
func clearMySessionsCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
func clearMySessionsCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, _ *zerolog.Event) (output any, err error) {
|
||||
session, err := request.Cookie("sessiondata")
|
||||
if err != nil {
|
||||
// doesn't have a login session cookie, return with no errors
|
||||
|
@ -74,7 +74,7 @@ func clearMySessionsCallback(writer http.ResponseWriter, request *http.Request,
|
|||
return "Logged out successfully", nil
|
||||
}
|
||||
|
||||
func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, wantsJSON bool, _, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, wantsJSON bool, _, errEv *zerolog.Event) (output any, err error) {
|
||||
limit := 20
|
||||
limitStr := request.FormValue("limit")
|
||||
if limitStr != "" {
|
||||
|
@ -102,7 +102,7 @@ func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return recentposts, nil
|
||||
}
|
||||
manageRecentsBuffer := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageRecentPosts, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageRecentPosts, map[string]any{
|
||||
"recentposts": recentposts,
|
||||
"allBoards": gcsql.AllBoards,
|
||||
"boardid": boardid,
|
||||
|
@ -114,12 +114,12 @@ func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return manageRecentsBuffer.String(), nil
|
||||
}
|
||||
|
||||
func announcementsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
func announcementsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output any, err error) {
|
||||
// return an array of announcements (with staff name instead of ID) and any errors
|
||||
return getAllAnnouncements()
|
||||
}
|
||||
|
||||
func staffCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func staffCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
do := request.FormValue("do")
|
||||
allStaff, err := getAllStaffNopass(true)
|
||||
if wantsJSON {
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
// manage actions that require moderator-level permission go here
|
||||
|
||||
func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
var outputStr string
|
||||
var ban gcsql.IPBan
|
||||
ban.StaffID = staff.ID
|
||||
|
@ -108,7 +108,7 @@ func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Sta
|
|||
}
|
||||
manageBansBuffer := bytes.NewBufferString("")
|
||||
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageBans, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageBans, map[string]any{
|
||||
"banlist": banlist,
|
||||
"allBoards": gcsql.AllBoards,
|
||||
"ban": ban,
|
||||
|
@ -121,7 +121,7 @@ func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Sta
|
|||
return outputStr, nil
|
||||
}
|
||||
|
||||
func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv, errEv *zerolog.Event) (output any, err error) {
|
||||
banIDstr := request.FormValue("banid")
|
||||
var banID int
|
||||
if banIDstr != "" {
|
||||
|
@ -165,7 +165,7 @@ func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
return appeals, nil
|
||||
}
|
||||
manageAppealsBuffer := bytes.NewBufferString("")
|
||||
pageData := map[string]interface{}{}
|
||||
pageData := map[string]any{}
|
||||
if len(appeals) > 0 {
|
||||
pageData["appeals"] = appeals
|
||||
}
|
||||
|
@ -349,10 +349,10 @@ func filtersCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func ipSearchCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func ipSearchCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
ipQuery := request.FormValue("ip")
|
||||
limitStr := request.FormValue("limit")
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"ipQuery": ipQuery,
|
||||
"limit": 20,
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ func ipSearchCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql
|
|||
return manageIpBuffer.String(), nil
|
||||
}
|
||||
|
||||
func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
dismissIDstr := request.FormValue("dismiss")
|
||||
if dismissIDstr != "" {
|
||||
// staff is dismissing a report
|
||||
|
@ -422,10 +422,10 @@ func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
reports := make([]map[string]interface{}, 0)
|
||||
reports := make([]map[string]any, 0)
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var staff_id interface{}
|
||||
var staff_id any
|
||||
var staff_user []byte
|
||||
var post_id int
|
||||
var ip string
|
||||
|
@ -442,7 +442,7 @@ func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
}
|
||||
|
||||
staff_id_int, _ := staff_id.(int64)
|
||||
reports = append(reports, map[string]interface{}{
|
||||
reports = append(reports, map[string]any{
|
||||
"id": id,
|
||||
"staff_id": int(staff_id_int),
|
||||
"staff_user": string(staff_user),
|
||||
|
@ -457,7 +457,7 @@ func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
}
|
||||
reportsBuffer := bytes.NewBufferString("")
|
||||
err = serverutil.MinifyTemplate(gctemplates.ManageReports,
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"reports": reports,
|
||||
"staff": staff,
|
||||
}, reportsBuffer, "text/html")
|
||||
|
@ -469,10 +469,10 @@ func reportsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
return
|
||||
}
|
||||
|
||||
func threadAttrsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, wantsJSON bool, infoEv, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func threadAttrsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, wantsJSON bool, infoEv, errEv *zerolog.Event) (output any, err error) {
|
||||
boardDir := request.FormValue("board")
|
||||
attrBuffer := bytes.NewBufferString("")
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"boards": gcsql.AllBoards,
|
||||
}
|
||||
if boardDir == "" {
|
||||
|
@ -572,7 +572,7 @@ func threadAttrsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return "", err
|
||||
}
|
||||
data["threads"] = threads
|
||||
var threadIDs []interface{}
|
||||
var threadIDs []any
|
||||
for i := len(threads) - 1; i >= 0; i-- {
|
||||
threadIDs = append(threadIDs, threads[i].ID)
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ type postInfoJSON struct {
|
|||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func postInfoCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func postInfoCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
postIDstr := request.FormValue("postid")
|
||||
if postIDstr == "" {
|
||||
return "", errors.New("invalid request (missing postid)")
|
||||
|
@ -670,7 +670,7 @@ type fingerprintJSON struct {
|
|||
Fingerprint string `json:"fingerprint"`
|
||||
}
|
||||
|
||||
func fingerprintCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func fingerprintCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
postIDstr := request.Form.Get("post")
|
||||
if postIDstr == "" {
|
||||
return "", errors.New("missing 'post' field")
|
||||
|
|
|
@ -19,7 +19,7 @@ const (
|
|||
loginTitle = "Login"
|
||||
)
|
||||
|
||||
func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output any, err error) {
|
||||
systemCritical := config.GetSystemCriticalConfig()
|
||||
if staff.Rank > 0 {
|
||||
http.Redirect(writer, request, path.Join(systemCritical.WebRoot, "manage"), http.StatusFound)
|
||||
|
@ -34,7 +34,7 @@ func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcs
|
|||
if username == "" || password == "" {
|
||||
//assume that they haven't logged in
|
||||
manageLoginBuffer := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageLogin, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageLogin, map[string]any{
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
"sections": gcsql.AllSections,
|
||||
"boards": gcsql.AllBoards,
|
||||
|
@ -64,7 +64,7 @@ type staffInfoJSON struct {
|
|||
Actions []Action `json:"actions,omitempty"`
|
||||
}
|
||||
|
||||
func staffInfoCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
func staffInfoCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output any, err error) {
|
||||
info := staffInfoJSON{
|
||||
Username: staff.Username,
|
||||
Rank: staff.Rank,
|
||||
|
|
|
@ -140,7 +140,7 @@ func PreloadModule(l *lua.LState) int {
|
|||
actionPerms := l.CheckInt(3)
|
||||
actionJSON := l.CheckInt(4)
|
||||
fn := l.CheckFunction(5)
|
||||
actionHandler := func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
actionHandler := func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error) {
|
||||
if err = l.CallByParam(lua.P{
|
||||
Fn: fn,
|
||||
NRet: 2,
|
||||
|
|
|
@ -131,7 +131,7 @@ func InitManagePages() {
|
|||
registerAdminPages()
|
||||
}
|
||||
|
||||
func dashboardCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (interface{}, error) {
|
||||
func dashboardCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, errEv *zerolog.Event) (any, error) {
|
||||
dashBuffer := bytes.NewBufferString("")
|
||||
announcements, err := getAllAnnouncements()
|
||||
if err != nil {
|
||||
|
@ -148,7 +148,7 @@ func dashboardCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staf
|
|||
}
|
||||
|
||||
availableActions := getAvailableActions(staff.Rank, true)
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageDashboard, map[string]interface{}{
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageDashboard, map[string]any{
|
||||
"actions": availableActions,
|
||||
"rank": staff.Rank,
|
||||
"rankString": rankString,
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
|
||||
func showBanpage(ban *gcsql.IPBan, post *gcsql.Post, postBoard *gcsql.Board, writer http.ResponseWriter, _ *http.Request) {
|
||||
banPageBuffer := bytes.NewBufferString("")
|
||||
err := serverutil.MinifyTemplate(gctemplates.BanPage, map[string]interface{}{
|
||||
err := serverutil.MinifyTemplate(gctemplates.BanPage, map[string]any{
|
||||
"systemCritical": config.GetSystemCriticalConfig(),
|
||||
"siteConfig": config.GetSiteConfig(),
|
||||
"boardConfig": config.GetBoardConfig(postBoard.Dir),
|
||||
|
|
|
@ -111,7 +111,7 @@ func ServeCaptcha(writer http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
fmt.Println("Success:", result)
|
||||
}
|
||||
err := serverutil.MinifyTemplate(gctemplates.Captcha, map[string]interface{}{
|
||||
err := serverutil.MinifyTemplate(gctemplates.Captcha, map[string]any{
|
||||
"boardConfig": config.GetBoardConfig(""),
|
||||
"boards": gcsql.AllBoards,
|
||||
"siteKey": captchaCfg.SiteKey,
|
||||
|
|
|
@ -21,7 +21,7 @@ func PreloadModule(l *lua.LState) int {
|
|||
Fn: handler,
|
||||
NRet: 1,
|
||||
// Protect: true,
|
||||
}, luar.New(l, upload), luar.New(l, post), lua.LString(board), lua.LString(filePath), lua.LString(thumbPath), lua.LString(catalogThumbPath))
|
||||
}, luar.New(l, upload), luar.New(l, post), lua.LString(board), lua.LString(filePath), lua.LString(thumbPath), lua.LString(catalogThumbPath), luar.New(l, infoEv), luar.New(l, accessEv), luar.New(l, errEv))
|
||||
|
||||
errRet := l.CheckAny(-1)
|
||||
if errRet != nil && errRet.Type() != lua.LTNil {
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestServeJSON(t *testing.T) {
|
|||
config.SetRandomSeed("test")
|
||||
|
||||
writer := httptest.NewRecorder()
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"status": "success",
|
||||
"postID": "777",
|
||||
"srcBoard": "srcBoard",
|
||||
|
@ -46,7 +46,7 @@ func TestServeJSON(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the response body
|
||||
var response map[string]interface{}
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(writer.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("failed to unmarshal response: %v", err)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func TestServeError(t *testing.T) {
|
|||
name string
|
||||
err string
|
||||
wantsJSON bool
|
||||
data map[string]interface{}
|
||||
data map[string]any
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ func TestServeError(t *testing.T) {
|
|||
name: "JSON response with existing data",
|
||||
err: "another error occurred",
|
||||
wantsJSON: true,
|
||||
data: map[string]interface{}{"info": "some info"},
|
||||
data: map[string]any{"info": "some info"},
|
||||
expected: `another error occurred`,
|
||||
},
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ func TestServeError(t *testing.T) {
|
|||
// Check the response
|
||||
if tt.wantsJSON {
|
||||
// Check if the response is JSON
|
||||
var responseMap map[string]interface{}
|
||||
var responseMap map[string]any
|
||||
if err := json.NewDecoder(rr.Body).Decode(&responseMap); err != nil {
|
||||
t.Fatalf("Failed to decode JSON response: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func PreloadModule(l *lua.LState) int {
|
|||
tmplUD := l.CheckUserData(1)
|
||||
tmpl := tmplUD.Value.(*template.Template)
|
||||
dataTable := l.CheckTable(2)
|
||||
data := map[string]interface{}{}
|
||||
data := map[string]any{}
|
||||
dataTable.ForEach(func(l1, l2 lua.LValue) {
|
||||
data[l1.String()] = luautil.LValueToInterface(l, l2)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue