Fetch remote files when not in indexeddb

This commit is contained in:
Magnus Åhall 2026-06-26 14:07:26 +02:00
parent f3ca7b9a44
commit 6df2be7944
6 changed files with 153 additions and 36 deletions

42
file.go
View file

@ -12,13 +12,14 @@ import (
)
type File struct {
ID int
UUID string
UserID int `db:"user_id"`
Filename string
Size int
MIME string
Modified time.Time
ID int
UUID string
UserID int `db:"user_id"`
Name string `db:"name"`
Size int
Type string `db:"type"`
Modified time.Time
UploadComplete bool `db:"upload_complete"`
}
var (
@ -41,9 +42,9 @@ func AddFileToDb(userID int, file *File) (err error) { // {{{
`,
file.UserID,
file.UUID,
file.Filename,
file.Name,
file.Size,
file.MIME,
file.Type,
file.Modified,
)
if err != nil {
@ -94,7 +95,7 @@ func FileIDToPath(id int) (string, string) { // {{{
return dir, fpath
} // }}}
func FileWriteData(userID int, dbID int, data []byte, create bool) (err error) {// {{{
func FileWriteData(userID int, dbID int, data []byte, create bool) (err error) { // {{{
dir, fpath := FileIDToPath(dbID)
err = os.MkdirAll(dir, 0700)
if err != nil {
@ -121,6 +122,25 @@ func FileWriteData(userID int, dbID int, data []byte, create bool) (err error) {
}
return
}// }}}
} // }}}
func FileMetadata(userID int, uuid string) (f File, err error) { // {{{
row := db.QueryRowx(`SELECT * FROM public.file WHERE user_id = $1 AND "uuid" = $2`, userID, uuid)
err = row.StructScan(&f)
return
} // }}}
func FileForUser(userID int, uuid string) (f *os.File, md File, err error) { // {{{
row := db.QueryRowx(`SELECT * FROM public.file WHERE user_id = $1 AND "uuid" = $2`, userID, uuid)
err = row.StructScan(&md)
if err != nil {
return
}
_, fpath := FileIDToPath(md.ID)
f, err = os.OpenFile(fpath, os.O_RDONLY, 0600)
return
} // }}}
// vim: foldmethod=marker