make all books public by default (revert visibility gating)
All checks were successful
Release / Test backend (push) Successful in 5m47s
Release / Test UI (push) Successful in 1m4s
Release / Build and push images (push) Successful in 6m20s
Release / Deploy to prod (push) Successful in 3m53s
Release / Deploy to homelab (push) Successful in 8s
Release / Gitea Release (push) Successful in 25s
All checks were successful
Release / Test backend (push) Successful in 5m47s
Release / Test UI (push) Successful in 1m4s
Release / Build and push images (push) Successful in 6m20s
Release / Deploy to prod (push) Successful in 3m53s
Release / Deploy to homelab (push) Successful in 8s
Release / Gitea Release (push) Successful in 25s
This commit is contained in:
@@ -86,12 +86,11 @@ func (s *Store) WriteMetadata(ctx context.Context, meta domain.BookMeta) error {
|
|||||||
return fmt.Errorf("WriteMetadata: %w", err)
|
return fmt.Errorf("WriteMetadata: %w", err)
|
||||||
}
|
}
|
||||||
if err == ErrNotFound {
|
if err == ErrNotFound {
|
||||||
// New scraped book — default to admin_only visibility.
|
|
||||||
postPayload := make(map[string]any, len(patchPayload)+1)
|
postPayload := make(map[string]any, len(patchPayload)+1)
|
||||||
for k, v := range patchPayload {
|
for k, v := range patchPayload {
|
||||||
postPayload[k] = v
|
postPayload[k] = v
|
||||||
}
|
}
|
||||||
postPayload["visibility"] = domain.VisibilityAdminOnly
|
postPayload["visibility"] = domain.VisibilityPublic
|
||||||
postErr := s.pb.post(ctx, "/api/collections/books/records", postPayload, nil)
|
postErr := s.pb.post(ctx, "/api/collections/books/records", postPayload, nil)
|
||||||
if postErr == nil {
|
if postErr == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
42
backend/migrations/20260427000001_make_all_books_public.go
Normal file
42
backend/migrations/20260427000001_make_all_books_public.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(app core.App) error {
|
||||||
|
coll, err := app.FindCollectionByNameOrId("books")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if coll.Fields.GetByName("visibility") == nil {
|
||||||
|
coll.Fields.Add(&core.TextField{Name: "visibility"})
|
||||||
|
if err := app.Save(coll); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const perPage = 200
|
||||||
|
for page := 1; ; page++ {
|
||||||
|
records, err := app.FindRecordsByFilter(
|
||||||
|
"books", `visibility="admin_only"`, "+id", perPage, (page-1)*perPage, nil,
|
||||||
|
)
|
||||||
|
if err != nil || len(records) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for _, rec := range records {
|
||||||
|
rec.Set("visibility", "public")
|
||||||
|
_ = app.Save(rec)
|
||||||
|
}
|
||||||
|
if len(records) < perPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, func(app core.App) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user