mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-13 09:26:23 -07:00
Re-add incoming-upload event trigger
This commit is contained in:
parent
9551c35f83
commit
9875b011df
2 changed files with 18 additions and 24 deletions
|
@ -3,6 +3,8 @@ package gcsql
|
|||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/gochan-org/gochan/pkg/events"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -51,7 +53,16 @@ func (p *Post) AttachFile(upload *Upload) error {
|
|||
if upload == nil {
|
||||
return nil // no upload to attach, so no error
|
||||
}
|
||||
const query = `INSERT INTO DBPREFIXfiles (
|
||||
|
||||
_, err, recovered := events.TriggerEvent("incoming-upload", upload)
|
||||
if recovered {
|
||||
return errors.New("recovered from a panic in an event handler (incoming-upload)")
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New("unable to attach upload to post: " + err.Error())
|
||||
}
|
||||
|
||||
const insertSQL = `INSERT INTO DBPREFIXfiles (
|
||||
post_id, file_order, original_filename, filename, checksum, file_size,
|
||||
is_spoilered, thumbnail_width, thumbnail_height, width, height)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?)`
|
||||
|
@ -64,7 +75,7 @@ func (p *Post) AttachFile(upload *Upload) error {
|
|||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
stmt, err := PrepareSQL(query, tx)
|
||||
stmt, err := PrepareSQL(insertSQL, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -325,33 +325,16 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
|
||||
upload, err := uploads.AttachUploadFromRequest(request, writer, post, postBoard, infoEv, errEv)
|
||||
documentRoot := config.GetSystemCriticalConfig().DocumentRoot
|
||||
var filePath, thumbPath, catalogThumbPath string
|
||||
if upload != nil {
|
||||
filePath = path.Join(documentRoot, postBoard.Dir, "src", upload.Filename)
|
||||
thumbPath, catalogThumbPath := uploads.GetThumbnailFilenames(
|
||||
path.Join(documentRoot, postBoard.Dir, "thumb", upload.Filename))
|
||||
if recovered {
|
||||
os.Remove(filePath)
|
||||
os.Remove(thumbPath)
|
||||
os.Remove(catalogThumbPath)
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Recovered from a panic in an event handler (incoming-upload)", wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("event", "incoming-upload").
|
||||
Send()
|
||||
server.ServeError(writer, "Unable to attach upload to post: "+err.Error(), wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
// got an error receiving the upload or the upload was rejected
|
||||
server.ServeError(writer, err.Error(), wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
documentRoot := config.GetSystemCriticalConfig().DocumentRoot
|
||||
filePath := path.Join(documentRoot, postBoard.Dir, "src", upload.Filename)
|
||||
thumbPath, catalogThumbPath := uploads.GetThumbnailFilenames(
|
||||
path.Join(documentRoot, postBoard.Dir, "thumb", upload.Filename))
|
||||
|
||||
filter, err := gcsql.DoPostFiltering(post, upload, boardID, request, errEv)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue