0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-11-19 00:00:55 +01:00

mediaapi/writers/upload: Don't use deprecated sql.ErrNoRows check

This commit is contained in:
Robert Swain 2017-05-31 14:52:45 +02:00
parent f0c717b0a1
commit 5922ad383d

View file

@ -15,7 +15,6 @@
package writers
import (
"database/sql"
"fmt"
"io"
"net/http"
@ -127,18 +126,26 @@ func (r *uploadRequest) doUpload(reqReader io.Reader, cfg *config.MediaAPI, db *
r.MediaMetadata.Base64Hash = hash
r.MediaMetadata.MediaID = types.MediaID(hash)
r.Logger = r.Logger.WithField("MediaID", r.MediaMetadata.MediaID)
r.Logger.WithFields(log.Fields{
"MediaID": r.MediaMetadata.MediaID,
"Origin": r.MediaMetadata.Origin,
"Base64Hash": r.MediaMetadata.Base64Hash,
"UploadName": r.MediaMetadata.UploadName,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"Content-Type": r.MediaMetadata.ContentType,
"ContentType": r.MediaMetadata.ContentType,
}).Info("File uploaded")
// check if we already have a record of the media in our database and if so, we can remove the temporary directory
mediaMetadata, err := db.GetMediaMetadata(r.MediaMetadata.MediaID, r.MediaMetadata.Origin)
if err == nil {
if err != nil {
r.Logger.WithError(err).Error("Error querying the database.")
return &util.JSONResponse{
Code: 500,
JSON: jsonerror.InternalServerError(),
}
}
if mediaMetadata != nil {
r.MediaMetadata = mediaMetadata
fileutils.RemoveDir(tmpDir, r.Logger)
return &util.JSONResponse{
@ -147,8 +154,6 @@ func (r *uploadRequest) doUpload(reqReader io.Reader, cfg *config.MediaAPI, db *
ContentURI: fmt.Sprintf("mxc://%s/%s", cfg.ServerName, r.MediaMetadata.MediaID),
},
}
} else if err != sql.ErrNoRows {
r.Logger.WithError(err).WithField("MediaID", r.MediaMetadata.MediaID).Warn("Failed to query database")
}
// TODO: generate thumbnails