Skip to content

Commit

Permalink
Add option to allow share to be downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Mar 11, 2023
1 parent a22eef3 commit a7d3e6e
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 7 deletions.
2 changes: 2 additions & 0 deletions conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type configOptions struct {
EnableStarRating bool
EnableUserEditing bool
EnableSharing bool
DefaultDownloadableShare bool
DefaultTheme string
DefaultLanguage string
DefaultUIVolume int
Expand Down Expand Up @@ -306,6 +307,7 @@ func init() {
viper.SetDefault("devautologinusername", "")
viper.SetDefault("devactivitypanel", true)
viper.SetDefault("enablesharing", false)
viper.SetDefault("defaultdownloadableshare", false)
viper.SetDefault("devenablebufferedscrobble", true)
viper.SetDefault("devsidebarplaylists", true)
viper.SetDefault("devshowartistpage", true)
Expand Down
2 changes: 1 addition & 1 deletion core/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) {
}

func (r *shareRepositoryWrapper) Update(id string, entity interface{}, _ ...string) error {
cols := []string{"description"}
cols := []string{"description", "downloadable"}

// TODO Better handling of Share expiration
if !entity.(*model.Share).ExpiresAt.IsZero() {
Expand Down
2 changes: 1 addition & 1 deletion core/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Share", func() {
entity := &model.Share{}
err := repo.Update("id", entity)
Expect(err).ToNot(HaveOccurred())
Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description"))
Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description", "downloadable"))
})
})
})
Expand Down
23 changes: 23 additions & 0 deletions db/migration/20230310222612_add_download_to_share.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package migrations

import (
"database/sql"

"github.com/pressly/goose"
)

func init() {
goose.AddMigration(upAddDownloadToShare, downAddDownloadToShare)
}

func upAddDownloadToShare(tx *sql.Tx) error {
_, err := tx.Exec(`
alter table share
add downloadable bool not null default false;
`)
return err
}

func downAddDownloadToShare(tx *sql.Tx) error {
return nil
}
1 change: 1 addition & 0 deletions model/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Share struct {
UserID string `structs:"user_id" json:"userId,omitempty" orm:"column(user_id)"`
Username string `structs:"-" json:"username,omitempty" orm:"-"`
Description string `structs:"description" json:"description,omitempty"`
Downloadable bool `structs:"downloadable" json:"downloadable"`
ExpiresAt time.Time `structs:"expires_at" json:"expiresAt,omitempty"`
LastVisitedAt time.Time `structs:"last_visited_at" json:"lastVisitedAt,omitempty"`
ResourceIDs string `structs:"resource_ids" json:"resourceIds,omitempty" orm:"column(resource_ids)"`
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"username": "Compartilhado por",
"url": "Link",
"description": "Descrição",
"downloadable": "Permitir Baixar?",
"contents": "Conteúdo",
"expiresAt": "Dt. Expiração",
"lastVisitedAt": "Última visita",
Expand Down Expand Up @@ -452,4 +453,4 @@
"current_song": "Vai para música atual"
}
}
}
}
1 change: 1 addition & 0 deletions server/serve_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func serveIndex(ds model.DataStore, fs fs.FS, shareInfo *model.Share) http.Handl
"devActivityPanel": conf.Server.DevActivityPanel,
"enableUserEditing": conf.Server.EnableUserEditing,
"enableSharing": conf.Server.EnableSharing,
"defaultDownloadableShare": conf.Server.DefaultDownloadableShare,
"devSidebarPlaylists": conf.Server.DevSidebarPlaylists,
"lastFMEnabled": conf.Server.LastFM.Enabled,
"lastFMApiKey": conf.Server.LastFM.ApiKey,
Expand Down
11 changes: 11 additions & 0 deletions server/serve_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ var _ = Describe("serveIndex", func() {
Expect(config).To(HaveKeyWithValue("enableSharing", false))
})

It("sets the defaultDownloadableShare", func() {
conf.Server.DefaultDownloadableShare = true
r := httptest.NewRequest("GET", "/index.html", nil)
w := httptest.NewRecorder()

serveIndex(ds, fs, nil)(w, r)

config := extractAppConfig(w.Body.String())
Expect(config).To(HaveKeyWithValue("defaultDownloadableShare", true))
})

It("sets the defaultDownsamplingFormat", func() {
r := httptest.NewRequest("GET", "/index.html", nil)
w := httptest.NewRecorder()
Expand Down
1 change: 1 addition & 0 deletions ui/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultConfig = {
defaultUIVolume: 100,
enableUserEditing: true,
enableSharing: true,
defaultDownloadableShare: true,
devSidebarPlaylists: true,
lastFMEnabled: true,
lastFMApiKey: '9b94a5515ea66b2da3ec03c12300327e',
Expand Down
17 changes: 16 additions & 1 deletion ui/src/dialogs/ShareDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
SimpleForm,
TextInput,
BooleanInput,
useCreate,
useNotify,
useTranslate,
Expand All @@ -17,6 +18,7 @@ import { shareUrl } from '../utils'
import { useTranscodingOptions } from './useTranscodingOptions'
import { useDispatch, useSelector } from 'react-redux'
import { closeShareMenu } from '../actions'
import config from '../config'

export const ShareDialog = () => {
const {
Expand All @@ -30,6 +32,9 @@ export const ShareDialog = () => {
const notify = useNotify()
const translate = useTranslate()
const [description, setDescription] = useState('')
const [downloadable, setDownloadable] = useState(
config.defaultDownloadableShare
)
useEffect(() => {
setDescription('')
}, [ids])
Expand All @@ -41,6 +46,7 @@ export const ShareDialog = () => {
resourceType: resource,
resourceIds: ids?.join(','),
description,
downloadable,
...(!originalFormat && { format }),
...(!originalFormat && { maxBitRate }),
},
Expand Down Expand Up @@ -105,12 +111,21 @@ export const ShareDialog = () => {
<DialogContent>
<SimpleForm toolbar={null} variant={'outlined'}>
<TextInput
source="description"
resource={'share'}
source={'description'}
fullWidth
onChange={(event) => {
setDescription(event.target.value)
}}
/>
<BooleanInput
resource={'share'}
source={'downloadable'}
defaultValue={downloadable}
onChange={(value) => {
setDownloadable(value)
}}
/>
<TranscodingOptionsInput
fullWidth
label={translate('message.shareOriginalFormat')}
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"username": "Shared By",
"url": "URL",
"description": "Description",
"downloadable": "Allow Downloads?",
"contents": "Contents",
"expiresAt": "Expires",
"lastVisitedAt": "Last Visited",
Expand Down
2 changes: 2 additions & 0 deletions ui/src/share/ShareEdit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DateTimeInput,
BooleanInput,
Edit,
NumberField,
SimpleForm,
Expand All @@ -19,6 +20,7 @@ export const ShareEdit = (props) => {
{url}
</Link>
<TextInput source="description" />
<BooleanInput source="downloadable" />
<DateTimeInput source="expiresAt" />
<TextInput source="contents" disabled />
<TextInput source="format" disabled />
Expand Down
11 changes: 8 additions & 3 deletions ui/src/share/ShareList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Datagrid,
FunctionField,
BooleanField,
List,
NumberField,
SimpleList,
Expand All @@ -24,6 +25,7 @@ export const FormatInfo = ({ record, size }) => {

const ShareList = (props) => {
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('lg'))
const translate = useTranslate()
const notify = useNotify()

Expand Down Expand Up @@ -101,10 +103,13 @@ const ShareList = (props) => {
/>
<TextField source="username" />
<TextField source="description" />
<TextField source="contents" />
<FormatInfo source="format" />
{isDesktop && <TextField source="contents" />}
{isDesktop && <FormatInfo source="format" />}
<BooleanField source="downloadable" />
<NumberField source="visitCount" />
<DateField source="lastVisitedAt" showTime sortByOrder={'DESC'} />
{isDesktop && (
<DateField source="lastVisitedAt" showTime sortByOrder={'DESC'} />
)}
<DateField source="expiresAt" showTime />
</Datagrid>
)}
Expand Down

0 comments on commit a7d3e6e

Please sign in to comment.