mirror of
https://github.com/go-shiori/shiori.git
synced 2025-09-08 05:54:31 +08:00
* migrate bookmark content route to new http server * new archive page * remove unused go generate comment * database mock * utils cleanup * unused var * domains refactor and tests * fixed secret key type * redirect to login on ui errors * fixed archive folder with storage domain * webroot documentation * some bookmark route tests * fixed error in bookmark domain for non existant bookmarks * centralice errors * add coverage data to unittests * added tests, refactor storage to use afero * removed mock to avoid increasing complexity * using deps to copy files around * remove config usage (to deps) * remove handler-ui file
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package domains
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-shiori/shiori/internal/dependencies"
|
|
"github.com/go-shiori/shiori/internal/model"
|
|
)
|
|
|
|
type BookmarksDomain struct {
|
|
deps *dependencies.Dependencies
|
|
}
|
|
|
|
func (d *BookmarksDomain) HasEbook(b *model.BookmarkDTO) bool {
|
|
ebookPath := model.GetEbookPath(b)
|
|
return d.deps.Domains.Storage.FileExists(ebookPath)
|
|
}
|
|
|
|
func (d *BookmarksDomain) HasArchive(b *model.BookmarkDTO) bool {
|
|
archivePath := model.GetArchivePath(b)
|
|
return d.deps.Domains.Storage.FileExists(archivePath)
|
|
}
|
|
|
|
func (d *BookmarksDomain) HasThumbnail(b *model.BookmarkDTO) bool {
|
|
thumbnailPath := model.GetThumbnailPath(b)
|
|
return d.deps.Domains.Storage.FileExists(thumbnailPath)
|
|
}
|
|
|
|
func (d *BookmarksDomain) GetBookmark(ctx context.Context, id model.DBID) (*model.BookmarkDTO, error) {
|
|
bookmark, exists, err := d.deps.Database.GetBookmark(ctx, int(id), "")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get bookmark: %w", err)
|
|
}
|
|
|
|
if !exists {
|
|
return nil, model.ErrBookmarkNotFound
|
|
}
|
|
|
|
// Check if it has ebook and archive.
|
|
bookmark.HasEbook = d.HasEbook(&bookmark)
|
|
bookmark.HasArchive = d.HasArchive(&bookmark)
|
|
|
|
return &bookmark, nil
|
|
}
|
|
|
|
func NewBookmarksDomain(deps *dependencies.Dependencies) *BookmarksDomain {
|
|
return &BookmarksDomain{
|
|
deps: deps,
|
|
}
|
|
}
|