mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-22 08:37:29 -06:00
delete statuses
This commit is contained in:
parent
29c17cce12
commit
ddfb9aae65
20 changed files with 475 additions and 147 deletions
|
|
@ -32,17 +32,17 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
accountIDKey = "account_id"
|
||||
mediaTypeKey = "media_type"
|
||||
mediaSizeKey = "media_size"
|
||||
fileNameKey = "file_name"
|
||||
AccountIDKey = "account_id"
|
||||
MediaTypeKey = "media_type"
|
||||
MediaSizeKey = "media_size"
|
||||
FileNameKey = "file_name"
|
||||
|
||||
filesPath = "files"
|
||||
FilesPath = "files"
|
||||
)
|
||||
|
||||
// fileServer implements the RESTAPIModule interface.
|
||||
// FileServer implements the RESTAPIModule interface.
|
||||
// The goal here is to serve requested media files if the gotosocial server is configured to use local storage.
|
||||
type fileServer struct {
|
||||
type FileServer struct {
|
||||
config *config.Config
|
||||
db db.DB
|
||||
storage storage.Storage
|
||||
|
|
@ -52,7 +52,7 @@ type fileServer struct {
|
|||
|
||||
// New returns a new fileServer module
|
||||
func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.Logger) apimodule.ClientAPIModule {
|
||||
return &fileServer{
|
||||
return &FileServer{
|
||||
config: config,
|
||||
db: db,
|
||||
storage: storage,
|
||||
|
|
@ -62,12 +62,12 @@ func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.L
|
|||
}
|
||||
|
||||
// Route satisfies the RESTAPIModule interface
|
||||
func (m *fileServer) Route(s router.Router) error {
|
||||
s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageBase, accountIDKey, mediaTypeKey, mediaSizeKey, fileNameKey), m.ServeFile)
|
||||
func (m *FileServer) Route(s router.Router) error {
|
||||
s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageBase, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey), m.ServeFile)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *fileServer) CreateTables(db db.DB) error {
|
||||
func (m *FileServer) CreateTables(db db.DB) error {
|
||||
models := []interface{}{
|
||||
>smodel.MediaAttachment{},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import (
|
|||
//
|
||||
// Note: to mitigate scraping attempts, no information should be given out on a bad request except "404 page not found".
|
||||
// Don't give away account ids or media ids or anything like that; callers shouldn't be able to infer anything.
|
||||
func (m *fileServer) ServeFile(c *gin.Context) {
|
||||
func (m *FileServer) ServeFile(c *gin.Context) {
|
||||
l := m.log.WithFields(logrus.Fields{
|
||||
"func": "ServeFile",
|
||||
"request_uri": c.Request.RequestURI,
|
||||
|
|
@ -45,28 +45,28 @@ func (m *fileServer) ServeFile(c *gin.Context) {
|
|||
// We use request params to check what to pull out of the database/storage so check everything. A request URL should be formatted as follows:
|
||||
// "https://example.org/fileserver/[ACCOUNT_ID]/[MEDIA_TYPE]/[MEDIA_SIZE]/[FILE_NAME]"
|
||||
// "FILE_NAME" consists of two parts, the attachment's database id, a period, and the file extension.
|
||||
accountID := c.Param(accountIDKey)
|
||||
accountID := c.Param(AccountIDKey)
|
||||
if accountID == "" {
|
||||
l.Debug("missing accountID from request")
|
||||
c.String(http.StatusNotFound, "404 page not found")
|
||||
return
|
||||
}
|
||||
|
||||
mediaType := c.Param(mediaTypeKey)
|
||||
mediaType := c.Param(MediaTypeKey)
|
||||
if mediaType == "" {
|
||||
l.Debug("missing mediaType from request")
|
||||
c.String(http.StatusNotFound, "404 page not found")
|
||||
return
|
||||
}
|
||||
|
||||
mediaSize := c.Param(mediaSizeKey)
|
||||
mediaSize := c.Param(MediaSizeKey)
|
||||
if mediaSize == "" {
|
||||
l.Debug("missing mediaSize from request")
|
||||
c.String(http.StatusNotFound, "404 page not found")
|
||||
return
|
||||
}
|
||||
|
||||
fileName := c.Param(fileNameKey)
|
||||
fileName := c.Param(FileNameKey)
|
||||
if fileName == "" {
|
||||
l.Debug("missing fileName from request")
|
||||
c.String(http.StatusNotFound, "404 page not found")
|
||||
|
|
@ -86,7 +86,7 @@ func (m *fileServer) ServeFile(c *gin.Context) {
|
|||
c.String(http.StatusNotFound, "404 page not found")
|
||||
}
|
||||
|
||||
func (m *fileServer) serveAttachment(c *gin.Context, accountID string, mediaType string, mediaSize string, fileName string) {
|
||||
func (m *FileServer) serveAttachment(c *gin.Context, accountID string, mediaType string, mediaSize string, fileName string) {
|
||||
l := m.log.WithFields(logrus.Fields{
|
||||
"func": "serveAttachment",
|
||||
"request_uri": c.Request.RequestURI,
|
||||
|
|
@ -160,7 +160,7 @@ func (m *fileServer) serveAttachment(c *gin.Context, accountID string, mediaType
|
|||
c.DataFromReader(http.StatusOK, int64(contentLength), contentType, bytes.NewReader(attachmentBytes), map[string]string{})
|
||||
}
|
||||
|
||||
func (m *fileServer) serveEmoji(c *gin.Context, accountID string, mediaType string, mediaSize string, fileName string) {
|
||||
func (m *FileServer) serveEmoji(c *gin.Context, accountID string, mediaType string, mediaSize string, fileName string) {
|
||||
l := m.log.WithFields(logrus.Fields{
|
||||
"func": "serveEmoji",
|
||||
"request_uri": c.Request.RequestURI,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package fileserver
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/apimodule/fileserver"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
|
||||
|
|
@ -60,7 +61,7 @@ type ServeFileTestSuite struct {
|
|||
testAttachments map[string]*gtsmodel.MediaAttachment
|
||||
|
||||
// item being tested
|
||||
fileServer *fileServer
|
||||
fileServer *fileserver.FileServer
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -78,7 +79,7 @@ func (suite *ServeFileTestSuite) SetupSuite() {
|
|||
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
||||
|
||||
// setup module being tested
|
||||
suite.fileServer = New(suite.config, suite.db, suite.storage, suite.log).(*fileServer)
|
||||
suite.fileServer = fileserver.New(suite.config, suite.db, suite.storage, suite.log).(*fileserver.FileServer)
|
||||
}
|
||||
|
||||
func (suite *ServeFileTestSuite) TearDownSuite() {
|
||||
|
|
@ -89,7 +90,7 @@ func (suite *ServeFileTestSuite) TearDownSuite() {
|
|||
|
||||
func (suite *ServeFileTestSuite) SetupTest() {
|
||||
testrig.StandardDBSetup(suite.db)
|
||||
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
|
||||
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
|
||||
suite.testTokens = testrig.NewTestTokens()
|
||||
suite.testClients = testrig.NewTestClients()
|
||||
suite.testApplications = testrig.NewTestApplications()
|
||||
|
|
@ -120,19 +121,19 @@ func (suite *ServeFileTestSuite) TestServeOriginalFileSuccessful() {
|
|||
// but because we're calling the ServeFile function directly, we need to set them manually.
|
||||
ctx.Params = gin.Params{
|
||||
gin.Param{
|
||||
Key: accountIDKey,
|
||||
Key: fileserver.AccountIDKey,
|
||||
Value: targetAttachment.AccountID,
|
||||
},
|
||||
gin.Param{
|
||||
Key: mediaTypeKey,
|
||||
Key: fileserver.MediaTypeKey,
|
||||
Value: media.MediaAttachment,
|
||||
},
|
||||
gin.Param{
|
||||
Key: mediaSizeKey,
|
||||
Key: fileserver.MediaSizeKey,
|
||||
Value: media.MediaOriginal,
|
||||
},
|
||||
gin.Param{
|
||||
Key: fileNameKey,
|
||||
Key: fileserver.FileNameKey,
|
||||
Value: fmt.Sprintf("%s.jpeg", targetAttachment.ID),
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue