Newer
Older
//
// tank
//
// Import and Playlist Daemon for autoradio project
//
//
// Copyright (C) 2017-2018 Christian Pointner <equinox@helsinki.at>
//
// This file is part of tank.
//
// tank is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// tank is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package store
import (
const (
// well-known table names
var (
ErrNotImplented = errors.New("not implemented")
ErrFileInUse = errors.New("file is in use by at least one playlist")
//******* Groups
type Group struct {
Name string `json:"name" gorm:"primary_key"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}
func (g Group) String() string {
return g.Name
}
//******* Files
// type ImportState int
// const (
// ImportNew ImportState = iota
// ImportPending
// ImportRunning
// ImportDone
// ImportAborted
// )
// func (s ImportState) String() string {
// switch s {
// case ImportNew:
// return "new"
// case ImportPending:
// return "pending"
// case ImportRunning:
// return "running"
// case ImportDone:
// return "done"
// case ImportAborted:
// return "aborted"
// }
// return "unknown"
// }
// func (s *ImportState) fromString(str string) error {
// switch str {
// case "new":
// *s = ImportNew
// case "pending":
// *s = ImportPending
// case "running":
// *s = ImportRunning
// case "done":
// *s = ImportDone
// case "aborted":
// *s = ImportAborted
// default:
// return errors.New("invalid import state: '" + str + "'")
// }
// return nil
// }
// func (s ImportState) MarshalText() (data []byte, err error) {
// data = []byte(s.String())
// return
// }
// func (s *ImportState) UnmarshalText(data []byte) (err error) {
// return s.fromString(string(data))
// }
// type ImportLogLine struct {
// Timestamp time.Time `json:"timestamp"`
// Message string `json:"message"`
// }
// type ImportLog []ImportLogLine
// func (l ImportLog) Append(message string) {
// l = append(l, ImportLogLine{time.Now(), message})
// }
type Import struct {
// State ImportState `json:"state"`
Success bool `json:"success"`
// Log ImportLog `json:"log"`
}
FileName string `json:"filename"`
Hash string `json:"hash"`
Import Import `json:"import" gorm:"embedded;embedded_prefix:import__"`
// TODO: actually a full-text index would be nice here...
Artist string `json:"artist" gorm:"index"`
Title string `json:"title" gorm:"index"`
Album string `json:"album" gorm:"index"`
// TODO: add more fields
}
type File struct {
ID uint `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
GroupName string `json:"group" gorm:"not null;index"`
Group Group `json:"-"`
Source FileSource `json:"source" gorm:"embedded;embedded_prefix:source__"`
Metadata FileMetadata `json:"metadata" gorm:"embedded;embedded_prefix:metadata__"`
Size uint64 `json:"size"`
PlaylistID uint `json:"-" gorm:"not null;index;unique_index:unique_playlist_line_numbers"`
LineNum uint `json:"line-num" gorm:"not null;unique_index:unique_playlist_line_numbers"`
Uri string `json:"uri"`
File File `json:"file"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
GroupName string `json:"group" gorm:"not null;index"`
Group Group `json:"-"`