accounts and email
This commit is contained in:
@@ -123,6 +123,53 @@ func (s *Service) ListDocuments(ctx context.Context) ([]DocumentRecord, error) {
|
||||
return s.repo.ListDocuments(ctx)
|
||||
}
|
||||
|
||||
func (s *Service) ListArchivedDocuments(ctx context.Context) ([]DocumentRecord, error) {
|
||||
return s.repo.ListArchivedDocuments(ctx)
|
||||
}
|
||||
|
||||
func (s *Service) ArchiveDocument(ctx context.Context, path string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if _, err := s.syncSourceDirLocked(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
record, _, err := s.resolveRecord(ctx, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.repo.ArchiveDocument(ctx, record.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.onChange != nil {
|
||||
s.onChange(DocumentChange{
|
||||
Path: record.Path,
|
||||
Title: record.Title,
|
||||
Hash: record.CurrentHash,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) RestoreDocument(ctx context.Context, path string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if err := s.repo.RestoreDocument(ctx, path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := s.syncSourceDirLocked(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) LoadPage(ctx context.Context, requestPath string) (*Page, error) {
|
||||
if _, err := s.SyncSourceDir(ctx); err != nil {
|
||||
return nil, err
|
||||
@@ -317,7 +364,7 @@ func (s *Service) syncFile(ctx context.Context, path string) (*DocumentChange, e
|
||||
return nil, fmt.Errorf("store content file %s: %w", path, err)
|
||||
}
|
||||
|
||||
existing, err := s.repo.GetDocumentByPath(ctx, relative)
|
||||
existing, err := s.repo.GetDocumentByPathIncludingArchived(ctx, relative)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, err
|
||||
}
|
||||
@@ -347,6 +394,10 @@ func (s *Service) syncFile(ctx context.Context, path string) (*DocumentChange, e
|
||||
s.logger.Warn("index search content", "path", relative, "error", err)
|
||||
}
|
||||
|
||||
if existing != nil && existing.ArchivedAt != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
s.logger.Debug("synced document", "path", relative, "hash", record.Hash)
|
||||
return &DocumentChange{
|
||||
Path: relative,
|
||||
|
||||
Reference in New Issue
Block a user