resource

package module
v0.0.0-...-b2a009e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2019 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIPNSNotFound is returned when an IPNS is not found in Datastore.
	ErrIPNSNotFound = errors.New("IPNS not found")

	// ErrCIDNotFound is returned when a CID is not found in Datastore.
	ErrCIDNotFound = errors.New("CID not found")

	// ErrNegativeTagItemCount is returned when the value of tag::[tagStr] in Datastore is negative.
	ErrNegativeTagItemCount = errors.New("Negative tag item count")

	// ErrFolderNotExists is returned when folder doesn't exist.
	ErrFolderNotExists = errors.New("Folder doesn't exist")

	// ErrParentFolderNotExists is returned when parent folder doesn't exist.
	ErrParentFolderNotExists = errors.New("Parent folder doesn't exist")

	// ErrItemNotInFolder is returned when the item is not in the folder.
	ErrItemNotInFolder = errors.New("Item is not in the folder")

	// ErrItemInCollection is returned when the item is already in the collection.
	ErrItemInCollection = errors.New("Item is already in the collection")

	// ErrCantDelRootFolder is returned when trying to delete a root folder.
	ErrCantDelRootFolder = errors.New("Root folder can't be deleted")
)

Functions

This section is empty.

Types

type Collection

type Collection struct {
	IPNSAddress string // Can be either a IPNS hash or a DNSLink domain
	Name        string
	Description string
	IsMine      bool
}

Collection is a collection of resource Items. TODO: Last update timestamp

type Datastore

type Datastore struct {
	// contains filtered or unexported fields
}

Datastore is a store for saving resource collections data. Including collections and their resource items. For now it is a struct using BadgerDB. Later on it will be refactored as an interface with multiple database implements. Key-Values:

collections_all::[ipns] = [ipns] collections_mine::[ipns] = [ipns] collections_others::[ipns] = [ipns] collection::[ipns]::name collection::[ipns]::description collection::[ipns]::ismine collection_item::[ipns]::[cid] = [cid] folders::[ipns]::[folderPath] = [folderPath] # The folderPath of root folder is "" folder::[ipns]::[folderPath]::children = [listOfChildFolderNames] folder_item::[ipns]::[folderPath]::[cid] = [cid] items::[cid] = [cid] item::[cid]::name item_collection::[cid]::[ipns] = [ipns] item_tag::[cid]::[tagStr] = [tagStr] item_folder::[cid]::[ipns]::[folderPath] = [folderPath] tags::[tagStr] = [tagStr] tag::[tagStr].count = [itemCount] tag_item::[tagStr]::[cid] = [cid]

func NewDatastore

func NewDatastore(dbPath string) (*Datastore, error)

NewDatastore creates a new Datastore.

func (*Datastore) AddItemTag

func (d *Datastore) AddItemTag(cid string, t Tag) error

AddItemTag adds a Tag to an Item. If the tag doesn't exist in database, it will be created.

func (*Datastore) AddItemToCollection

func (d *Datastore) AddItemToCollection(cid string, ipns string) error

AddItemToCollection adds an Item to a Collection.

func (*Datastore) AddItemToFolder

func (d *Datastore) AddItemToFolder(cid string, folder *Folder) error

AddItemToFolder adds an item to a folder

func (*Datastore) Close

func (d *Datastore) Close() error

Close Datastore

func (*Datastore) CreateOrUpdateCollection

func (d *Datastore) CreateOrUpdateCollection(c *Collection) error

CreateOrUpdateCollection update collection information

func (*Datastore) CreateOrUpdateFolder

func (d *Datastore) CreateOrUpdateFolder(folder *Folder) error

CreateOrUpdateFolder creates a new folder or updates a folder

func (*Datastore) CreateOrUpdateItem

func (d *Datastore) CreateOrUpdateItem(i *Item) error

CreateOrUpdateItem update collection information

func (*Datastore) DelCollection

func (d *Datastore) DelCollection(ipns string) error

DelCollection deletes a collection from datastore. Deleting a collection won't delete items that belongs to the collection.

func (*Datastore) DelFolder

func (d *Datastore) DelFolder(folder *Folder) error

DelFolder deletes a folder and all its children folders. It also remove relationships with items. Items won't be deleted. If an item doesn't belong to any folder of the collection, it will be removed from the collection.

func (*Datastore) DelItem

func (d *Datastore) DelItem(cid string) error

DelItem deletes an item by its CID.

func (*Datastore) HasTag

func (d *Datastore) HasTag(cid string, t Tag) (bool, error)

HasTag checks if an Item has a Tag.

func (*Datastore) IsCollectionEmpty

func (d *Datastore) IsCollectionEmpty(ipns string) (bool, error)

func (*Datastore) IsFolderPathExists

func (d *Datastore) IsFolderPathExists(ipns, path string) (bool, error)

IsFolderPathExists checkes if a folder exists.

func (*Datastore) IsItemInCollection

func (d *Datastore) IsItemInCollection(cid string, ipns string) (bool, error)

IsItemInCollection checks if an Item belongs to a Collection.

func (*Datastore) IsItemInFolder

func (d *Datastore) IsItemInFolder(cid string, folder *Folder) (bool, error)

IsItemInFolder checks if an item is in a folder

func (*Datastore) ListCollections

func (d *Datastore) ListCollections(mineFlag, emptyFlag FilterFlag) ([]*Collection, error)

ListCollections list collections

func (*Datastore) MoveOrCopyFolder

func (d *Datastore) MoveOrCopyFolder(folderFrom, folderTo *Folder, copy bool) error

MoveOrCopyFolder moves or copies a folder to destination

func (*Datastore) MoveOrCopyItem

func (d *Datastore) MoveOrCopyItem(cid string, folderFrom, folderTo *Folder, copy bool) error

MoveOrCopyItem moves or copies an item from a folder to another folder

func (*Datastore) ReadCollection

func (d *Datastore) ReadCollection(ipns string) (*Collection, error)

ReadCollection reads Collection data from database.

func (*Datastore) ReadCollectionItems

func (d *Datastore) ReadCollectionItems(ipns string) ([]string, error)

ReadCollectionItems returns all items' CID in a collection

func (*Datastore) ReadFolder

func (d *Datastore) ReadFolder(ipns, path string) (*Folder, error)

ReadFolder reads a folder from Datastore.

func (*Datastore) ReadFolderChildren

func (d *Datastore) ReadFolderChildren(folder *Folder) ([]string, error)

ReadFolderChildren returns all children (sub-folders) in a folder

func (*Datastore) ReadFolderItems

func (d *Datastore) ReadFolderItems(folder *Folder) ([]string, error)

ReadFolderItems returns all items' CID in a folder

func (*Datastore) ReadItem

func (d *Datastore) ReadItem(cid string) (*Item, error)

ReadItem reads Item from database

func (*Datastore) ReadTagItemCount

func (d *Datastore) ReadTagItemCount(tags []Tag) ([]uint, error)

ReadTagItemCount returns []uint that are item counts of []Tag

func (*Datastore) RemoveItemFromCollection

func (d *Datastore) RemoveItemFromCollection(cid string, ipns string) error

RemoveItemFromCollection removes an Item from a Collection.

func (*Datastore) RemoveItemFromFolder

func (d *Datastore) RemoveItemFromFolder(cid string, folder *Folder) error

RemoveItemFromFolder removes item from a folder

func (*Datastore) RemoveItemTag

func (d *Datastore) RemoveItemTag(cid string, t Tag) error

RemoveItemTag removes a Tag from an Item.

func (*Datastore) SearchTags

func (d *Datastore) SearchTags(prefix string) ([]Tag, error)

SearchTags searches all available tags with prefix

type FilterFlag

type FilterFlag int
const (
	FilterOnly FilterFlag = 1
	FilterAny  FilterFlag = 0
	FilterNone FilterFlag = -1
)

type Folder

type Folder struct {
	IPNSAddress string
	Path        string
}

Folder belongs to only one collection. It may have a parent folder and multiple sub folders. In one collection, a Folder's path is unique. If path is "", it's the root directory of a collection TODO: Total file size of resources that the folder contains. Including subfolders. TODO: Last update timestamp

func (*Folder) Basename

func (f *Folder) Basename() string

Basename returns the last part of paths (base name)

func (*Folder) ParentPath

func (f *Folder) ParentPath() string

ParentPath return parent paths of the folder

type Item

type Item struct {
	CID  string
	Name string
	Tags []Tag
}

Item is one item of any kind of resource. TODO: File size

type Tag

type Tag []string

Tag is for tagging Items.

func NewTagFromStr

func NewTagFromStr(str string) Tag

NewTagFromStr create new Tag struct from a string.

func (Tag) Equals

func (t Tag) Equals(t2 Tag) bool

Equals check if a tag equals to this tag

func (Tag) IsEmpty

func (t Tag) IsEmpty() bool

IsEmpty checks if a Tag is empty

func (Tag) String

func (t Tag) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL