Merge branch 'main' of gitlab.com:mstarongitlab/linstrom

This commit is contained in:
Melody Becker 2024-09-15 12:25:45 +02:00
commit 71beed7eb3
86 changed files with 34935 additions and 155 deletions

View file

@ -42,7 +42,9 @@ func (p *EncoderPool) Encode(raw any) ([]byte, error) {
defer encoder.Unlock()
// Clear the buffer to avoid funky output from previous operations
encoder.Buffer.Reset()
encoder.Encoder.Encode(raw)
if err := encoder.Encoder.Encode(raw); err != nil {
return nil, err
}
data, err := io.ReadAll(encoder.Buffer)
if err != nil {
return nil, err

6
storage/housekeeping.go Normal file
View file

@ -0,0 +1,6 @@
package storage
// Contains various functions for housekeeping
// Things like true deletion of soft deleted data after some time
// Or removing inactive access tokens
// All of this will be handled by goroutines

View file

@ -26,14 +26,52 @@ type MediaMetadata struct {
Name string
}
// TODO: Figure out how to actually manage media. Because this current idea sucks
// One idea would be to make another storage provider, but purely focused on handling the files
// and then using this section to store metadata about the files it knows
func (s *Storage) NewMediaMetadata(url, mediaType, name string) (*MediaMetadata, error) {
func (s *Storage) NewMediaMetadata(location, mediaType, name string) (*MediaMetadata, error) {
newMedia := MediaMetadata{
Location: url,
Location: location,
Name: name,
Type: mediaType,
}
s.db.Create(&newMedia)
return nil, nil
}
func (s *Storage) FuzzyFindMediaMetadataByName(name string) ([]MediaMetadata, error) {
notes := []MediaMetadata{}
err := s.db.Where("name LIKE %?%", name).Find(notes).Error
if err != nil {
return nil, err
}
return notes, nil
}
func (s *Storage) GetMediaMetadataById(id string) (*MediaMetadata, error) {
media := MediaMetadata{ID: id}
err := s.db.First(&media).Error
if err != nil {
return nil, err
}
return &media, nil
}
func (s *Storage) FuzzyFindMediaMetadataByLocation(location string) ([]MediaMetadata, error) {
data := []MediaMetadata{}
if err := s.db.Where("location LIKE %?%", location).Find(data).Error; err != nil {
return nil, err
}
return data, nil
}
func (s *Storage) DeleteMediaMetadataById(id string) error {
return s.db.Delete(MediaMetadata{ID: id}).Error
}
func (s *Storage) DeleteMediaMetadataByFuzzyLocation(location string) error {
var tmp MediaMetadata
return s.db.Where("location LIKE %?%", location).Delete(&tmp).Error
}
func (s *Storage) DeleteMediaMetadataByFuzzyName(name string) error {
var tmp MediaMetadata
return s.db.Where("name LIKE %?%", name).Delete(&tmp).Error
}

View file

@ -0,0 +1,3 @@
package mediaprovider
// TODO: Implement me

View file

@ -121,3 +121,13 @@ func (s *Storage) DeleteNote(id string) {
s.cache.Delete(cacheNoteIdToNotePrefix + id)
s.db.Delete(Note{ID: id})
}
// Try and find a note with a given ID
func (store *Storage) FindNoteById(id string) (*Note, error) {
note := Note{}
res := store.db.First(&note, id)
if res.Error != nil {
return nil, res.Error
}
return &note, nil
}

View file

@ -1,5 +1,7 @@
package storage
// TODO: More helper stuff
func (s *Storage) NewRemoteUser(fullHandle string) (*Account, error) {
return nil, nil
}

View file

@ -5,4 +5,7 @@ type Role struct {
Name string
// If set, counts as all permissions being set and all restrictions being disabled
FullAdmin bool
// TODO: More control options
// Extend upon whatever Masto, Akkoma and Misskey have
// Lots of details please
}

View file

@ -1,7 +1,13 @@
// TODO: Unify function names
// Storage is the handler for cache and db access
// It handles storing various data in the database as well as caching that data
// Said data includes notes, accounts, metadata about media files, servers and similar
package storage
import (
"errors"
"fmt"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/storage/cache"
@ -41,3 +47,8 @@ func NewStorage(dbUrl string, cache *cache.Cache) (*Storage, error) {
return &Storage{db, cache}, nil
}
// TODO: Placeholder. Update to proper implementation later. Including signature
func (s *Storage) FindLocalAccount(handle string) (string, error) {
return handle, nil
}

View file

@ -13,3 +13,5 @@ type UserInfoField struct {
Value string
LastUrlCheckDate *time.Time // Used if the value is an url to somewhere. Empty if value is not an url
}
// TODO: Add functions to store, load, update and delete these

View file

@ -0,0 +1,34 @@
package storage
type AccountRestriction int64
const (
// Account has no restrictions applied
ACCOUNT_RESTRICTION_NONE = AccountRestriction(0)
// All messages of the account get a content warning applied if none is set
// Warning could be something like "Message auto-CWd by server"
ACCOUNT_RESTRICTION_AUTO_CW = AccountRestriction(1 << iota)
// Disable accessing the account via login or access token
ACCOUNT_RESTRICTION_DISABLE_LOGIN
// Disable sending activities to other servers if the account is local
// Or reject all activities if the account is remote
ACCOUNT_RESTRICTION_NO_FEDERATION
// Disallow sending direct messages from that account
ACCOUNT_RESTRICTION_NO_DMS
// Disallow sending follower only messages from that account
ACCOUNT_RESTRICTION_NO_FOLLOWER_POSTS
// Disable outbound follow requests (restricted account can't send follow requests)
ACCOUNT_RESTRICTION_DISABLE_OUTBOUND_FOLLOWS
// Disable inbound follow requests (all follow requests to that account are automatically rejected)
ACCOUNT_RESTRICTION_DISABLE_INBOUND_FOLLOWS
// Forces all posts by that account to be follower only
ACCOUNT_RESTRICTION_FORCE_FOLLOWERS_ONLY
// Disable all outbound activities of an account.
// Includes sending, updating or deleting own notes
// as well as boosting or reacting to any notes
ACCOUNT_RESTRICTION_DISABLE_ACTIVITIES
// Account can only be viewed while logged in or via verified requests to the AP endpoints
ACCOUNT_RESTRICTIONS_NO_PUBLIC_ACCESS
// Force tag all media the account posts as sensitive
ACCOUNT_RESTRICTIONS_FORCE_MEDIA_SENSITIVE
)