Skip to content
Snippets Groups Projects
types.go 2.23 KiB
Newer Older
  • Learn to ignore specific revisions
  • Christian Pointner's avatar
    Christian Pointner committed
    //
    //  tank
    //
    //  Import and Playlist Daemon for autoradio project
    //
    //
    //  Copyright (C) 2017 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 (
    	"encoding/binary"
    	"errors"
    	"time"
    )
    
    const (
    
    	// well-known bucket names
    	infoBn   = "_info"
    	groupsBn = "groups"
    
    	publicGroupBn = "_public"
    
    
    Christian Pointner's avatar
    Christian Pointner committed
    	filesBn     = "files"
    	playlistsBn = "playlists"
    
    	// well-known keys
    	storeVersionKey = "Version"
    )
    
    var (
    
    	groupBuckets = []string{filesBn, playlistsBn} // these buckets will be created inside every group bucket
    
    Christian Pointner's avatar
    Christian Pointner committed
    
    	ErrNotImplented = errors.New("not implemented")
    
    Christian Pointner's avatar
    Christian Pointner committed
    	ErrNotFound     = errors.New("not found")
    
    Christian Pointner's avatar
    Christian Pointner committed
    )
    
    func itob(v int) []byte {
    	b := make([]byte, 8)
    	binary.BigEndian.PutUint64(b, uint64(v))
    	return b
    }
    
    func btoi(b []byte) int {
    	return int(binary.BigEndian.Uint64(b))
    }
    
    type TimeAndUser struct {
    	User      string    `json:"u"`
    	Timestamp time.Time `josn:"ts"`
    }
    
    // stored in filesBn
    type FileSource struct {
    	FileName    string `json:"f"`
    	ContentHash string `json:"h"`
    }
    
    type FileMetadata struct {
    	Artist string `json:"a"`
    	Title  string `json:"t"`
    	Album  string `json:"b"`
    	// TODO: add more fields
    }
    
    type File struct {
    	Created     TimeAndUser  `json:"cr"`
    	LastChanged TimeAndUser  `json:"ch"`
    	Source      FileSource   `json:"src"`
    	Metadata    FileMetadata `json:"m"`
    	Size        uint64       `json:"s"`
    	Used        bool         `json:"u"`
    	Dirty       bool         `json:"d"`
    }
    
    
    type Files map[string]File
    
    Christian Pointner's avatar
    Christian Pointner committed
    
    // stored in filesBn
    type Playlist struct {
    	Created     TimeAndUser `json:"cr"`
    	LastChanged TimeAndUser `json:"ch"`
    	// TODO: playlist storage layout
    }
    
    
    type Playlists map[string]Playlist