fix (psql): psql storage issues

This commit is contained in:
MickaelK
2025-08-29 22:49:42 +10:00
parent 87ec71b3cb
commit cd45d2baad
6 changed files with 53 additions and 14 deletions

View File

@ -5,6 +5,9 @@
z-index: 2; z-index: 2;
background: transparent; background: transparent;
} }
.component_fab .content:empty {
display: none;
}
.component_fab .content { .component_fab .content {
height: 25px; height: 25px;
width: 25px; width: 25px;

View File

@ -103,16 +103,11 @@ func (this PSQL) LoginForm() Form {
func (this PSQL) Touch(path string) error { func (this PSQL) Touch(path string) error {
defer this.Close() defer this.Close()
if !strings.HasSuffix(path, ".form") { if !strings.HasSuffix(path, ".form") {
return ErrNotValid return NewError("Create a form file instead. eg: xxxx.form", 403)
} }
return nil return nil
} }
func (this PSQL) Rm(path string) error {
defer this.Close()
return ErrNotAuthorized
}
func (this PSQL) Mkdir(path string) error { func (this PSQL) Mkdir(path string) error {
defer this.Close() defer this.Close()
return ErrNotValid return ErrNotValid

View File

@ -53,7 +53,7 @@ func (this PSQL) Cat(path string) (io.ReadCloser, error) {
forms := make([]FormElement, len(c)) forms := make([]FormElement, len(c))
for i, _ := range columns { for i, _ := range columns {
forms[i] = createFormElement(col[i], columns[i]) forms[i] = createFormElement(col[i], columns[i])
if slices.Contains(columns[i].Constraint, "PRIMARY KEY") { if slices.Contains(columns[i].Constraint, "PRIMARY KEY") && forms[i].Value != nil {
forms[i].ReadOnly = true forms[i].ReadOnly = true
} else if slices.Contains(columns[i].Constraint, "FOREIGN KEY") { } else if slices.Contains(columns[i].Constraint, "FOREIGN KEY") {
if link, err := _findRelation(this.ctx, this.db, columns[i]); err == nil { if link, err := _findRelation(this.ctx, this.db, columns[i]); err == nil {

View File

@ -2,6 +2,7 @@ package plg_backend_psql
import ( import (
"os" "os"
"time"
. "github.com/mickael-kerjean/filestash/server/common" . "github.com/mickael-kerjean/filestash/server/common"
) )
@ -38,11 +39,18 @@ func (this PSQL) Ls(path string) ([]os.FileInfo, error) {
} }
return out, nil return out, nil
} else if l.row == "" { } else if l.row == "" {
_, key, err := processTable(this.ctx, this.db, l.table) columns, key, err := processTable(this.ctx, this.db, l.table)
if err != nil { if err != nil {
return nil, err return nil, err
} }
rows, err := this.db.QueryContext(this.ctx, `SELECT "`+key+`" FROM "`+l.table+`" LIMIT 500000`) query := `SELECT "` + key + `", NULL FROM "` + l.table + `" LIMIT 500000`
for _, c := range columns {
if c.Type == "timestamptz" {
query = `SELECT "` + key + `", "` + c.Name + `" FROM "` + l.table + `" LIMIT 500000`
break
}
}
rows, err := this.db.QueryContext(this.ctx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -50,12 +58,20 @@ func (this PSQL) Ls(path string) ([]os.FileInfo, error) {
out := []os.FileInfo{} out := []os.FileInfo{}
for rows.Next() { for rows.Next() {
var name string var name string
if err := rows.Scan(&name); err != nil { var t *time.Time
if err = rows.Scan(&name, &t); err != nil {
return nil, err return nil, err
} }
out = append(out, File{ out = append(out, File{
FName: name + ".form", FName: name + ".form",
FType: "file", FType: "file",
FTime: func() int64 {
if t == nil {
return 0
}
return t.Unix()
}(),
FSize: -1,
}) })
} }
return out, nil return out, nil

View File

@ -0,0 +1,25 @@
package plg_backend_psql
import (
. "github.com/mickael-kerjean/filestash/server/common"
)
func (this PSQL) Rm(path string) error {
defer this.Close()
l, err := getPath(path)
if err != nil {
return err
} else if l.table == "" {
return ErrNotFound
}
_, key, err := processTable(this.ctx, this.db, l.table)
if err != nil {
return err
}
_, err = this.db.ExecContext(
this.ctx,
`DELETE FROM "`+l.table+`" WHERE "`+key+`" = $1`,
l.row,
)
return err
}

View File

@ -115,11 +115,11 @@ func createFormElement(val any, column Column) FormElement {
f := FormElement{ f := FormElement{
Type: "text", Type: "text",
} }
switch val.(type) { switch column.Type {
case bool: case "timestamptz":
f.Type = "boolean"
case time.Time:
f.Type = "datetime" f.Type = "datetime"
case "bool":
f.Type = "boolean"
} }
f.Value = convertFromDB(val) f.Value = convertFromDB(val)