working commit

This commit is contained in:
2026-02-14 15:03:47 +02:00
parent 4a779007b5
commit 789119266a
14 changed files with 627 additions and 69 deletions
+28 -5
View File
@@ -35,6 +35,11 @@ type FileInfoResult struct {
ContentType string
ContentSize string
ContentDigest string
ContentCreatedAt string
ContentCreatedBy string
ContentUpdatedAt string
ContentUpdatedBy string
}
func cleanFilepath(filename string) (string, error) {
@@ -42,7 +47,7 @@ func cleanFilepath(filename string) (string, error) {
return filepath.Clean(filename), nil
}
func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int, *FileInfoResult, error) {
func (oper *Operator) FileInfo(ctx context.Context, operID string, param *FileInfoParams) (int, *FileInfoResult, error) {
var err error
code := http.StatusOK
res := &FileInfoResult{}
@@ -71,6 +76,11 @@ func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int,
ContentSize: strconv.FormatInt(fileDescr.Size, 10),
ContentType: fileDescr.Type,
ContentDigest: fileDescr.Checksum,
ContentCreatedAt: fileDescr.CreatedAt,
ContentCreatedBy: fileDescr.CreatedBy,
ContentUpdatedAt: fileDescr.UpdatedAt,
ContentUpdatedBy: fileDescr.UpdatedBy,
}
return code, res, err
}
@@ -87,7 +97,7 @@ type PutFileResult struct{}
const defaultContentType = "application/octet-stream"
// TODO: checking catalog and file names conflict
func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *PutFileResult, error) {
func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFileParams) (int, *PutFileResult, error) {
var err error
res := &PutFileResult{}
@@ -133,6 +143,7 @@ func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *
fileDescr.Checksum = checksum
fileDescr.UpdatedAt = now
fileDescr.Type = contentType
fileDescr.UpdatedBy = operID
err = oper.mdb.UpdateFileByID(ctx, fileDescr.ID, fileDescr)
if err != nil {
code := http.StatusInternalServerError
@@ -148,6 +159,8 @@ func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *
Checksum: checksum,
CreatedAt: now,
UpdatedAt: now,
CreatedBy: operID,
UpdatedBy: operID,
}
err = oper.mdb.InsertFile(ctx, fileDescr)
if err != nil {
@@ -174,9 +187,14 @@ type GetFileResult struct {
ContentSize string
ContentDigest string
Source io.ReadCloser
ContentCreatedAt string
ContentCreatedBy string
ContentUpdatedAt string
ContentUpdatedBy string
}
func (oper *Operator) GetFile(ctx context.Context, param *GetFileParams) (int, *GetFileResult, error) {
func (oper *Operator) GetFile(ctx context.Context, operID string, param *GetFileParams) (int, *GetFileResult, error) {
var err error
res := &GetFileResult{}
@@ -209,6 +227,11 @@ func (oper *Operator) GetFile(ctx context.Context, param *GetFileParams) (int, *
ContentType: fileDescr.Type,
ContentDigest: fileDescr.Checksum,
Source: reader,
ContentCreatedAt: fileDescr.CreatedAt,
ContentCreatedBy: fileDescr.CreatedBy,
ContentUpdatedAt: fileDescr.UpdatedAt,
ContentUpdatedBy: fileDescr.UpdatedBy,
}
code := http.StatusOK
return code, res, err
@@ -220,7 +243,7 @@ type DeleteFileParams struct {
}
type DeleteFileResult struct{}
func (oper *Operator) DeleteFile(ctx context.Context, param *DeleteFileParams) (int, *DeleteFileResult, error) {
func (oper *Operator) DeleteFile(ctx context.Context, operID string, param *DeleteFileParams) (int, *DeleteFileResult, error) {
var err error
res := &DeleteFileResult{}
code := http.StatusOK
@@ -262,7 +285,7 @@ type ListFilesResult struct {
//Catalogs []string `json:"files,omitempty"`
}
func (oper *Operator) ListFiles(ctx context.Context, param *ListFilesParams) (int, *ListFilesResult, error) {
func (oper *Operator) ListFiles(ctx context.Context, operID string, param *ListFilesParams) (int, *ListFilesResult, error) {
var err error
res := &ListFilesResult{
Files: make([]descr.File, 0),