]>
code.octet-stream.net Git - broadcaster/blob - server/files.go
12 type FileSpec
struct {
17 type AudioFiles
struct {
25 func InitAudioFiles(path
string) {
26 files
.changeWait
= make(chan bool)
28 log
.Println("initing audio files")
33 func (r
*AudioFiles
) Refresh() {
34 entries
, err
:= os
.ReadDir(r
.path
)
36 log
.Println("couldn't read dir", r
.path
)
40 for _
, file
:= range entries
{
41 f
, err
:= os
.Open(filepath
.Join(r
.path
, file
.Name()))
43 log
.Println("couldn't open", file
.Name())
48 r
.list
= append(r
.list
, FileSpec
{Name
: file
.Name(), Hash
: hex
.EncodeToString(hash
.Sum(nil))})
50 log
.Println("Files updated", r
.list
)
51 close(files
.changeWait
)
52 files
.changeWait
= make(chan bool)
55 func (r
*AudioFiles
) Path() string {
59 func (r
*AudioFiles
) Files() []FileSpec
{
63 func (r
*AudioFiles
) Delete(filename
string) {
64 path
:= filepath
.Join(r
.path
, filepath
.Base(filename
))
65 if filepath
.Clean(r
.path
) != filepath
.Clean(path
) {
71 func (r
*AudioFiles
) ChangeChannel() chan bool {