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

This commit is contained in:
Deluan 2023-01-21 22:04:40 -05:00
parent 364fdfbd8d
commit d9c42b3183
3 changed files with 31 additions and 1 deletions

View File

@ -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
}

View File

@ -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"

View File

@ -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 />