fixes trail sorting && secure cookie

This commit is contained in:
Christian Beutel
2024-06-16 00:27:32 +02:00
parent 7a6cb6c771
commit aecb21aab3
6 changed files with 44 additions and 6 deletions

View File

@@ -0,0 +1,38 @@
package migrations
import (
"os"
"github.com/meilisearch/meilisearch-go"
"github.com/pocketbase/dbx"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
client := meilisearch.NewClient(meilisearch.ClientConfig{
Host: os.Getenv("MEILI_URL"),
APIKey: os.Getenv("MEILI_MASTER_KEY"),
})
m.Register(func(db dbx.Builder) error {
_, err := client.Index("trails").UpdateSortableAttributes(&[]string{
"created", "date", "difficulty", "distance", "elevation_gain", "name",
})
if err != nil {
return err
}
return nil
}, func(db dbx.Builder) error {
_, err := client.Index("trails").UpdateSortableAttributes(&[]string{
"created", "difficulty", "distance", "elevation_gain", "name",
})
if err != nil {
return err
}
return nil
})
}

Binary file not shown.

View File

@@ -5,5 +5,5 @@ import { currentUser } from '$lib/stores/user_store';
pb.authStore.loadFromCookie(document.cookie)
pb.authStore.onChange(() => {
currentUser.set(pb.authStore.model as User)
document.cookie = pb.authStore.exportToCookie({ httpOnly: false })
document.cookie = pb.authStore.exportToCookie({ httpOnly: false, secure: location.protocol === "https:" })
}, true)

View File

@@ -65,7 +65,7 @@ export const handle: Handle = async ({ event, resolve }) => {
// send back the default 'pb_auth' cookie to the client with the latest store state
response.headers.set(
'set-cookie',
pb.authStore.exportToCookie({ httpOnly: false, secure: true })
pb.authStore.exportToCookie({ httpOnly: false, secure: event.url.protocol === "https:" })
)
return response

View File

@@ -122,7 +122,7 @@
}
</script>
<div class="trail-filter p-8 border border-input-border rounded-xl">
<div class="trail-filter sticky top-4 p-8 border border-input-border rounded-xl self-start">
{#if showTrailSearch}
<div class="flex gap-2 items-center">
<div class="basis-full">

View File

@@ -38,7 +38,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
let r = await f("/api/v1/search/trails", {
method: "POST",
body: JSON.stringify({ q: filter.q, options: { filter: filterText, hitsPerPage: 21, page: page } }),
body: JSON.stringify({ q: filter.q, options: { filter: filterText, sort: [`${filter.sort}:${filter.sortOrder == "+" ? "asc" : "desc"}`], hitsPerPage: 21, page: page } }),
});
const result = await r.json();
@@ -369,11 +369,11 @@ function buildFilterText(filter: TrailFilter, includeGeo: boolean): string {
filterText += ` AND difficulty IN [${filter.difficulty.join(",")}]`
if(filter.startDate) {
if (filter.startDate) {
filterText += ` AND date >= ${new Date(filter.startDate).getTime() / 1000}`
}
if(filter.endDate) {
if (filter.endDate) {
filterText += ` AND date <= ${new Date(filter.endDate).getTime() / 1000}`
}