touchups after refactor
This commit is contained in:
@@ -256,7 +256,7 @@ func createCommentHandler(app *pocketbase.PocketBase) func(e *core.RecordCreateE
|
||||
"id": commentTrail.Id,
|
||||
"author": commentAuthor.GetString("username"),
|
||||
"trail": commentTrail.GetString("name"),
|
||||
"comment": e.Record.GetString("text")[:128],
|
||||
"comment": e.Record.GetString("text"),
|
||||
},
|
||||
Seen: false,
|
||||
Author: e.Record.GetString("author"),
|
||||
|
||||
552
db/migrations/1735585642_updated_activities.go
Normal file
552
db/migrations/1735585642_updated_activities.go
Normal file
@@ -0,0 +1,552 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t9lphichi5xwyeu")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := map[string]any{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"query": "SELECT id,trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,type \nFROM (\n SELECT summit_logs.id,trails.id as trail_id,summit_logs.date,trails.name,text as description,summit_logs.gpx,summit_logs.author,summit_logs.photos,summit_logs.distance,summit_logs.duration,summit_logs.elevation_gain,summit_logs.elevation_loss,summit_logs.created,\"summit_log\" as type \n FROM summit_logs\n LEFT JOIN trails ON summit_logs.id IN (\n SELECT value\n FROM json_each(trails.summit_logs)\n )\n UNION\n SELECT id,id as trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,\"trail\" as type \n FROM trails\n)\nORDER BY date DESC"
|
||||
}`), &options); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.SetOptions(options)
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("zmvj8lcq")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("ujwzemal")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("royuu8hr")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("e5myhqi1")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("twzxntjy")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mbgymehy")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("jvd9zgrj")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("v6t7ybts")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("vnddbe3a")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mp9jqukw")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("c6zw4l4h")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("njsy8gsh")
|
||||
|
||||
// add
|
||||
new_trail_id := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mpcwfh4x",
|
||||
"name": "trail_id",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_trail_id); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_trail_id)
|
||||
|
||||
// add
|
||||
new_date := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "xsxx8b8a",
|
||||
"name": "date",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_date); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_date)
|
||||
|
||||
// add
|
||||
new_name := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "4ybgblqj",
|
||||
"name": "name",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_name); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_name)
|
||||
|
||||
// add
|
||||
new_description := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "f7y3unyx",
|
||||
"name": "description",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_description); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_description)
|
||||
|
||||
// add
|
||||
new_gpx := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "cowkmcyy",
|
||||
"name": "gpx",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_gpx); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_gpx)
|
||||
|
||||
// add
|
||||
new_author := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "dgewwftr",
|
||||
"name": "author",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_author); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_author)
|
||||
|
||||
// add
|
||||
new_photos := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "ugtikydq",
|
||||
"name": "photos",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_photos); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_photos)
|
||||
|
||||
// add
|
||||
new_distance := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "gal6bffx",
|
||||
"name": "distance",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_distance); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_distance)
|
||||
|
||||
// add
|
||||
new_duration := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "kimwtlps",
|
||||
"name": "duration",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_duration); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_duration)
|
||||
|
||||
// add
|
||||
new_elevation_gain := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "80vmdusd",
|
||||
"name": "elevation_gain",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_elevation_gain); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_elevation_gain)
|
||||
|
||||
// add
|
||||
new_elevation_loss := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mrq3rozi",
|
||||
"name": "elevation_loss",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_elevation_loss); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_elevation_loss)
|
||||
|
||||
// add
|
||||
new_type := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "i4dy54g8",
|
||||
"name": "type",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_type); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_type)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t9lphichi5xwyeu")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := map[string]any{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"query": "SELECT id,trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss, type \nFROM (\n SELECT summit_logs.id,trails.id as trail_id,summit_logs.date,trails.name,text as description,summit_logs.gpx,summit_logs.author,summit_logs.photos,summit_logs.distance,summit_logs.duration,summit_logs.elevation_gain,summit_logs.elevation_loss,\"summit_log\" as type \n FROM summit_logs\n LEFT JOIN trails ON summit_logs.id IN (\n SELECT value\n FROM json_each(trails.summit_logs)\n )\n UNION\n SELECT id,id as trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss, \"trail\" as type \n FROM trails\n)\nORDER BY date DESC"
|
||||
}`), &options); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.SetOptions(options)
|
||||
|
||||
// add
|
||||
del_trail_id := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "zmvj8lcq",
|
||||
"name": "trail_id",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_trail_id); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_trail_id)
|
||||
|
||||
// add
|
||||
del_date := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "ujwzemal",
|
||||
"name": "date",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_date); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_date)
|
||||
|
||||
// add
|
||||
del_name := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "royuu8hr",
|
||||
"name": "name",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_name); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_name)
|
||||
|
||||
// add
|
||||
del_description := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "e5myhqi1",
|
||||
"name": "description",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_description); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_description)
|
||||
|
||||
// add
|
||||
del_gpx := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "twzxntjy",
|
||||
"name": "gpx",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_gpx); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_gpx)
|
||||
|
||||
// add
|
||||
del_author := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mbgymehy",
|
||||
"name": "author",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_author); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_author)
|
||||
|
||||
// add
|
||||
del_photos := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "jvd9zgrj",
|
||||
"name": "photos",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_photos); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_photos)
|
||||
|
||||
// add
|
||||
del_distance := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "v6t7ybts",
|
||||
"name": "distance",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_distance); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_distance)
|
||||
|
||||
// add
|
||||
del_duration := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "vnddbe3a",
|
||||
"name": "duration",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_duration); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_duration)
|
||||
|
||||
// add
|
||||
del_elevation_gain := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mp9jqukw",
|
||||
"name": "elevation_gain",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_elevation_gain); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_elevation_gain)
|
||||
|
||||
// add
|
||||
del_elevation_loss := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "c6zw4l4h",
|
||||
"name": "elevation_loss",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_elevation_loss); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_elevation_loss)
|
||||
|
||||
// add
|
||||
del_type := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "njsy8gsh",
|
||||
"name": "type",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_type); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_type)
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mpcwfh4x")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("xsxx8b8a")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("4ybgblqj")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("f7y3unyx")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("cowkmcyy")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("dgewwftr")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("ugtikydq")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("gal6bffx")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("kimwtlps")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("80vmdusd")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mrq3rozi")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("i4dy54g8")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
||||
552
db/migrations/1735585929_updated_activities.go
Normal file
552
db/migrations/1735585929_updated_activities.go
Normal file
@@ -0,0 +1,552 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t9lphichi5xwyeu")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := map[string]any{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"query": "SELECT id,trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,type \nFROM (\n SELECT summit_logs.id,trails.id as trail_id,summit_logs.date,trails.name,text as description,summit_logs.gpx,summit_logs.author,summit_logs.photos,summit_logs.distance,summit_logs.duration,summit_logs.elevation_gain,summit_logs.elevation_loss,summit_logs.created,\"summit_log\" as type \n FROM summit_logs\n JOIN trails ON summit_logs.id IN (\n SELECT value\n FROM json_each(trails.summit_logs)\n )\n UNION\n SELECT id,id as trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,\"trail\" as type \n FROM trails\n)\nORDER BY date DESC"
|
||||
}`), &options); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.SetOptions(options)
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mpcwfh4x")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("xsxx8b8a")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("4ybgblqj")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("f7y3unyx")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("cowkmcyy")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("dgewwftr")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("ugtikydq")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("gal6bffx")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("kimwtlps")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("80vmdusd")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("mrq3rozi")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("i4dy54g8")
|
||||
|
||||
// add
|
||||
new_trail_id := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "nsakta5t",
|
||||
"name": "trail_id",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_trail_id); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_trail_id)
|
||||
|
||||
// add
|
||||
new_date := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "oahimwtf",
|
||||
"name": "date",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_date); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_date)
|
||||
|
||||
// add
|
||||
new_name := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "t9nlksmj",
|
||||
"name": "name",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_name); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_name)
|
||||
|
||||
// add
|
||||
new_description := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "fzfiex8c",
|
||||
"name": "description",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_description); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_description)
|
||||
|
||||
// add
|
||||
new_gpx := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "1vk5125z",
|
||||
"name": "gpx",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_gpx); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_gpx)
|
||||
|
||||
// add
|
||||
new_author := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "skmgodvs",
|
||||
"name": "author",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_author); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_author)
|
||||
|
||||
// add
|
||||
new_photos := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "5rkwvgcy",
|
||||
"name": "photos",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_photos); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_photos)
|
||||
|
||||
// add
|
||||
new_distance := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "xsuyuifg",
|
||||
"name": "distance",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_distance); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_distance)
|
||||
|
||||
// add
|
||||
new_duration := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "0hsfxjcm",
|
||||
"name": "duration",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_duration); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_duration)
|
||||
|
||||
// add
|
||||
new_elevation_gain := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "izyphasx",
|
||||
"name": "elevation_gain",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_elevation_gain); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_elevation_gain)
|
||||
|
||||
// add
|
||||
new_elevation_loss := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "bffz6a6t",
|
||||
"name": "elevation_loss",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_elevation_loss); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_elevation_loss)
|
||||
|
||||
// add
|
||||
new_type := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "2xlfylnh",
|
||||
"name": "type",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), new_type); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_type)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t9lphichi5xwyeu")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := map[string]any{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"query": "SELECT id,trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,type \nFROM (\n SELECT summit_logs.id,trails.id as trail_id,summit_logs.date,trails.name,text as description,summit_logs.gpx,summit_logs.author,summit_logs.photos,summit_logs.distance,summit_logs.duration,summit_logs.elevation_gain,summit_logs.elevation_loss,summit_logs.created,\"summit_log\" as type \n FROM summit_logs\n LEFT JOIN trails ON summit_logs.id IN (\n SELECT value\n FROM json_each(trails.summit_logs)\n )\n UNION\n SELECT id,id as trail_id,date,name,description,gpx,author,photos,distance,duration,elevation_gain,elevation_loss,created,\"trail\" as type \n FROM trails\n)\nORDER BY date DESC"
|
||||
}`), &options); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.SetOptions(options)
|
||||
|
||||
// add
|
||||
del_trail_id := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mpcwfh4x",
|
||||
"name": "trail_id",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_trail_id); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_trail_id)
|
||||
|
||||
// add
|
||||
del_date := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "xsxx8b8a",
|
||||
"name": "date",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_date); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_date)
|
||||
|
||||
// add
|
||||
del_name := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "4ybgblqj",
|
||||
"name": "name",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_name); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_name)
|
||||
|
||||
// add
|
||||
del_description := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "f7y3unyx",
|
||||
"name": "description",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_description); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_description)
|
||||
|
||||
// add
|
||||
del_gpx := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "cowkmcyy",
|
||||
"name": "gpx",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_gpx); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_gpx)
|
||||
|
||||
// add
|
||||
del_author := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "dgewwftr",
|
||||
"name": "author",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_author); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_author)
|
||||
|
||||
// add
|
||||
del_photos := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "ugtikydq",
|
||||
"name": "photos",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_photos); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_photos)
|
||||
|
||||
// add
|
||||
del_distance := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "gal6bffx",
|
||||
"name": "distance",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_distance); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_distance)
|
||||
|
||||
// add
|
||||
del_duration := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "kimwtlps",
|
||||
"name": "duration",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_duration); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_duration)
|
||||
|
||||
// add
|
||||
del_elevation_gain := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "80vmdusd",
|
||||
"name": "elevation_gain",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_elevation_gain); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_elevation_gain)
|
||||
|
||||
// add
|
||||
del_elevation_loss := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "mrq3rozi",
|
||||
"name": "elevation_loss",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_elevation_loss); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_elevation_loss)
|
||||
|
||||
// add
|
||||
del_type := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "i4dy54g8",
|
||||
"name": "type",
|
||||
"type": "json",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 1
|
||||
}
|
||||
}`), del_type); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(del_type)
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("nsakta5t")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("oahimwtf")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("t9nlksmj")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("fzfiex8c")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("1vk5125z")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("skmgodvs")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("5rkwvgcy")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("xsuyuifg")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("0hsfxjcm")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("izyphasx")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("bffz6a6t")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("2xlfylnh")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
||||
@@ -20,7 +20,7 @@ function csrf(allowedPaths: string[]): Handle {
|
||||
request.method === "PATCH" ||
|
||||
request.method === "DELETE") &&
|
||||
request.headers.get("origin") !== url.origin &&
|
||||
!allowedPaths.includes(url.pathname);
|
||||
!allowedPaths.some(p => url.pathname.startsWith(p));
|
||||
|
||||
if (forbidden) {
|
||||
const message = `Cross-site ${request.method} form submissions are forbidden`;
|
||||
@@ -111,4 +111,4 @@ const auth: Handle = async ({ event, resolve }) => {
|
||||
return response
|
||||
}
|
||||
|
||||
export const handle = sequence(csrf(['/api/v1/trail/upload']), auth)
|
||||
export const handle = sequence(csrf(['/api/v1']), auth)
|
||||
@@ -1,17 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Notification } from "$lib/models/notification";
|
||||
import { fly } from "svelte/transition";
|
||||
import NotificationCard from "./notification_card.svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/stores";
|
||||
import type { Notification } from "$lib/models/notification";
|
||||
import {
|
||||
notifications_index,
|
||||
notifications_mark_as_seen,
|
||||
} from "$lib/stores/notification_store";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
import SkeletonListItem from "../base/skeleton_list_item.svelte";
|
||||
import { fly } from "svelte/transition";
|
||||
import SkeletonNotificationCard from "../base/skeleton_notification_card.svelte";
|
||||
import NotificationCard from "./notification_card.svelte";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
let notifications: Notification[] = [];
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-gray-500 text-sm text-center py-6">
|
||||
No notifications
|
||||
{$_("no-notifications")}
|
||||
</p>
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
? $_("planned-a-trail")
|
||||
: $_("completed-a-trail")}
|
||||
<p class="text-xs text-gray-500 mb-3">
|
||||
{new Date(activity.date).toLocaleDateString(undefined, {
|
||||
{new Date(activity.created).toLocaleDateString(undefined, {
|
||||
month: "long",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Du hast noch kein Konto?",
|
||||
"no-data": "Keine Daten",
|
||||
"no-grid": "Kein Gitter",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Keine Präferenz",
|
||||
"no-results": "Keine Ergebnisse gefunden",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Don't have an account?",
|
||||
"no-data": "No data",
|
||||
"no-grid": "No Grid",
|
||||
"no-notifications": "No notifications",
|
||||
"no-preference": "No preference",
|
||||
"no-results": "No results found",
|
||||
"no-routes-added": "No routes added",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Pas encore de compte ?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Pas de préférence",
|
||||
"no-results": "Pas de résultat",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Nincs még fiókja?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nincs preferált",
|
||||
"no-results": "Nincs eredmény",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Non hai ancora un account?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nessuna preferenza",
|
||||
"no-results": "Nessun risultato trovato",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Heb je nog geen account?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Geen voorkeur",
|
||||
"no-results": "Er zijn geen zoekresultaten",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Nie masz konta?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Brak preferencji",
|
||||
"no-results": "Brak wyników",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Não tem uma conta?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nenhuma preferência",
|
||||
"no-results": "Nenhum resultado encontrado",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "还未注册?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "尚未规划",
|
||||
"no-results": "没有找到结果",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -12,6 +12,7 @@ interface Activity {
|
||||
elevation_loss: number;
|
||||
type: "trail" | "summit_log"
|
||||
author: string;
|
||||
created: string;
|
||||
}
|
||||
|
||||
export { type Activity }
|
||||
@@ -3,7 +3,7 @@ import type { Comment } from "../comment";
|
||||
|
||||
const CommentCreateSchema = z.object({
|
||||
text: z.string(),
|
||||
rating: z.number(),
|
||||
rating: z.number().optional(),
|
||||
author: z.string().length(15),
|
||||
trail: z.string().length(15),
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { UserAnonymous } from "./user";
|
||||
export class Comment {
|
||||
id?: string;
|
||||
text: string;
|
||||
rating: number;
|
||||
rating?: number;
|
||||
author: string;
|
||||
trail: string;
|
||||
created?: string;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { object, string } from "yup";
|
||||
import type { Trail } from "./trail";
|
||||
import type { ListShare } from "./list_share";
|
||||
import type { UserAnonymous } from "./user";
|
||||
@@ -36,11 +35,4 @@ export interface ListFilter {
|
||||
public?: boolean;
|
||||
shared?: boolean;
|
||||
sortOrder?: "+" | "-"
|
||||
}
|
||||
|
||||
export const listSchema = object<List>({
|
||||
id: string().optional(),
|
||||
name: string().required(),
|
||||
description: string().optional(),
|
||||
avatar: string().optional()
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as M from "maplibre-gl";
|
||||
import { number, object, string } from "yup";
|
||||
|
||||
class Waypoint {
|
||||
id?: string;
|
||||
|
||||
@@ -7,7 +7,8 @@ export async function activities_index(author: string, page: number = 1, perPage
|
||||
const r = await f('/api/v1/activity?' + new URLSearchParams({
|
||||
"perPage": perPage.toString(),
|
||||
page: page.toString(),
|
||||
filter: `author="${author}"`
|
||||
filter: `author="${author}"`,
|
||||
sort: "-created"
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function notifications_index(data: { recipient: string, seen?: bool
|
||||
filter: `created>=@month&&recipient='${data.recipient}'` + (data.seen !== undefined ? `&&seen=${data.seen}` : ''),
|
||||
sort: '+seen,-created',
|
||||
page: page.toString(),
|
||||
"per-page": perPage.toString()
|
||||
"perPage": perPage.toString()
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ export const editTrail: Writable<Trail> = writable(new Trail(""));
|
||||
|
||||
export async function trails_index(perPage: number = 21, random: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f('/api/v1/trail?' + new URLSearchParams({
|
||||
"per-page": perPage.toString(),
|
||||
"perPage": perPage.toString(),
|
||||
expand: "category,waypoints,summit_logs",
|
||||
sort: random ? "@random" : "",
|
||||
}), {
|
||||
@@ -102,7 +102,7 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
|
||||
}
|
||||
|
||||
r = await fetch('/api/v1/trail?' + new URLSearchParams({
|
||||
"per-page": "-1",
|
||||
"perPage": "-1",
|
||||
filter: `'${trailIds.join(',')}'~id`,
|
||||
expand: "category,waypoints,summit_logs",
|
||||
sort: `+name`,
|
||||
|
||||
@@ -60,11 +60,13 @@ export async function show<T>(event: RequestEvent, collection: Collection) {
|
||||
}
|
||||
|
||||
export async function create<T>(event: RequestEvent, schema: ZodSchema, collection: Collection) {
|
||||
const data = await event.request.json();
|
||||
const searchParams = Object.fromEntries(event.url.searchParams);
|
||||
const safeSearchParams = RecordOptionsSchema.parse(searchParams);
|
||||
|
||||
const data = await event.request.json();
|
||||
const safeData = schema.parse(data);
|
||||
|
||||
const r = await pb.collection(Collection[collection]).create<T>(safeData)
|
||||
const r = await pb.collection(Collection[collection]).create<T>(safeData, safeSearchParams)
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -106,10 +108,12 @@ export async function remove(event: RequestEvent, collection: Collection) {
|
||||
|
||||
export function handleError(e: any) {
|
||||
if (e instanceof ZodError) {
|
||||
return error(400, e.message)
|
||||
return error(400, { message: "invalid_params", details: e.issues } as any)
|
||||
} else if (e instanceof ClientResponseError && e.status > 0) {
|
||||
return error(e.status as NumericRange<400, 599>, e.message)
|
||||
return error(e.status as NumericRange<400, 599>, { message: e.message, detail: e.originalError.data } as any)
|
||||
} else if (e instanceof SyntaxError) {
|
||||
return error(400, "invalid_json")
|
||||
} else {
|
||||
return e
|
||||
return error(500, e.toString())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { handleError } from "$lib/util/api_util";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -13,7 +14,7 @@ export async function POST(event: RequestEvent) {
|
||||
const r = await pb.collection('users').confirmPasswordReset(safeData.token, safeData.password, safeData.passwordConfirm);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { handleError } from "$lib/util/api_util";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -15,7 +16,7 @@ export async function POST(event: RequestEvent) {
|
||||
const r = await pb.collection('users').authWithPassword(safeData.email ?? safeData.username!, data.password);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { env as private_env } from "$env/dynamic/private";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { handleError } from "$lib/util/api_util";
|
||||
|
||||
const redirectURL = private_env.ORIGIN + "/login/redirect"
|
||||
|
||||
@@ -18,7 +19,7 @@ export async function GET(event: RequestEvent) {
|
||||
}
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +41,7 @@ export async function POST(event: RequestEvent) {
|
||||
)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import { z } from "zod";
|
||||
export async function GET(event: RequestEvent) {
|
||||
|
||||
const safeParams = z.object({
|
||||
collection: z.string().length(15),
|
||||
collection: z.string(),
|
||||
record: z.string().length(15),
|
||||
file: z.string()
|
||||
}).safeParse(event.params)
|
||||
|
||||
if (!safeParams.success) {
|
||||
throw error(400, 'Invalid params')
|
||||
throw error(400, safeParams.error)
|
||||
}
|
||||
|
||||
const parts = [];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Notification } from '$lib/models/notification';
|
||||
import type { UserAnonymous } from '$lib/models/user';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { Collection, list } from '$lib/util/api_util';
|
||||
import { Collection, handleError, list } from '$lib/util/api_util';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
@@ -17,6 +17,6 @@ export async function GET(event: RequestEvent) {
|
||||
}
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,10 +152,9 @@
|
||||
$page.url.searchParams.has("lat") &&
|
||||
$page.url.searchParams.has("lon")
|
||||
) {
|
||||
map.setCenter([
|
||||
parseFloat($page.url.searchParams.get("lon")!),
|
||||
parseFloat($page.url.searchParams.get("lat")!),
|
||||
]);
|
||||
const lat = $page.url.searchParams.get("lat");
|
||||
const lon = $page.url.searchParams.get("lon");
|
||||
map.setCenter([parseFloat(lon!), parseFloat(lat!)]);
|
||||
map.setZoom(14);
|
||||
} else if (settings && settings.mapFocus == "trails") {
|
||||
const boundingBox: M.LngLatBoundsLike = [
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-[356px_minmax(0,_1fr)] gap-4 max-w-6xl mx-auto items-start"
|
||||
>
|
||||
<div class="border border-input-border rounded-xl">
|
||||
<div class="border border-input-border rounded-xl sticky top-8">
|
||||
{#if data.user}
|
||||
<div class="flex items-center gap-x-6 px-6 my-6">
|
||||
<img
|
||||
|
||||
@@ -217,7 +217,7 @@
|
||||
|
||||
async function loadSummitLogs() {
|
||||
const logs = await summit_logs_index($page.params.id, filter);
|
||||
summitLogs.set(logs);
|
||||
summitLogs.set(logs.items);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user