Skip to content

🎧 Your Personal Streaming Service

Add share's `contents` and `description` to the DB

Deluand9c42b318382
diff --git a/core/share.go b/core/share.go
index 736a15772..d3cb180b8 100644
--- a/core/share.go
+++ b/core/share.go
@@ -74,9 +74,11 @@ func (s *shareService) loadMediafiles(ctx context.Context, filter squirrel.Eq, s
func (s *shareService) NewRepository(ctx context.Context) rest.Repository {
repo := s.ds.Share(ctx)
wrapper := &shareRepositoryWrapper{
+ ctx: ctx,
ShareRepository: repo,
Repository: repo.(rest.Repository),
Persistable: repo.(rest.Persistable),
+ ds: s.ds,
}
return wrapper
}
@@ -85,6 +87,8 @@ type shareRepositoryWrapper struct {
model.ShareRepository
rest.Repository
rest.Persistable
+ ctx context.Context
+ ds model.DataStore
}
func (r *shareRepositoryWrapper) newId() (string, error) {
@@ -113,6 +117,9 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) {
if s.ExpiresAt.IsZero() {
s.ExpiresAt = time.Now().Add(365 * 24 * time.Hour)
}
+ if s.ResourceType == "album" {
+ s.Contents = r.shareContentsFromAlbums(s.ID, s.ResourceIDs)
+ }
id, err = r.Persistable.Save(s)
return id, err
}
@@ -120,3 +127,17 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) {
func (r *shareRepositoryWrapper) Update(id string, entity interface{}, _ ...string) error {
return r.Persistable.Update(id, entity, "description", "expires_at")
}
+
+func (r *shareRepositoryWrapper) shareContentsFromAlbums(shareID string, ids string) string {
+ all, err := r.ds.Album(r.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"id": ids}})
+ if err != nil {
+ log.Error(r.ctx, "Error retrieving album names for share", "share", shareID, err)
+ return ""
+ }
+ names := slice.Map(all, func(a model.Album) string { return a.Name })
+ content := strings.Join(names, ", ")
+ if len(content) > 30 {
+ content = content[:26] + "..."
+ }
+ return content
+}
diff --git a/ui/src/dialogs/ShareDialog.js b/ui/src/dialogs/ShareDialog.js
index edd95de52..77fb586f5 100644
--- a/ui/src/dialogs/ShareDialog.js
+++ b/ui/src/dialogs/ShareDialog.js
@@ -10,6 +10,7 @@ import {
import {
SelectInput,
SimpleForm,
+ TextInput,
useCreate,
useGetList,
useNotify,
@@ -24,6 +25,7 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
const [format, setFormat] = useState(config.defaultDownsamplingFormat)
const [maxBitRate, setMaxBitRate] = useState(DEFAULT_SHARE_BITRATE)
const [originalFormat, setUseOriginalFormat] = useState(true)
+ const [description, setDescription] = useState('')
const { data: formats, loading: loadingFormats } = useGetList(
'transcoding',
{
@@ -59,6 +61,7 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
{
resourceType: resource,
resourceIds: ids?.join(','),
+ description,
...(!originalFormat && { format }),
...(!originalFormat && { maxBitRate }),
},
@@ -105,6 +108,12 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
label={'Share in original format'}
onChange={handleOriginal}
/>
+ <TextInput
+ source="description"
+ onChange={(event) => {
+ setDescription(event.target.value)
+ }}
+ />
{!originalFormat && (
<SelectInput
source="format"
diff --git a/ui/src/share/ShareList.js b/ui/src/share/ShareList.js
index 716628b63..3d1efa667 100644
--- a/ui/src/share/ShareList.js
+++ b/ui/src/share/ShareList.js
@@ -44,7 +44,7 @@ const ShareList = (props) => {
/>
<TextField source="username" />
<TextField source="description" />
- <DateField source="contents" />
+ <TextField source="contents" />
<FormatInfo source="format" />
<NumberField source="visitCount" />
<DateField source="expiresAt" showTime />