diff --git a/future-useful-libs.md b/future-useful-libs.md new file mode 100644 index 0000000..2869049 --- /dev/null +++ b/future-useful-libs.md @@ -0,0 +1,6 @@ +- golang.org/x/net/html + - Parsing and manipulating html +- https://github.com/chasefleming/elem-go + - Generating html +- mime + - working with mime types diff --git a/go.mod b/go.mod index 887ecde..537442f 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,14 @@ toolchain go1.23.0 require ( github.com/BurntSushi/toml v1.4.0 - github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 + github.com/dgraph-io/ristretto v0.1.1 github.com/eko/gocache/lib/v4 v4.1.6 - github.com/eko/gocache/store/memcache/v4 v4.2.2 + github.com/eko/gocache/store/redis/v4 v4.2.2 + github.com/eko/gocache/store/ristretto/v4 v4.2.2 github.com/glebarez/sqlite v1.11.0 github.com/go-webauthn/webauthn v0.11.2 github.com/mstarongithub/passkey v0.0.0-20240817142622-de6912c8303e + github.com/redis/go-redis/v9 v9.0.2 github.com/rs/zerolog v1.33.0 gitlab.com/mstarongitlab/goutils v1.3.0 gorm.io/driver/postgres v1.5.7 @@ -21,10 +23,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/eko/gocache/store/redis/v4 v4.2.2 // indirect - github.com/eko/gocache/store/ristretto/v4 v4.2.2 // indirect github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -36,7 +35,6 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect - github.com/redis/go-redis/v9 v9.0.2 // indirect golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect golang.org/x/sync v0.8.0 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index ef84456..4bdcc70 100644 --- a/go.sum +++ b/go.sum @@ -44,11 +44,12 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 h1:wAIE/kN63Oig1DdOzN7O+k4AbFh2cCJoKMFXrwRJtzk= -github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= +github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ= +github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= +github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8= +github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -66,6 +67,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= @@ -74,8 +76,6 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/eko/gocache/lib/v4 v4.1.6 h1:5WWIGISKhE7mfkyF+SJyWwqa4Dp2mkdX8QsZpnENqJI= github.com/eko/gocache/lib/v4 v4.1.6/go.mod h1:HFxC8IiG2WeRotg09xEnPD72sCheJiTSr4Li5Ameg7g= -github.com/eko/gocache/store/memcache/v4 v4.2.2 h1:VKfxytQ5bkcfF3LhmgkrqRiEU2yCN2/rJBUvF1fKZJw= -github.com/eko/gocache/store/memcache/v4 v4.2.2/go.mod h1:9lFU3tZPiej8E3J4ueZ0K9kIdiDQpRxu6WhtId5OsZA= github.com/eko/gocache/store/redis/v4 v4.2.2 h1:Thw31fzGuH3WzJywsdbMivOmP550D6JS7GDHhvCJPA0= github.com/eko/gocache/store/redis/v4 v4.2.2/go.mod h1:LaTxLKx9TG/YUEybQvPMij++D7PBTIJ4+pzvk0ykz0w= github.com/eko/gocache/store/ristretto/v4 v4.2.2 h1:lXFzoZ5ck6Gy6ON7f5DHSkNt122qN7KoroCVgVwF7oo= diff --git a/storage/mediaFile.go b/storage/mediaFile.go index a37e1e2..5725aac 100644 --- a/storage/mediaFile.go +++ b/storage/mediaFile.go @@ -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 +} diff --git a/storage/mediaProvider/mediaProvider.go b/storage/mediaProvider/mediaProvider.go new file mode 100644 index 0000000..a2026c8 --- /dev/null +++ b/storage/mediaProvider/mediaProvider.go @@ -0,0 +1 @@ +package mediaprovider diff --git a/storage/storage.go b/storage/storage.go index 92ce234..d609588 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -1,3 +1,8 @@ +// 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 (