+Bilder- u. Download-Manager

This commit is contained in:
Simon Martens
2026-01-27 13:44:46 +01:00
parent 826c08add2
commit 8cf466851a
8 changed files with 275 additions and 34 deletions

View File

@@ -1,6 +1,9 @@
package dbmodels
import "github.com/pocketbase/pocketbase/core"
import (
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/types"
)
type File struct {
core.BaseRecordProxy
@@ -14,6 +17,14 @@ func (f *File) SetKey(key string) {
f.Set(KEY_FIELD, key)
}
func (f *File) Title() string {
return f.GetString(TITLE_FIELD)
}
func (f *File) SetTitle(title string) {
f.Set(TITLE_FIELD, title)
}
func (f *File) Description() string {
return f.GetString(DESCRIPTION_FIELD)
}
@@ -29,3 +40,23 @@ func (f *File) FileField() string {
func (f *File) SetFileField(file string) {
f.Set(FILE_FIELD, file)
}
func (f *File) PublicURL() string {
filename := f.FileField()
if filename == "" {
return ""
}
return "/api/files/" + FILES_TABLE + "/" + f.Id + "/" + filename
}
func (f *File) Created() types.DateTime {
return f.GetDateTime(CREATED_FIELD)
}
func (f *File) CreatedUnix() int64 {
t := f.GetDateTime(CREATED_FIELD)
if t.IsZero() {
return 0
}
return t.Time().Unix()
}

View File

@@ -1,6 +1,9 @@
package dbmodels
import "github.com/pocketbase/pocketbase/core"
import (
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/types"
)
type Image struct {
core.BaseRecordProxy
@@ -57,3 +60,15 @@ func (i *Image) VorschauPath() string {
func (i *Image) Beschreibung() string {
return i.Description()
}
func (i *Image) Created() types.DateTime {
return i.GetDateTime(CREATED_FIELD)
}
func (i *Image) CreatedUnix() int64 {
t := i.GetDateTime(CREATED_FIELD)
if t.IsZero() {
return 0
}
return t.Time().Unix()
}

View File

@@ -190,6 +190,14 @@ func Images_KeyPrefix(app core.App, prefix string) ([]*Image, error) {
return images, err
}
func Files_All(app core.App) ([]*File, error) {
files := make([]*File, 0)
err := app.RecordQuery(FILES_TABLE).
OrderBy(CREATED_FIELD + " DESC").
All(&files)
return files, err
}
func AccessTokens_Token(app core.App, token string) (*AccessToken, error) {
ret, err := TableByField[AccessToken](
app,