Skip to content

Commit

Permalink
virtual file support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Jul 18, 2023
1 parent a6ec958 commit c622a1a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions handlers/file_upload_handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/JackalLabs/jackalgo/types"
"github.com/JackalLabs/jackalgo/utils/crypt"
Expand Down Expand Up @@ -64,6 +65,33 @@ func TrackFile(file *os.File, parentPath string) (*FileUploadHandler, error) {
return NewFileUploadHandler(file, parentPath, uuid, savedKey, savedIv)
}

func TrackVirtualFile(bytes []byte, fileName string, parentPath string) (*FileUploadHandler, error) {
savedKey := crypt.GenKey()
savedIv := crypt.GenIv()
uuid := uuid.New().String()

details := types.Details{
Name: fileName,
LastModified: time.Now(),
FileType: "virtual",
Size: int64(len(bytes)),
}

newFile := types.NewFile(bytes, details)

f := FileUploadHandler{
File: newFile,
parentPath: parentPath,
uuid: uuid,
key: savedKey,
iv: savedIv,
cid: "",
fid: make([]string, 0),
}

return &f, nil
}

func (f *FileUploadHandler) SetIds(cid string, fid []string) {
f.cid = cid
f.fid = fid
Expand Down

0 comments on commit c622a1a

Please sign in to comment.