Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
4e91be6
[#3948] added Bitbucket OAuth2 provider
ganigeorgiev Dec 17, 2023
5f5f9ca
reorder loading=lazy before src per the svelte docs
ganigeorgiev Dec 18, 2023
c807f66
synced with master
ganigeorgiev Dec 24, 2023
6b3780c
[#4035] replaced JWT token with just JWT
ganigeorgiev Dec 26, 2023
370862f
updated AppleClientSecretCreate struct comment
ganigeorgiev Dec 26, 2023
e73b3a3
synced with master
ganigeorgiev Dec 27, 2023
705d7f4
synced with master
ganigeorgiev Dec 29, 2023
422eb30
synced with master
ganigeorgiev Dec 29, 2023
97a8409
fixed sleep example typo and synced with master
ganigeorgiev Dec 30, 2023
d123e19
synced with master
ganigeorgiev Jan 3, 2024
3b7d0e8
synced with master
ganigeorgiev Jan 3, 2024
b033109
synced with master
ganigeorgiev Jan 4, 2024
0f95a11
Merge branch 'master' into develop
ganigeorgiev Jan 5, 2024
6155e64
ghupdate messages update
ganigeorgiev Jan 13, 2024
2e3ae1b
[#4145] fixed JSVM types generation for functions with omitted arg types
ganigeorgiev Jan 13, 2024
931f6bc
updated go deps
ganigeorgiev Jan 13, 2024
8cff94f
synced with master
ganigeorgiev Jan 13, 2024
d795a66
updated go.sum
ganigeorgiev Jan 13, 2024
036c0da
reduce slightly the min row table height
ganigeorgiev Jan 13, 2024
2a28f6f
[#4106] added custom Prism.js bundle and registered new TinyMCE codes…
ganigeorgiev Jan 13, 2024
cd2fc53
updated Prism.js bundle
ganigeorgiev Jan 13, 2024
af7c6d8
[#4066] mark user as verified on confirm password reset
ganigeorgiev Jan 13, 2024
cdb539d
updated changelog
ganigeorgiev Jan 13, 2024
28fc186
added support for loading a serialized json payload as part of multip…
ganigeorgiev Jan 14, 2024
c9bc2f0
added EmailTemplate.Hidden field
ganigeorgiev Jan 16, 2024
9419d19
[#4160] fixed the Admin UI auto indexes update when renaming fields w…
ganigeorgiev Jan 16, 2024
fa65038
synced with master
ganigeorgiev Jan 16, 2024
fc18e69
[#4175] update patreon logo
ghostdevv Jan 18, 2024
b2b792b
[#4177] added graceful OAuth2 redirect error handling
ganigeorgiev Jan 19, 2024
c642a86
rename local const redirect path vars for consistency
ganigeorgiev Jan 20, 2024
d9b219d
[#4192] take collection minPasswordLength in consideration for the us…
ganigeorgiev Jan 20, 2024
9855397
replaced the default binder with rest.MultiBinder
ganigeorgiev Jan 20, 2024
3f7db19
remove funding.yaml
ganigeorgiev Jan 21, 2024
702b4aa
Merge branch 'master' into develop
ganigeorgiev Jan 21, 2024
ba56623
exported .gzip() and .bodyLimit(bytes) JSVM middlewares
ganigeorgiev Jan 21, 2024
f0410a7
[#4033] added option to duplicate fields
ganigeorgiev Jan 21, 2024
bf30af3
include 0 in the auto numeric suffix field name
ganigeorgiev Jan 21, 2024
a44a73a
fixed unverified typos
ganigeorgiev Jan 22, 2024
6fd2e7a
updated min Go and Node.js verion in CONTRIBUTING.md
ganigeorgiev Jan 22, 2024
3013e02
added helper admin cmd error message in case the migrations are not i…
ganigeorgiev Jan 23, 2024
80d65a1
optimized multiple records cascade delete query
ganigeorgiev Jan 23, 2024
aabe820
fixed typos and some linter suggestions
ganigeorgiev Jan 23, 2024
eaf121e
updated ui/dist
ganigeorgiev Jan 23, 2024
2862119
updated serve command error reporting
ganigeorgiev Jan 24, 2024
05556e7
updated changelog and go deps
ganigeorgiev Jan 24, 2024
9436efb
fixed hideControls store reactivity check
ganigeorgiev Jan 24, 2024
fb78a39
updated readme and the thumbGenSem limit
ganigeorgiev Jan 31, 2024
3b6fcf2
fixed RecordUpsert.RemoveFiles godoc example
ganigeorgiev Feb 2, 2024
8a0eed2
update ghupdate to use the config executable name when excluding the …
ganigeorgiev Feb 2, 2024
8402938
fixed Admin UI vertical image preview scroll
ganigeorgiev Feb 2, 2024
fa8e3d8
updated npm deps
ganigeorgiev Feb 2, 2024
ef965aa
removed unused tinymce assets
ganigeorgiev Feb 3, 2024
49adba6
added jsvm.Config.OnInit optional field
ganigeorgiev Feb 3, 2024
03a3f98
sync Admin UI collection changes across browser tabs
ganigeorgiev Feb 3, 2024
b902901
upgraded to aws-sdk-go-v2 and added a special middleware for GCP
ganigeorgiev Feb 5, 2024
5105612
renamed gcp middleware file and updated go deps
ganigeorgiev Feb 5, 2024
442b286
updated changelog
ganigeorgiev Feb 5, 2024
722a749
fixed the error reporting of admin update/delete commands
ganigeorgiev Feb 6, 2024
bada233
[#2173] fixed request.auth.* initialization which caused the current …
ganigeorgiev Feb 7, 2024
ed9cc2f
updated changelog
ganigeorgiev Feb 7, 2024
41aa9b1
updated changelog
ganigeorgiev Feb 7, 2024
368af1f
updated the readme
ganigeorgiev Feb 7, 2024
b7447f3
synced with master
ganigeorgiev Feb 7, 2024
7ef1185
use the email field const
ganigeorgiev Feb 7, 2024
9f1c1c2
updated go deps and the min github action go version
ganigeorgiev Feb 7, 2024
5f1b2fd
updated github action node version
ganigeorgiev Feb 7, 2024
1b89aab
updated github actions
ganigeorgiev Feb 7, 2024
8f8a7c3
fixed readme typo
ganigeorgiev Feb 7, 2024
81ef6f1
Merge branch 'master' into develop
ganigeorgiev Feb 7, 2024
c32f272
[#4322] disable the JS required validations for disabled OIDC providers
ganigeorgiev Feb 9, 2024
388f61a
[#4310] allow HEAD requests to the health endpoint
ganigeorgiev Feb 10, 2024
71141dd
aligned healthCheckResponse struct fields
ganigeorgiev Feb 10, 2024
8599754
sync with master
ganigeorgiev Feb 10, 2024
a5fdbea
manually clear all TinyMCE events on editor removal
ganigeorgiev Feb 10, 2024
a46815e
merged with master
ganigeorgiev Feb 10, 2024
27b6d0c
updated jstypes and ui/dist
ganigeorgiev Feb 10, 2024
aaa6e97
fixed changelog typo
ganigeorgiev Feb 11, 2024
4c14c6c
synced with master
ganigeorgiev Feb 11, 2024
d4a2f05
added presentable file field fallback
ganigeorgiev Feb 11, 2024
959c6b6
[#3403] added option to import/export a subset of collections
ganigeorgiev Feb 12, 2024
2662d87
removed unnecessary concat
ganigeorgiev Feb 12, 2024
6aaf982
hide the merge collections import btn if no schema is specified
ganigeorgiev Feb 12, 2024
a11abef
added @request.context field
ganigeorgiev Feb 17, 2024
4743c1c
updated jsvm types and changelog
ganigeorgiev Feb 17, 2024
4937acb
added back relation filter reference support
ganigeorgiev Feb 19, 2024
f2ed186
added autocomplete for the back relation keys
ganigeorgiev Feb 19, 2024
5a715cc
[#4394] reschedule the first cron tick to start at 00 second
ganigeorgiev Feb 21, 2024
4fba93e
regenerated jsvm types and added locks for the startTimer
ganigeorgiev Feb 21, 2024
4f46222
[#4393] added Planning Center OAuth2 provider
ganigeorgiev Feb 24, 2024
20fba0f
moved filter autocomplete to worker
ganigeorgiev Feb 24, 2024
6132fb4
updated collections export styles
ganigeorgiev Feb 24, 2024
a8b363e
normalized collections export sidebar padding and reduced the waiting…
ganigeorgiev Feb 24, 2024
88c56cd
added :each support for file and relation fields
ganigeorgiev Feb 25, 2024
1014c92
sort exported collections by type and name
ganigeorgiev Feb 25, 2024
548fce2
added back-relation expand limit
ganigeorgiev Feb 25, 2024
53ee521
[#4431] always refresh the app settings before loading the backup cro…
ganigeorgiev Feb 26, 2024
f1a6c19
fixed logs printer dev tests
ganigeorgiev Feb 26, 2024
d084800
updated go deps and bumped ui version
ganigeorgiev Feb 26, 2024
f414e70
Merge branch 'develop'
ganigeorgiev Feb 26, 2024
631957f
=fixed changelog typo and added PR link
ganigeorgiev Feb 26, 2024
39d24ba
Merge branch 'master' into develop
ganigeorgiev Feb 26, 2024
b845d3d
[#4437] initialize `RecordAuthWithOAuth2Event.IsNewRecord` for the `O…
ganigeorgiev Feb 27, 2024
9babca5
[#4448] added error checks to the autogenerated Go migrations
ganigeorgiev Feb 29, 2024
bb410e7
[#4462] fixed Admin UI record and collection panels not reinitializin…
ganigeorgiev Mar 1, 2024
35d7b5f
updated changelog
ganigeorgiev Mar 1, 2024
186d2ed
bumped app version
ganigeorgiev Mar 2, 2024
4a1736a
restored nullifyMissingField checks
ganigeorgiev Mar 2, 2024
1eeacf0
[#4492] fixed admin dropdown z-index on Safari
ganigeorgiev Mar 5, 2024
6695aba
[#4498] fixed OnAfterApiError nil error reference
ganigeorgiev Mar 6, 2024
5574fe3
updated go deps
ganigeorgiev Mar 3, 2024
90c313c
updated go deps
ganigeorgiev Mar 6, 2024
eff0985
updated GitHub release action min Go version
ganigeorgiev Mar 6, 2024
3551dea
[#4500] added the field name as part of the `@request.data.*` relatio…
ganigeorgiev Mar 6, 2024
0afc380
bumped app version
ganigeorgiev Mar 6, 2024
e5e2519
[#4505] removed redundant CodeBlock component styles
ganigeorgiev Mar 6, 2024
adab0da
[#4510] fixed godoc typos
ganigeorgiev Mar 7, 2024
0f1b73a
[#4544] implemented JSVM FormData and added support for $http.send mu…
ganigeorgiev Mar 12, 2024
20653ef
bumped app version
ganigeorgiev Mar 12, 2024
a5eff39
[#4566] fixed JSVM routerUse() example
ganigeorgiev Mar 15, 2024
be40803
updated security.Encrypt and security.Decrypt docs
ganigeorgiev Mar 17, 2024
48153d4
updated restore backup warning message and changed archive.Extract to…
ganigeorgiev Mar 17, 2024
03cec9a
[#4600] autorun migrations for the test app and call the OnTerminate …
ganigeorgiev Mar 20, 2024
309c4fe
call TestApp.ResetBootstrap as finalizer of the test OnTerminate hook
ganigeorgiev Mar 20, 2024
98ba003
added done channel for the cron ticker
ganigeorgiev Mar 20, 2024
0492717
updated backup restore message
ganigeorgiev Mar 21, 2024
b596bbd
updated go deps
ganigeorgiev Mar 21, 2024
0122d4f
[#4607] fixed the keyboard-accebility of the Admin UI dropdowns
ganigeorgiev Mar 22, 2024
31f2ba8
added aria-hidden attr and bumped app version
ganigeorgiev Mar 23, 2024
7ce2545
updated go deps
ganigeorgiev Mar 23, 2024
9090979
[#4650] updated GitLab logo
MvRemmerden Mar 28, 2024
9eb3ff5
updated ui/dist
ganigeorgiev Mar 28, 2024
37dd9c8
vendored and trimmed the s3blob driver and updated dependencies
ganigeorgiev Mar 29, 2024
ac76166
updated changelog
ganigeorgiev Mar 29, 2024
63bcffb
[#4704] fixed '~' autowildcard wrapping when the string has escaped %…
ganigeorgiev Apr 5, 2024
d5fc74d
updated go deps
ganigeorgiev Apr 5, 2024
bee8e08
[#4707] added constrasting border to the default email template btn s…
ganigeorgiev Apr 5, 2024
c951d4b
updated ui/dist
ganigeorgiev Apr 5, 2024
ebc1ed6
replaced btn mail template outline with border for compatability
ganigeorgiev Apr 5, 2024
a9d468a
updated ui/dist
ganigeorgiev Apr 5, 2024
4dc8a10
added aria-expanded to the dropdown triggers
ganigeorgiev Apr 5, 2024
8264ead
updated changelog
ganigeorgiev Apr 5, 2024
4286812
updated go deps
ganigeorgiev Apr 6, 2024
7734d63
[#4737] fixed OAuth2 clear btn action
ganigeorgiev Apr 13, 2024
4745bb4
fixed zeroValue isArray check
ganigeorgiev Apr 13, 2024
4ac0954
fixed zeroValue isArray check and bumped app version
ganigeorgiev Apr 13, 2024
34a25f6
updated go deps
ganigeorgiev Apr 13, 2024
4cfabc6
updated changelog and ui/dist
ganigeorgiev Apr 15, 2024
7628dc5
bumped goreleaser action version
ganigeorgiev Apr 15, 2024
0ea26d9
rollback to goreleaser-action v3
ganigeorgiev Apr 15, 2024
ece62eb
[#4824] updated the uploaded filename normalization to take double ex…
ganigeorgiev Apr 24, 2024
e7ebbd1
updated go deps
ganigeorgiev Apr 24, 2024
4902b72
Merge branch 'master' into develop
ganigeorgiev Apr 24, 2024
3df868f
added extra extension length normalization
ganigeorgiev Apr 24, 2024
2b82c36
updated test cases
ganigeorgiev Apr 24, 2024
7675d2e
Merge branch 'master' into develop
ganigeorgiev Apr 24, 2024
950f796
added temp collections cache
ganigeorgiev Apr 25, 2024
dd7b06c
Merge branch 'master' into develop
ganigeorgiev Apr 25, 2024
7a9dae7
updated changelog
ganigeorgiev Apr 25, 2024
3a18121
Merge branch 'master' into develop
ganigeorgiev Apr 25, 2024
2aeb37d
[#4857] load the full record in the relation picker edit panel
ganigeorgiev May 3, 2024
52a0a87
Merge branch 'master' into develop
ganigeorgiev May 3, 2024
c410f34
updated go deps
ganigeorgiev May 3, 2024
8a75a9a
Merge branch 'master' into develop
ganigeorgiev May 4, 2024
5acaa0a
[#4865] fixed Firefox calendar picker grid layout
ganigeorgiev May 4, 2024
1682db5
updated ui/dist and go deps
ganigeorgiev May 11, 2024
970b000
updated go deps and bumped app version
ganigeorgiev Jun 3, 2024
9d84767
added support for OAuth2 post redirect
ganigeorgiev Jun 14, 2024
d417b86
added POST OAuth2 redirect test
ganigeorgiev Jun 14, 2024
af9cf33
[#5074] redirect with 303 in case of a POST OAuth2 callback
ganigeorgiev Jun 18, 2024
58ace5d
updated the rules when linking OAuth2 by email
ganigeorgiev Jun 18, 2024
9fae8c9
updated go deps
ganigeorgiev Jun 18, 2024
76b43eb
updated changelog
ganigeorgiev Jun 18, 2024
bc1bcac
updated changelog with the reporter GitHub username handle
ganigeorgiev Jun 18, 2024
5b58a78
[#5157] added `tests.TestMailer` mutex
ganigeorgiev Jul 1, 2024
3a80d44
manually unset the verified state on drysubmit
ganigeorgiev Jul 1, 2024
c79ef4a
updated goja
ganigeorgiev Jul 1, 2024
679751d
updated ui/dist
ganigeorgiev Jul 1, 2024
a8e9c97
bumped the min Go version in the GitHub release action
ganigeorgiev Jul 2, 2024
29b75ba
updated go deps
ganigeorgiev Jul 2, 2024
c7f758a
normalized wrapped errors casing
ganigeorgiev Jul 2, 2024
ae2f8a4
log cronAdd failures with error log level
ganigeorgiev Jul 2, 2024
f1aa477
downgrade modernc.org/libc as it needs to match with the modernc.org/…
ganigeorgiev Jul 2, 2024
10ac417
[#5179] fixed days calculation for triggering old logs deletion
nehmeroumani Jul 6, 2024
2036287
[#5179] added logs delete trigger test and bumped app version
ganigeorgiev Jul 6, 2024
f9fcea8
updated changelog
ganigeorgiev Jul 6, 2024
1e8e70c
fixed logs delete check
ganigeorgiev Jul 9, 2024
8560e90
disabled mouse selection when changing the sidebar width
ganigeorgiev Jul 9, 2024
4d5188d
updated npm deps
ganigeorgiev Jul 9, 2024
e766622
updated ui/dist
ganigeorgiev Jul 9, 2024
55f1517
updated tinymce
ganigeorgiev Jul 9, 2024
f5f92fd
updated min sidebar width
ganigeorgiev Jul 9, 2024
b0f8c78
updated ui/dist
ganigeorgiev Jul 9, 2024
1f08b70
updated logs delete trigger frequency and tests
ganigeorgiev Jul 9, 2024
01450cd
normalized internal errors formatting
ganigeorgiev Jul 9, 2024
9663411
updated changelog
ganigeorgiev Jul 9, 2024
d2e355e
[#5246] improved files delete performance when using the local filesy…
ganigeorgiev Jul 23, 2024
5be32e8
added empty dir delete test for trailing slash prefixes
ganigeorgiev Jul 23, 2024
238eddc
updated go deps
ganigeorgiev Jul 23, 2024
781273b
upgrade to pd-v0.22.18
abdokhaire Aug 7, 2024
41086ab
add feature to read config from .env file
abdokhaire Aug 7, 2024
25541eb
fix no required module provides package for github.com/joho/godotenv
abdokhaire Aug 7, 2024
951b8cb
revert changes to original values
abdokhaire Aug 7, 2024
498a21b
include the 'user' object in the Apple.FetchRawUserData result
ganigeorgiev Aug 12, 2024
86e0e9c
fix multi relation issue
abdokhaire Aug 16, 2024
14814e3
Merge branch 'dev'
abdokhaire Aug 16, 2024
ca1ca9f
Merge remote-tracking branch 'pb/master' into dev
abdokhaire Aug 20, 2024
99624db
revert changes to original values
abdokhaire Aug 7, 2024
a944792
Merge branch 'master' of https://github.com/abdokhaire/postgresbase
abdokhaire Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# after generating keys, you can set as environment variables
JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
<<$(cat ./keys/private.pem)>>
-----END PRIVATE KEY-----"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
<<$(cat ./keys/public.pem)>>
-----END PUBLIC KEY-----"
CGO_ENABLED=0
LOGS_DATABASE="postgresql://user:pass@localhost/logs?sslmode=disable"
DATABASE="postgresql://user:pass@localhost/postgres?sslmode=disable"


# optional ENV_VARS
BCRYPT_COST=10 # default is 12
13 changes: 0 additions & 13 deletions .github/FUNDING.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20.8.1
node-version: 20.11.0

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: '>=1.21.3'
go-version: '>=1.22.5'

# This step usually is not needed because the /ui/dist is pregenerated locally
# but its here to ensure that each release embeds the latest admin ui artifacts.
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.vscode/
/.vscode/*
.idea

.DS_Store
Expand All @@ -23,4 +23,6 @@ pb_migrations/*
pb_data/*
server
*.exe
keys/*
keys/*
.env
!.vscode/launch.json
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/examples/base",
"buildFlags": "-tags=pq",
"args": ["serve", "--dev"],
"envFile": "${workspaceRoot}/.env",
"debugAdapter": "dlv-dap"
}
]
}
296 changes: 296 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This document describes how to prepare a PR for a change in the main repository.

## Prerequisites

- Go 1.19+ (for making changes in the Go code)
- Node 16+ (for making changes in the Admin UI)
- Go 1.21+ (for making changes in the Go code)
- Node 18+ (for making changes in the Admin UI)

If you haven't already, you can fork the main repository and clone your fork so that you can work locally:

Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ go mod download
# 1. postgres://user:pass@localhost/logs?sslmode=disable
# 2. minio: UI runs on port 9001 and API on 9000 (minio123:minio123)
# 2. s3://minio123:minio123@localhost:9000/public
# (dont forget to manually create bucket called "public" via web ui to establish s3 connection from pocketbase)
# 2.1. (dont forget to manually create bucket called "public" via web ui to establish s3 connection from pocketbase localhost:9001 user:minio123 pass:minio123 )
# 2.2. Create new access key http://localhost:9001/access-keys and save it locally as we will use it later
# 2.3. Configure the S3 file storage from pd http://127.0.0.1:8090/_/?#/settings/storage usin the following
# 2.3. Endpoint: http://localhost:9000/public
# 2.3. Bucket: public
# 2.3. Region: us-east-1
# 2.3. Access key & secret use the one you create at step 2.2
# 2.3. Save Changes
# 3. mailhog: port: SMTP-1025 and UI-8025
# 3. smtp://localhost:1025 - http://localhost:8025
docker-compose up -d
docker compose up -d

# before run the project, you need to create and set RSA Public key pair for JWT before run the application.
# you can use following command to generate RSA key pair
Expand Down
5 changes: 3 additions & 2 deletions apis/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const trailedAdminPath = "/_/"
func InitApi(app core.App) (*echo.Echo, error) {
e := echo.New()
e.Debug = false
e.Binder = &rest.MultiBinder{}
e.JSONSerializer = &rest.Serializer{
FieldsParam: fieldsQueryParam,
}
Expand Down Expand Up @@ -82,7 +83,7 @@ func InitApi(app core.App) (*echo.Echo, error) {
logRequest(app, c, apiErr)

if c.Response().Committed {
return // already commited
return // already committed
}

event := new(core.ApiErrorEvent)
Expand All @@ -105,7 +106,7 @@ func InitApi(app core.App) (*echo.Echo, error) {

if hookErr == nil {
if err := app.OnAfterApiError().Trigger(event); err != nil {
app.Logger().Debug("OnAfterApiError failure", slog.String("error", hookErr.Error()))
app.Logger().Debug("OnAfterApiError failure", slog.String("error", err.Error()))
}
} else {
app.Logger().Debug("OnBeforeApiError error (truly rare case, eg. client already disconnected)", slog.String("error", hookErr.Error()))
Expand Down
63 changes: 37 additions & 26 deletions apis/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/AlperRehaYAZGAN/postgresbase/apis"
"github.com/AlperRehaYAZGAN/postgresbase/tests"
"github.com/AlperRehaYAZGAN/postgresbase/tools/rest"
"github.com/labstack/echo/v5"
"github.com/spf13/cast"
)
Expand Down Expand Up @@ -220,15 +221,24 @@ func TestRemoveTrailingSlashMiddleware(t *testing.T) {
}
}

func TestEagerRequestInfoCache(t *testing.T) {
func TestMultiBinder(t *testing.T) {
t.Parallel()

rawJson := `{"name":"test123"}`

formData, mp, err := tests.MockMultipartData(map[string]string{
rest.MultipartJsonKey: rawJson,
})
if err != nil {
t.Fatal(err)
}

scenarios := []tests.ApiScenario{
{
Name: "custom non-api group route",
Name: "non-api group route",
Method: "POST",
Url: "/custom",
Body: strings.NewReader(`{"name":"test123"}`),
Body: strings.NewReader(rawJson),
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
e.AddRoute(echo.Route{
Method: "POST",
Expand All @@ -242,11 +252,10 @@ func TestEagerRequestInfoCache(t *testing.T) {
return err
}

// since the unknown method is not eager cache support
// it should fail reading the json body twice
// try to read the body again
r := apis.RequestInfo(c)
if v := cast.ToString(r.Data["name"]); v != "" {
t.Fatalf("Expected empty request data body, got, %v", r.Data)
if v := cast.ToString(r.Data["name"]); v != "test123" {
t.Fatalf("Expected request data with name %q, got, %q", "test123", v)
}

return c.NoContent(200)
Expand All @@ -256,10 +265,10 @@ func TestEagerRequestInfoCache(t *testing.T) {
ExpectedStatus: 200,
},
{
Name: "api group route with unsupported eager cache request method",
Name: "api group route",
Method: "GET",
Url: "/api/admins",
Body: strings.NewReader(`{"name":"test123"}`),
Body: strings.NewReader(rawJson),
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
Expand All @@ -273,11 +282,10 @@ func TestEagerRequestInfoCache(t *testing.T) {
}{}
c.Bind(data)

// since the unknown method is not eager cache support
// it should fail reading the json body twice
// try to read the body again
r := apis.RequestInfo(c)
if v := cast.ToString(r.Data["name"]); v != "" {
t.Fatalf("Expected empty request data body, got, %v", r.Data)
if v := cast.ToString(r.Data["name"]); v != "test123" {
t.Fatalf("Expected request data with name %q, got, %q", "test123", v)
}

return nil
Expand All @@ -287,31 +295,34 @@ func TestEagerRequestInfoCache(t *testing.T) {
ExpectedStatus: 200,
},
{
Name: "api group route with supported eager cache request method",
Name: "custom route with @jsonPayload as multipart body",
Method: "POST",
Url: "/api/admins",
Body: strings.NewReader(`{"name":"test123"}`),
Url: "/custom",
Body: formData,
RequestHeaders: map[string]string{
"Content-Type": mp.FormDataContentType(),
},
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// it is not important whether the route handler return an error since
// we just need to ensure that the eagerRequestInfoCache was registered
next(c)

// ensure that the body was read at least once
e.AddRoute(echo.Route{
Method: "POST",
Path: "/custom",
Handler: func(c echo.Context) error {
data := &struct {
Name string `json:"name"`
}{}
c.Bind(data)

if err := c.Bind(data); err != nil {
return err
}

// try to read the body again
r := apis.RequestInfo(c)
if v := cast.ToString(r.Data["name"]); v != "test123" {
t.Fatalf("Expected request data with name %q, got, %q", "test123", v)
}

return nil
}
return c.NoContent(200)
},
})
},
ExpectedStatus: 200,
Expand Down
3 changes: 2 additions & 1 deletion apis/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,8 @@ func TestCollectionUpdate(t *testing.T) {
{"type":"text","name":"password"},
{"type":"text","name":"passwordConfirm"},
{"type":"text","name":"oldPassword"}
]
],
"indexes": []
}`),
RequestHeaders: map[string]string{
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
Expand Down
5 changes: 3 additions & 2 deletions apis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var defaultThumbSizes = []string{"100x100"}
func bindFileApi(app core.App, rg *echo.Group) {
api := fileApi{
app: app,
thumbGenSem: semaphore.NewWeighted(int64(runtime.NumCPU() + 1)), // the value is arbitrary chosen and may change in the future
thumbGenSem: semaphore.NewWeighted(int64(runtime.NumCPU() + 2)), // the value is arbitrary chosen and may change in the future
thumbGenPending: new(singleflight.Group),
thumbGenMaxWait: 60 * time.Second,
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func (api *fileApi) download(c echo.Context) error {

options, ok := fileField.Options.(*schema.FileOptions)
if !ok {
return NewBadRequestError("", errors.New("Failed to load file options."))
return NewBadRequestError("", errors.New("failed to load file options"))
}

// check whether the request is authorized to view the protected file
Expand All @@ -122,6 +122,7 @@ func (api *fileApi) download(c echo.Context) error {

// create a copy of the cached request data and adjust it for the current auth model
requestInfo := *RequestInfo(c)
requestInfo.Context = models.RequestInfoContextProtectedFile
requestInfo.Admin = nil
requestInfo.AuthRecord = nil
if adminOrAuthRecord != nil {
Expand Down
7 changes: 6 additions & 1 deletion apis/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func bindHealthApi(app core.App, rg *echo.Group) {
api := healthApi{app: app}

subGroup := rg.Group("/health")
subGroup.HEAD("", api.healthCheck)
subGroup.GET("", api.healthCheck)
}

Expand All @@ -20,15 +21,19 @@ type healthApi struct {
}

type healthCheckResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Code int `json:"code"`
Data struct {
CanBackup bool `json:"canBackup"`
} `json:"data"`
}

// healthCheck returns a 200 OK response if the server is healthy.
func (api *healthApi) healthCheck(c echo.Context) error {
if c.Request().Method == http.MethodHead {
return c.NoContent(http.StatusOK)
}

resp := new(healthCheckResponse)
resp.Code = http.StatusOK
resp.Message = "API is healthy."
Expand Down
8 changes: 7 additions & 1 deletion apis/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ func TestHealthAPI(t *testing.T) {

scenarios := []tests.ApiScenario{
{
Name: "health status returns 200",
Name: "HEAD health status",
Method: http.MethodHead,
Url: "/api/health",
ExpectedStatus: 200,
},
{
Name: "GET health status",
Method: http.MethodGet,
Url: "/api/health",
ExpectedStatus: 200,
Expand Down
4 changes: 3 additions & 1 deletion apis/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func LoadCollectionContext(app core.App, optCollectionTypes ...string) echo.Midd
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if param := c.PathParam("collection"); param != "" {
collection, err := app.Dao().FindCollectionByNameOrId(param)
collection, err := core.FindCachedCollectionByNameOrId(app, param)
if err != nil || collection == nil {
return NewNotFoundError("", err)
}
Expand Down Expand Up @@ -402,6 +402,8 @@ func realUserIp(r *http.Request, fallbackIp string) string {
return fallbackIp
}

// @todo consider removing as this may no longer be needed due to the custom rest.MultiBinder.
//
// eagerRequestInfoCache ensures that the request data is cached in the request
// context to allow reading for example the json request body data more than once.
func eagerRequestInfoCache(app core.App) echo.MiddlewareFunc {
Expand Down
3 changes: 2 additions & 1 deletion apis/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ type recordData struct {
func (api *realtimeApi) broadcastRecord(action string, record *models.Record, dryCache bool) error {
collection := record.Collection()
if collection == nil {
return errors.New("[broadcastRecord] Record collection not set.")
return errors.New("[broadcastRecord] Record collection not set")
}

clients := api.app.SubscriptionsBroker().Clients()
Expand Down Expand Up @@ -409,6 +409,7 @@ func (api *realtimeApi) broadcastRecord(action string, record *models.Record, dr

// mock request data
requestInfo := &models.RequestInfo{
Context: models.RequestInfoContextRealtime,
Method: "GET",
Query: options.Query,
Headers: options.Headers,
Expand Down
Loading