mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-05 11:06:23 -07:00
Make post info use a struct for safer typing, add staff-specific options JSON
This commit is contained in:
parent
0795a0a8a8
commit
c5e44eb915
5 changed files with 52 additions and 14 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
"github.com/gochan-org/gochan/pkg/gctemplates"
|
||||
"github.com/gochan-org/gochan/pkg/gcutil"
|
||||
"github.com/gochan-org/gochan/pkg/posting/uploads"
|
||||
"github.com/gochan-org/gochan/pkg/server/serverutil"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
@ -110,6 +111,22 @@ func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return manageRecentsBuffer.String(), nil
|
||||
}
|
||||
|
||||
type staffOptionsJSON struct {
|
||||
FingerprintVideoThumbs bool `json:"fingerprintVideoThumbs"`
|
||||
ImageExtensions []string `json:"imageExtensions,omitempty"`
|
||||
VideoExtensions []string `json:"videoExtensions,omitempty"`
|
||||
}
|
||||
|
||||
func staffOptionsCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
staffOptions := staffOptionsJSON{}
|
||||
if staff.Rank > JanitorPerms {
|
||||
staffOptions.FingerprintVideoThumbs = config.GetSiteConfig().FingerprintVideoThumbnails
|
||||
staffOptions.ImageExtensions = uploads.ImageExtensions
|
||||
staffOptions.VideoExtensions = uploads.VideoExtensions
|
||||
}
|
||||
return staffOptions, nil
|
||||
}
|
||||
|
||||
func announcementsCallback(_ http.ResponseWriter, _ *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
// return an array of announcements (with staff name instead of ID) and any errors
|
||||
return getAllAnnouncements()
|
||||
|
@ -252,5 +269,12 @@ func registerJanitorPages() {
|
|||
JSONoutput: OptionalJSON,
|
||||
Callback: staffCallback,
|
||||
},
|
||||
Action{
|
||||
ID: "staffoptions",
|
||||
Title: "Staff-specific options",
|
||||
Permissions: JanitorPerms,
|
||||
JSONoutput: AlwaysJSON,
|
||||
Callback: staffOptionsCallback,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -626,6 +626,15 @@ func threadAttrsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
return attrBuffer.String(), nil
|
||||
}
|
||||
|
||||
type postInfoJSON struct {
|
||||
Post *gcsql.Post `json:"post"`
|
||||
IP string `json:"ip"`
|
||||
FQDN []string `json:"ipFQDN"`
|
||||
|
||||
OriginalFilename string `json:"originalFilename,omitempty"`
|
||||
Checksum string `json:"checksum,omitempty"`
|
||||
}
|
||||
|
||||
func postInfoCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
|
||||
postIDstr := request.FormValue("postid")
|
||||
if postIDstr == "" {
|
||||
|
@ -640,23 +649,23 @@ func postInfoCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Sta
|
|||
return "", err
|
||||
}
|
||||
|
||||
postInfo := map[string]interface{}{
|
||||
"post": post,
|
||||
"ip": post.IP,
|
||||
postInfo := postInfoJSON{
|
||||
Post: post,
|
||||
IP: post.IP,
|
||||
}
|
||||
names, err := net.LookupAddr(post.IP)
|
||||
if err == nil {
|
||||
postInfo["ipFQDN"] = names
|
||||
postInfo.FQDN = names
|
||||
} else {
|
||||
postInfo["ipFQDN"] = []string{err.Error()}
|
||||
postInfo.FQDN = []string{err.Error()}
|
||||
}
|
||||
upload, err := post.GetUpload()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if upload != nil {
|
||||
postInfo["originalFilename"] = upload.OriginalFilename
|
||||
postInfo["checksum"] = upload.Checksum
|
||||
postInfo.OriginalFilename = upload.OriginalFilename
|
||||
postInfo.Checksum = upload.Checksum
|
||||
}
|
||||
return postInfo, nil
|
||||
}
|
||||
|
|
|
@ -115,7 +115,12 @@ func CallManageFunction(writer http.ResponseWriter, request *http.Request) {
|
|||
Msg("Recovered from panic while calling manage function")
|
||||
}
|
||||
}()
|
||||
output, err = action.Callback(writer, request, staff, wantsJSON, infoEv, errEv)
|
||||
if action.Callback == nil {
|
||||
output = ""
|
||||
err = fmt.Errorf("action %q exists but has no defined callback", action.ID)
|
||||
} else {
|
||||
output, err = action.Callback(writer, request, staff, wantsJSON, infoEv, errEv)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
|
@ -24,10 +24,10 @@ import (
|
|||
|
||||
var (
|
||||
uploadHandlers map[string]UploadHandler
|
||||
imageExtensions = []string{
|
||||
ImageExtensions = []string{
|
||||
".bmp", ".gif", ".jpg", ".jpeg", ".png", ".webp",
|
||||
}
|
||||
videoExtensions = []string{
|
||||
VideoExtensions = []string{
|
||||
".mp4", ".webm",
|
||||
}
|
||||
)
|
||||
|
@ -41,10 +41,10 @@ func RegisterUploadHandler(ext string, handler UploadHandler) {
|
|||
|
||||
func init() {
|
||||
uploadHandlers = make(map[string]UploadHandler)
|
||||
for _, ext := range imageExtensions {
|
||||
for _, ext := range ImageExtensions {
|
||||
uploadHandlers[ext] = processImage
|
||||
}
|
||||
for _, ext := range videoExtensions {
|
||||
for _, ext := range VideoExtensions {
|
||||
uploadHandlers[ext] = processVideo
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,13 +61,13 @@ func fingerprintFile(filePath string, board string) (*gcsql.FileBan, error) {
|
|||
func canFingerprint(filename string) bool {
|
||||
siteCfg := config.GetSiteConfig()
|
||||
ext := path.Ext(filename)
|
||||
for _, iExt := range imageExtensions {
|
||||
for _, iExt := range ImageExtensions {
|
||||
if iExt == ext {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if siteCfg.FingerprintVideoThumbnails {
|
||||
for _, vExt := range videoExtensions {
|
||||
for _, vExt := range VideoExtensions {
|
||||
if vExt == ext {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue