mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 23:26:23 -07:00
Fix recent post checking
This commit is contained in:
parent
30b5a84aab
commit
fd6ca5d38c
3 changed files with 112 additions and 75 deletions
|
@ -3,6 +3,7 @@ package building
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"html/template"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
@ -14,8 +15,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
postQueryBase = `SELECT DBPREFIXposts.id AS postid, thread_id AS threadid, name, tripcode, email, subject,
|
||||
postQueryBase = `SELECT DBPREFIXposts.id AS postid, thread_id AS threadid, ip, name, tripcode, email, subject, created_on, created_on as last_modified,
|
||||
(SELECT id FROM DBPREFIXposts WHERE thread_id = threadid AND is_top_post) AS parent_id,
|
||||
message, message_raw,
|
||||
(SELECT board_id FROM DBPREFIXthreads where id = threadid LIMIT 1) AS boardid,
|
||||
(SELECT dir FROM DBPREFIXboards WHERE id = boardid LIMIT 1) AS dir,
|
||||
coalesce(DBPREFIXfiles.original_filename,'') as original_filename,
|
||||
|
@ -31,27 +33,52 @@ const (
|
|||
)
|
||||
|
||||
type PostJSON struct {
|
||||
ID int `json:"no"`
|
||||
ParentID int `json:"resto"`
|
||||
BoardID int `json:"-"`
|
||||
BoardDir string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Trip string `json:"trip"`
|
||||
Email string `json:"email"`
|
||||
Subject string `json:"sub"`
|
||||
Message string `json:"com"`
|
||||
Filename string `json:"tim"`
|
||||
OriginalFilename string `json:"filename"`
|
||||
Checksum string `json:"md5"`
|
||||
Extension string `json:"extension"`
|
||||
Filesize int `json:"fsize"`
|
||||
Width int `json:"w"`
|
||||
Height int `json:"h"`
|
||||
ThumbnailWidth int `json:"tn_w"`
|
||||
ThumbnailHeight int `json:"tn_h"`
|
||||
Capcode string `json:"capcode"`
|
||||
Time string `json:"time"`
|
||||
LastModified string `json:"last_modified"`
|
||||
ID int `json:"no"`
|
||||
ParentID int `json:"resto"`
|
||||
BoardID int `json:"-"`
|
||||
BoardDir string `json:"-"`
|
||||
IP string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Tripcode string `json:"trip"`
|
||||
Email string `json:"email"`
|
||||
Subject string `json:"sub"`
|
||||
MessageRaw string `json:"com"`
|
||||
Message template.HTML `json:"-"`
|
||||
Filename string `json:"tim"`
|
||||
OriginalFilename string `json:"filename"`
|
||||
Checksum string `json:"md5"`
|
||||
Extension string `json:"extension"`
|
||||
Filesize int `json:"fsize"`
|
||||
Width int `json:"w"`
|
||||
Height int `json:"h"`
|
||||
ThumbnailWidth int `json:"tn_w"`
|
||||
ThumbnailHeight int `json:"tn_h"`
|
||||
Capcode string `json:"capcode"`
|
||||
Time string `json:"time"`
|
||||
LastModified string `json:"last_modified"`
|
||||
}
|
||||
|
||||
func (p *PostJSON) WebPath() string {
|
||||
threadID := p.ParentID
|
||||
if threadID == 0 {
|
||||
threadID = p.ID
|
||||
}
|
||||
return config.WebPath(p.BoardDir, "res", strconv.Itoa(threadID)+".html#"+strconv.Itoa(p.ID))
|
||||
}
|
||||
|
||||
func (p *PostJSON) ThumbnailPath() string {
|
||||
if p.Filename == "" {
|
||||
return ""
|
||||
}
|
||||
return config.WebPath(p.BoardDir, "thumb", gcutil.GetThumbnailPath("reply", p.Filename))
|
||||
}
|
||||
|
||||
func (p *PostJSON) UploadPath() string {
|
||||
if p.Filename == "" {
|
||||
return ""
|
||||
}
|
||||
return config.WebPath(p.BoardDir, "src", p.Filename)
|
||||
|
||||
}
|
||||
|
||||
func GetPostJSON(id int, boardid int) (*PostJSON, error) {
|
||||
|
@ -59,19 +86,28 @@ func GetPostJSON(id int, boardid int) (*PostJSON, error) {
|
|||
var post PostJSON
|
||||
var threadID int
|
||||
err := gcsql.QueryRowSQL(query, []interface{}{id}, []interface{}{
|
||||
&post.ID, &threadID, &post.Name, &post.Trip, &post.Email, &post.Subject,
|
||||
&post.ParentID, &post.BoardID, &post.BoardDir, &post.OriginalFilename, &post.Filename,
|
||||
&post.Checksum, &post.Filesize, &post.ThumbnailWidth, &post.ThumbnailHeight,
|
||||
&post.Width, &post.Height,
|
||||
&post.ID, &threadID, &post.IP, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.Time, &post.LastModified,
|
||||
&post.ParentID, &post.Message, &post.MessageRaw, &post.BoardID, &post.BoardDir,
|
||||
&post.OriginalFilename, &post.Filename, &post.Checksum, &post.Filesize,
|
||||
&post.ThumbnailWidth, &post.ThumbnailHeight, &post.Width, &post.Height,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
post.Extension = path.Ext(post.Filename)
|
||||
return &post, nil
|
||||
}
|
||||
|
||||
func GetRecentPosts(boardid int, limit int) ([]PostJSON, error) {
|
||||
rows, err := gcsql.QuerySQL(postQueryBase + " LIMIT " + strconv.Itoa(limit))
|
||||
query := "SELECT * FROM (" + postQueryBase + ") posts"
|
||||
var args []interface{} = []interface{}{}
|
||||
|
||||
if boardid > 0 {
|
||||
query += " WHERE boardid = ?"
|
||||
args = append(args, boardid)
|
||||
}
|
||||
|
||||
rows, err := gcsql.QuerySQL(query+" LIMIT "+strconv.Itoa(limit), args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -81,15 +117,16 @@ func GetRecentPosts(boardid int, limit int) ([]PostJSON, error) {
|
|||
var post PostJSON
|
||||
var threadID int
|
||||
err = rows.Scan(
|
||||
&post.ID, &threadID, &post.Name, &post.Trip, &post.Email, &post.Subject,
|
||||
&post.ParentID, &post.BoardID, &post.BoardDir, &post.OriginalFilename, &post.Filename,
|
||||
&post.Checksum, &post.Filesize, &post.ThumbnailWidth, &post.ThumbnailHeight,
|
||||
&post.Width, &post.Height,
|
||||
&post.ID, &threadID, &post.IP, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.Time, &post.LastModified,
|
||||
&post.ParentID, &post.Message, &post.MessageRaw, &post.BoardID, &post.BoardDir,
|
||||
&post.OriginalFilename, &post.Filename, &post.Checksum, &post.Filesize,
|
||||
&post.ThumbnailWidth, &post.ThumbnailHeight, &post.Width, &post.Height,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if boardid > 0 && post.BoardID == boardid {
|
||||
if boardid == 0 || post.BoardID == boardid {
|
||||
post.Extension = path.Ext(post.Filename)
|
||||
posts = append(posts, post)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,21 +171,38 @@ var actions = []Action{
|
|||
Permissions: JanitorPerms,
|
||||
JSONoutput: OptionalJSON,
|
||||
Callback: func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv, errEv *zerolog.Event) (output interface{}, err error) {
|
||||
limit, err := getIntField("limit", staff.Username, request, 0)
|
||||
limit := 20
|
||||
limitStr := request.FormValue("limit")
|
||||
if limitStr != "" {
|
||||
limit, err = strconv.Atoi(limitStr)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
boardidStr := request.FormValue("boardid")
|
||||
var recentposts []building.PostJSON
|
||||
var boardid int
|
||||
if boardidStr != "" {
|
||||
if boardid, err = strconv.Atoi(boardidStr); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
recentposts, err = building.GetRecentPosts(boardid, limit)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", err
|
||||
}
|
||||
boardid, err := getIntField("boardid", staff.Username, request, 0)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
recentposts, err := building.GetRecentPosts(boardid, limit)
|
||||
if err != nil {
|
||||
return "", err
|
||||
if wantsJSON {
|
||||
return recentposts, nil
|
||||
}
|
||||
manageRecentsBuffer := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageRecentPosts, map[string]interface{}{
|
||||
"recentposts": recentposts,
|
||||
"allBoards": gcsql.AllBoards,
|
||||
"boardid": boardid,
|
||||
"limit": limit,
|
||||
"webroot": config.GetSystemCriticalConfig().WebRoot,
|
||||
}, manageRecentsBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
|
@ -194,30 +211,6 @@ var actions = []Action{
|
|||
return manageRecentsBuffer.String(), nil
|
||||
},
|
||||
},
|
||||
// {
|
||||
// ID: "recentposts",
|
||||
// Title: "Recent posts",
|
||||
// Permissions: JanitorPerms,
|
||||
// JSONoutput: OptionalJSON,
|
||||
// Callback: func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool) (output interface{}, err error) {
|
||||
// limit := gcutil.HackyStringToInt(request.FormValue("limit"))
|
||||
// if limit == 0 {
|
||||
// limit = 50
|
||||
// }
|
||||
// recentposts, err := gcsql.GetRecentPostsGlobal(limit, false) //only uses boardname, boardid, postid, parentid, message, ip and timestamp
|
||||
// if wantsJSON || err != nil {
|
||||
// return recentposts, err
|
||||
// }
|
||||
// manageRecentsBuffer := bytes.NewBufferString("")
|
||||
// if err = serverutil.MinifyTemplate(gctemplates.ManageRecentPosts, map[string]interface{}{
|
||||
// "recentposts": recentposts,
|
||||
// "webroot": config.GetSystemCriticalConfig().WebRoot,
|
||||
// }, manageRecentsBuffer, "text/html"); err != nil {
|
||||
// errEv.Err(err).Caller().Send()
|
||||
// return "", errors.New("Error executing ban management page template: " + err.Error())
|
||||
// }
|
||||
// return manageRecentsBuffer.String(), nil
|
||||
// }},
|
||||
/* {
|
||||
ID: "filebans",
|
||||
Title: "File bans",
|
||||
|
|
|
@ -1,24 +1,31 @@
|
|||
<!-- Limit by: <select id="limitby">
|
||||
<option>25</option>
|
||||
<option>50</option>
|
||||
<option>100</option>
|
||||
<option>200</option>
|
||||
</select><br /><br /> -->
|
||||
<form action="{{$.webroot}}manage" method="GET">
|
||||
<input type="hidden" name="action" value="recentposts">
|
||||
<label for="boardid">Board:</label>
|
||||
<select name="boardid" id="boardid">
|
||||
<option value="0">All boards</option>
|
||||
{{- range $b, $board := $.allBoards -}}
|
||||
<option value="{{$board.ID}}" {{if eq $.boardid $board.ID}}selected{{end}}>/{{$board.Dir}}/ - {{$board.Title}}</option>
|
||||
{{- end -}}
|
||||
</select><br />
|
||||
<label for="limit">Limit:</label>
|
||||
<input type="number" name="limit" id="limit" value="20" min="1">
|
||||
<input type="submit" />
|
||||
</form><hr />
|
||||
<table width="100%" border="1">
|
||||
<colgroup><col width="5%"><col width="15%"><col width="60%"><col width="15%"></colgroup>
|
||||
<tr><th></th><th>Name</th><th>Message</th><th>Thumb</th></tr>
|
||||
{{range $rp, $post := $.recentposts}}
|
||||
<tr><td><a href="{{$post.BoardName}}/res/{{if eq $post.ParentID 0}}{{$post.ID}}{{else}}{{$post.ParentID}}{{end}}.html#{{$post.PostID}}" class="centered">Post</a></td>
|
||||
<tr><td><a href="{{$post.WebPath}}" class="centered">Post</a></td>
|
||||
<td><b>Name: </b> {{- if and (eq $post.Name "") (eq $post.Tripcode "")}}<span class="postername">Anonymous</span>{{end}}
|
||||
{{- if ne $post.Name ""}}<span class="postername">{{$post.Name}}</span>{{end -}}
|
||||
{{- if ne $post.Tripcode ""}}!<span class="tripcode">{{$post.Tripcode}}</span>{{end -}}<br />
|
||||
<b>IP: </b> {{$post.IP}}</td>
|
||||
<b>IP: </b> {{$post.IP}}<br />
|
||||
<b>Board: </b>/{{$post.BoardDir}}/
|
||||
</td>
|
||||
<td>{{truncateMessage (stripHTML $post.Message) 300 16}}</td><td>
|
||||
{{- if eq $post.Filename "deleted" -}}
|
||||
<div class="file-deleted-box centered" style="text-align:center;">File removed</div>
|
||||
{{- else if ne $post.Filename "" -}}
|
||||
{{- $thumbURL := stringAppend $.webroot $post.BoardName "/thumb/" (getThreadThumbnail $post.Filename) -}}
|
||||
{{- $uploadURL := stringAppend $.webroot $post.BoardName "/src/" $post.Filename -}}
|
||||
<a href="{{$uploadURL}}" target="_blank" class="centered"><img src="{{$thumbURL}}"></a>
|
||||
<a href="{{$post.UploadPath}}" target="_blank" class="centered"><img src="{{$post.ThumbnailPath}}"></a>
|
||||
{{end}}</td></tr>{{end}}
|
||||
</table>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue