Skip to content

Commit

Permalink
automatic thumbnails for textfiles artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 17, 2024
1 parent d180256 commit 5e81907
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions handler/app/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/Defacto2/server/handler/readme"
"github.com/Defacto2/server/handler/render"
"github.com/Defacto2/server/handler/sess"
"github.com/Defacto2/server/internal/command"
"github.com/Defacto2/server/internal/postgres/models"
"github.com/Defacto2/server/internal/tags"
"github.com/Defacto2/server/model"
Expand Down Expand Up @@ -182,18 +183,23 @@ func (dir Dirs) updateMagics(db *sql.DB, logger *zap.SugaredLogger,
}
return data
}
switch modMagic {
case
magicnumber.ARChiveSEA.Title(),
magicnumber.YoshiLHA.Title(),
magicnumber.ArchiveRobertJung.Title(),
magicnumber.PKWAREZipImplode.Title(),
magicnumber.PKWAREZipReduce.Title(),
magicnumber.PKWAREZipShrink.Title():
case magicnumber.PKWAREZip.Title():
switch {
case redundantArchive(modMagic):
case modMagic == magicnumber.PKWAREZip.Title():
if !repackZIP(name) {
return data
}
case plainText(modMagic):
dirs := command.Dirs{
Download: dir.Download,
Preview: dir.Preview,
Thumbnail: dir.Thumbnail,
}
if err := dirs.TextImager(logger, name, uid); err != nil {
logger.Error(errorWithID(err, "text imager", uid))
}
data["missingAssets"] = ""
return data
default:
return data
}
Expand All @@ -211,6 +217,43 @@ func (dir Dirs) updateMagics(db *sql.DB, logger *zap.SugaredLogger,
return data
}

func redundantArchive(modMagic interface{}) bool {
switch modMagic.(type) {
case string:
default:
return false
}
switch modMagic.(string) {
case
magicnumber.ARChiveSEA.Title(),
magicnumber.YoshiLHA.Title(),
magicnumber.ArchiveRobertJung.Title(),
magicnumber.PKWAREZipImplode.Title(),
magicnumber.PKWAREZipReduce.Title(),
magicnumber.PKWAREZipShrink.Title():
return true
default:
return false
}
}

func plainText(modMagic interface{}) bool {
switch modMagic.(type) {
case string:
default:
return false
}
switch modMagic.(string) {
case
magicnumber.UTF8Text.Title(),
magicnumber.ANSIEscapeText.Title(),
magicnumber.PlainText.Title():
return true
default:
return false
}
}

func (dir Dirs) embed(art *models.File, data map[string]interface{}) (map[string]interface{}, error) {
if art == nil {
return data, nil
Expand Down

0 comments on commit 5e81907

Please sign in to comment.