Skip to content

Commit

Permalink
extract 3mf bundled assets
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoOliveira committed Jul 24, 2024
1 parent 40d1c68 commit 4685f3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion v2/library/entities/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewAssetFromRootPath(root, path string, isDir bool, parent *Asset) *Asset {
func NewBundledAsset(parent *Asset, path string) *Asset {
ext := filepath.Ext(path)

data := []byte(filepath.Join(*parent.Root, *parent.Path, path))
data := []byte(filepath.Join(*parent.Root, *parent.Path, path)) //TODO: make consistent with the way its calculated on discovery
md5Hash := md5.Sum(data)

var asset = &Asset{
Expand Down
32 changes: 32 additions & 0 deletions v2/library/process/extractors/threemfextractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extractors

import (
"archive/zip"
"errors"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -103,5 +104,36 @@ func (t *ThreeMFExtractor) filterThumb(files []*zip.File) string {
}

func (t *ThreeMFExtractor) ExtractBundled(asset *entities.Asset) error {
if asset.Parent == nil || asset.Parent.Root == nil || asset.Parent.Path == nil {
return errors.New("invalid parent asset")
}
archive, err := zip.OpenReader(filepath.Join(*asset.Root, *asset.Parent.Path))
if err != nil {
return err
}
defer archive.Close()

f, err := archive.Open(utils.VoZ(asset.Path))
if err != nil {
return err
}
defer f.Close()
parentDir := filepath.Dir(*asset.Parent.Path)
assetBase := filepath.Base(*asset.Path)

if err := utils.SaveFile(filepath.Join(*asset.Parent.Root, parentDir, assetBase), f); err != nil {
return err
}

asset.Path = utils.Ptr(filepath.Join(parentDir, assetBase))
asset.Root = asset.Parent.Root
asset.NodeKind = utils.Ptr(entities.NodeKindFile)

kind := config.Cfg.Library.AssetTypes.ByExtension(*asset.Extension).Name
asset.Kind = utils.Ptr(kind)
if kind == "image" {
asset.Thumbnail = utils.Ptr(asset.ID)
}

return nil
}

0 comments on commit 4685f3b

Please sign in to comment.