47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"git.jmbit.de/jmb/scanfile/server/internal/sqlc"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func GetFileByID(fileID string) (sqlc.File, error) {
|
|
var pgUUID pgtype.UUID
|
|
err := pgUUID.Scan(fileID)
|
|
if err != nil {
|
|
slog.Error("Unable to convert string to UUID", "file-uuid", fileID, "error", err)
|
|
}
|
|
query := sqlc.New(pool)
|
|
file, err := query.GetFileByUUID(context.Background(), pgUUID)
|
|
|
|
return file, nil
|
|
}
|
|
|
|
func InsertFileProperties(properties sqlc.InsertFilePropertiesParams) error {
|
|
query := sqlc.New(pool)
|
|
err := query.InsertFileProperties(context.Background(), properties)
|
|
if err != nil {
|
|
slog.Error("Unable to add file properties", "file-uuid", properties.ID.String(), "error", err)
|
|
}
|
|
return err
|
|
}
|
|
|
|
// InsertJsonResult() into one of the following tables:
|
|
// diec, msoffice_mraptor, msoffice_oleid, msoffice_olevba
|
|
func InsertJsonResult(fileID pgtype.UUID, data []byte, table string) error {
|
|
query := sqlc.New(pool)
|
|
var err error
|
|
switch table {
|
|
case "diec":
|
|
err = query.InsertFileDIEC(context.Background(), sqlc.InsertFileDIECParams{FileID: fileID, Data: data})
|
|
case "msoffice_oleid":
|
|
|
|
}
|
|
if err != nil {
|
|
slog.Error("Unable to insert DIEC results", "file-uuid", fileID.String(), "error", err)
|
|
}
|
|
return err
|
|
}
|