Implement updateShare and deleteShare Subsonic endpoints

This commit is contained in:
Deluan
2023-01-22 20:21:06 -05:00
parent 20271df4fb
commit d5df102f9f
6 changed files with 52 additions and 7 deletions
+1 -1
View File
@@ -35,7 +35,6 @@ func Init(ds model.DataStore) {
func createBaseClaims() map[string]any {
tokenClaims := map[string]any{}
tokenClaims[jwt.IssuerKey] = consts.JWTIssuer
tokenClaims[jwt.IssuedAtKey] = time.Now().UTC().Unix()
return tokenClaims
}
@@ -65,6 +64,7 @@ func CreateExpiringPublicToken(exp time.Time, claims map[string]any) (string, er
func CreateToken(u *model.User) (string, error) {
claims := createBaseClaims()
claims[jwt.SubjectKey] = u.UserName
claims[jwt.IssuedAtKey] = time.Now().UTC().Unix()
claims["uid"] = u.ID
claims["adm"] = u.IsAdmin
token, _, err := TokenAuth.Encode(claims)
+7 -1
View File
@@ -148,7 +148,13 @@ 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")
cols := []string{"description"}
// TODO Better handling of Share expiration
if !entity.(*model.Share).ExpiresAt.IsZero() {
cols = append(cols, "expires_at")
}
return r.Persistable.Update(id, entity, cols...)
}
func (r *shareRepositoryWrapper) shareContentsFromAlbums(shareID string, ids string) string {
+2 -3
View File
@@ -42,11 +42,10 @@ var _ = Describe("Share", func() {
Describe("Update", func() {
It("filters out read-only fields", func() {
entity := "entity"
entity := &model.Share{}
err := repo.Update("id", entity)
Expect(err).ToNot(HaveOccurred())
Expect(mockedRepo.(*tests.MockShareRepo).Entity).To(Equal("entity"))
Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description", "expires_at"))
Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description"))
})
})
})