mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-06 20:29:22 -05:00
[server] Move fs code around
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
@@ -229,3 +230,25 @@ func (f filesystem) insertResource(id, parent uuid.UUID, name string, dir bool,
|
||||
return r, err
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesystem) updateResourceModified(id uuid.UUID) error {
|
||||
const q = "UPDATE resources SET modified = NOW() WHERE id = $1"
|
||||
_, err := f.db.Exec(q, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (f filesystem) createResourceVersion(id, versionID uuid.UUID, size int64, mimeType, sha256 string) error {
|
||||
const q = `INSERT INTO resource_versions(id, resource_id, size, mime_type, sha256, storage)
|
||||
VALUES (@version_id::UUID, @resource_id::UUID, @size::INT, @mime_type::TEXT, @sha256::TEXT, @storage::TEXT)`
|
||||
|
||||
args := pgx.NamedArgs{
|
||||
"resource_id": id,
|
||||
"version_id": versionID,
|
||||
"size": size,
|
||||
"mime_type": mimeType,
|
||||
"sha256": sha256,
|
||||
"storage": "_",
|
||||
}
|
||||
_, err := f.db.Exec(q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func (f filesystem) updateResourceModified(id uuid.UUID) error {
|
||||
const q = "UPDATE resources SET modified = NOW() WHERE id = $1"
|
||||
_, err := f.db.Exec(q, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (f filesystem) createResourceVersion(id, versionID uuid.UUID, size int64, mimeType, sha256 string) error {
|
||||
const q = `INSERT INTO resource_versions(id, resource_id, size, mime_type, sha256, storage)
|
||||
VALUES (@version_id::UUID, @resource_id::UUID, @size::INT, @mime_type::TEXT, @sha256::TEXT, @storage::TEXT)`
|
||||
|
||||
args := pgx.NamedArgs{
|
||||
"resource_id": id,
|
||||
"version_id": versionID,
|
||||
"size": size,
|
||||
"mime_type": mimeType,
|
||||
"sha256": sha256,
|
||||
"storage": "_",
|
||||
}
|
||||
_, err := f.db.Exec(q, args)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user