shiori/internal/domains/archiver.go
Felipe Martin cc7c75116d
refactor: migrate bookmark static pages to new http server (#775)
* 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
2023-12-28 18:18:32 +01:00

55 lines
1.4 KiB
Go

package domains
import (
"fmt"
"path/filepath"
"github.com/go-shiori/shiori/internal/core"
"github.com/go-shiori/shiori/internal/dependencies"
"github.com/go-shiori/shiori/internal/model"
"github.com/go-shiori/warc"
)
type ArchiverDomain struct {
deps *dependencies.Dependencies
}
func (d *ArchiverDomain) DownloadBookmarkArchive(book model.BookmarkDTO) (*model.BookmarkDTO, error) {
content, contentType, err := core.DownloadBookmark(book.URL)
if err != nil {
return nil, fmt.Errorf("error downloading url: %s", err)
}
processRequest := core.ProcessRequest{
DataDir: d.deps.Config.Storage.DataDir,
Bookmark: book,
Content: content,
ContentType: contentType,
}
result, isFatalErr, err := core.ProcessBookmark(d.deps, processRequest)
content.Close()
if err != nil && isFatalErr {
return nil, fmt.Errorf("failed to process: %v", err)
}
return &result, nil
}
func (d *ArchiverDomain) GetBookmarkArchive(book *model.BookmarkDTO) (*warc.Archive, error) {
archivePath := model.GetArchivePath(book)
if !d.deps.Domains.Storage.FileExists(archivePath) {
return nil, fmt.Errorf("archive for bookmark %d doesn't exist", book.ID)
}
// FIXME: This only works in local filesystem
return warc.Open(filepath.Join(d.deps.Config.Storage.DataDir, archivePath))
}
func NewArchiverDomain(deps *dependencies.Dependencies) *ArchiverDomain {
return &ArchiverDomain{
deps: deps,
}
}