fixes trail sorting && secure cookie
This commit is contained in:
38
db/migrations/1718486749_update_sortable_attributes.go
Normal file
38
db/migrations/1718486749_update_sortable_attributes.go
Normal 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.
@@ -5,5 +5,5 @@ import { currentUser } from '$lib/stores/user_store';
|
|||||||
pb.authStore.loadFromCookie(document.cookie)
|
pb.authStore.loadFromCookie(document.cookie)
|
||||||
pb.authStore.onChange(() => {
|
pb.authStore.onChange(() => {
|
||||||
currentUser.set(pb.authStore.model as User)
|
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)
|
}, true)
|
||||||
@@ -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
|
// send back the default 'pb_auth' cookie to the client with the latest store state
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
'set-cookie',
|
'set-cookie',
|
||||||
pb.authStore.exportToCookie({ httpOnly: false, secure: true })
|
pb.authStore.exportToCookie({ httpOnly: false, secure: event.url.protocol === "https:" })
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -122,7 +122,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</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}
|
{#if showTrailSearch}
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
<div class="basis-full">
|
<div class="basis-full">
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
|
|||||||
|
|
||||||
let r = await f("/api/v1/search/trails", {
|
let r = await f("/api/v1/search/trails", {
|
||||||
method: "POST",
|
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();
|
const result = await r.json();
|
||||||
@@ -369,11 +369,11 @@ function buildFilterText(filter: TrailFilter, includeGeo: boolean): string {
|
|||||||
|
|
||||||
filterText += ` AND difficulty IN [${filter.difficulty.join(",")}]`
|
filterText += ` AND difficulty IN [${filter.difficulty.join(",")}]`
|
||||||
|
|
||||||
if(filter.startDate) {
|
if (filter.startDate) {
|
||||||
filterText += ` AND date >= ${new Date(filter.startDate).getTime() / 1000}`
|
filterText += ` AND date >= ${new Date(filter.startDate).getTime() / 1000}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filter.endDate) {
|
if (filter.endDate) {
|
||||||
filterText += ` AND date <= ${new Date(filter.endDate).getTime() / 1000}`
|
filterText += ` AND date <= ${new Date(filter.endDate).getTime() / 1000}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user