mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-11-04 03:52:24 -06:00 
			
		
		
		
	
		
			
				
	
	
		
			63 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package fileserver
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
 | 
						|
	"github.com/sirupsen/logrus"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/apimodule"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/config"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/db"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/router"
 | 
						|
	"github.com/superseriousbusiness/gotosocial/internal/storage"
 | 
						|
)
 | 
						|
 | 
						|
// 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 {
 | 
						|
	config      *config.Config
 | 
						|
	db          db.DB
 | 
						|
	storage     storage.Storage
 | 
						|
	log         *logrus.Logger
 | 
						|
	storageBase string
 | 
						|
}
 | 
						|
 | 
						|
// New returns a new fileServer module
 | 
						|
func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.Logger) apimodule.ClientAPIModule {
 | 
						|
 | 
						|
	storageBase := config.StorageConfig.BasePath // TODO: do this properly
 | 
						|
 | 
						|
	return &fileServer{
 | 
						|
		config:      config,
 | 
						|
		db:          db,
 | 
						|
		storage:     storage,
 | 
						|
		log:         log,
 | 
						|
		storageBase: storageBase,
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// Route satisfies the RESTAPIModule interface
 | 
						|
func (m *fileServer) Route(s router.Router) error {
 | 
						|
	// s.AttachHandler(http.MethodPost, appsPath, m.appsPOSTHandler)
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (m *fileServer) CreateTables(db db.DB) error {
 | 
						|
	models := []interface{}{
 | 
						|
		>smodel.User{},
 | 
						|
		>smodel.Account{},
 | 
						|
		>smodel.Follow{},
 | 
						|
		>smodel.FollowRequest{},
 | 
						|
		>smodel.Status{},
 | 
						|
		>smodel.Application{},
 | 
						|
		>smodel.EmailDomainBlock{},
 | 
						|
		>smodel.MediaAttachment{},
 | 
						|
	}
 | 
						|
 | 
						|
	for _, m := range models {
 | 
						|
		if err := db.CreateTable(m); err != nil {
 | 
						|
			return fmt.Errorf("error creating table: %s", err)
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 |