Skip to content

Commit

Permalink
detectANSI to handle ansi text file uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 22, 2024
1 parent 9f0d507 commit 4810f80
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions handler/app/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (dir Dirs) Artifact(c echo.Context, db *sql.DB, logger *zap.SugaredLogger,
data := empty(c)
if !readonly {
data = dir.Editor(art, data)
data = detectANSI(db, logger, art.ID, data)
}
// page metadata
uri := filerecord.DownloadID(art)
Expand Down Expand Up @@ -122,6 +123,21 @@ func (dir Dirs) Artifact(c echo.Context, db *sql.DB, logger *zap.SugaredLogger,
return nil
}

func detectANSI(db *sql.DB, logger *zap.SugaredLogger, id int64, data map[string]interface{}) map[string]interface{} {
if db == nil {
return data
}
mos, numb := data["modOS"].(string), data["modMagicNumber"].(string)
textfile := strings.EqualFold(mos, tags.Text.String())
if textfile && numb == magicnumber.ANSIEscapeText.Title() {
if err := model.UpdatePlatform(db, id, tags.ANSI.String()); err != nil && logger != nil {
logger.Error(errorWithID(err, "update artifact editor platform", id))
}
data["platform"] = tags.ANSI.String()
}
return data
}

func repackZIP(name string) bool {
x, err := pkzip.Methods(name)
if err != nil {
Expand Down

0 comments on commit 4810f80

Please sign in to comment.