ziplab

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DOSColorToANSI

func DOSColorToANSI(dosAttr int) (fg int, bg int, bold bool)

DOSColorToANSI converts a DOS color attribute (bg*16 + fg) to ANSI components. Returns foreground color (0-15), background color (0-7), and whether bold is needed.

func DefaultArchiveExtensions

func DefaultArchiveExtensions() []string

DefaultArchiveExtensions returns the list of archive extensions from the default config.

func RunZipLabView

func RunZipLabView(s ssh.Session, terminal *term.Terminal, filePath string, filename string, outputMode ansi.OutputMode)

RunZipLabView presents an interactive archive viewer that lets the user browse entries and extract individual files via ZMODEM.

Types

type AddCommentConfig

type AddCommentConfig struct {
	StepConfig
	CommentFile string `json:"commentFile,omitempty"` // Path to ZCOMMENT.TXT
}

AddCommentConfig extends StepConfig with a comment file.

type ArchiveType

type ArchiveType struct {
	Extension      string   `json:"extension"`                // e.g., ".zip", ".rar"
	Native         bool     `json:"native"`                   // true = handled by Go stdlib
	ExtractCommand string   `json:"extractCommand,omitempty"` // External extract command
	ExtractArgs    []string `json:"extractArgs,omitempty"`    // Extract arguments
	TestCommand    string   `json:"testCommand,omitempty"`    // Integrity test command
	TestArgs       []string `json:"testArgs,omitempty"`       // Test arguments
	AddCommand     string   `json:"addCommand,omitempty"`     // Add file command
	AddArgs        []string `json:"addArgs,omitempty"`        // Add arguments
	CommentCommand string   `json:"commentCommand,omitempty"` // Add comment command
	CommentArgs    []string `json:"commentArgs,omitempty"`    // Comment arguments
}

ArchiveType defines how to handle a specific archive format.

type Config

type Config struct {
	Enabled          bool          `json:"enabled"`
	RunOnUpload      bool          `json:"runOnUpload"`
	ScanFailBehavior string        `json:"scanFailBehavior"` // "delete" or "quarantine"
	QuarantinePath   string        `json:"quarantinePath,omitempty"`
	Steps            StepsConfig   `json:"steps"`
	ArchiveTypes     []ArchiveType `json:"archiveTypes"`
}

Config holds the complete ZipLab configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

func LoadConfig

func LoadConfig(configPath string) (Config, error)

LoadConfig loads ZipLab configuration from ziplab.json in the given config directory. Returns defaults if the file doesn't exist.

func (*Config) GetArchiveType

func (c *Config) GetArchiveType(filename string) (ArchiveType, bool)

GetArchiveType returns the ArchiveType config for a given filename.

func (*Config) IsArchiveSupported

func (c *Config) IsArchiveSupported(filename string) bool

IsArchiveSupported checks if a filename matches a configured archive type.

type IncludeFileConfig

type IncludeFileConfig struct {
	StepConfig
	FilePath string `json:"filePath,omitempty"` // Path to BBS.AD or similar
}

IncludeFileConfig extends StepConfig with the file to include.

type NFOConfig

type NFOConfig struct {
	Entries map[string]NFOEntry // key = "1D", "1P", "1F", etc.
}

NFOConfig holds all parsed entries from ZIPLAB.NFO.

func ParseNFO

func ParseNFO(filePath string) (*NFOConfig, error)

ParseNFO reads and parses a ZIPLAB.NFO file. Format: {step}{status} = X,Y,NormalColor,HiColor,DisplayChars

func (*NFOConfig) BuildStatusSequence

func (n *NFOConfig) BuildStatusSequence(step int, status Status) string

BuildStatusSequence generates an ANSI escape sequence that positions the cursor and renders the status indicator for a given step+status.

func (*NFOConfig) GetEntry

func (n *NFOConfig) GetEntry(step int, status Status) (NFOEntry, bool)

GetEntry returns the NFO entry for a given step and status.

func (*NFOConfig) HasStep

func (n *NFOConfig) HasStep(step int) bool

HasStep returns true if the NFO has any entries for the given step number.

func (*NFOConfig) MaxRow

func (n *NFOConfig) MaxRow() int

MaxRow returns the highest row number used by any NFO entry.

type NFOEntry

type NFOEntry struct {
	Step         int
	Status       Status
	Col          int    // X position (1-based)
	Row          int    // Y position (1-based)
	NormalColor  int    // DOS color attribute (bg*16 + fg)
	HiColor      int    // DOS highlight color attribute
	DisplayChars string // Characters to display (e.g., "███")
}

NFOEntry holds the parsed display coordinates and colors for one step+status.

type PipelineResult

type PipelineResult struct {
	Success     bool
	Description string // Extracted FILE_ID.DIZ content, if found
	StepResults []StepResult
	Error       error
}

PipelineResult holds the outcome of a ZipLab pipeline run.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor runs the ZipLab pipeline steps against an uploaded archive.

func NewProcessor

func NewProcessor(cfg Config, baseDir string) *Processor

NewProcessor creates a new ZipLab processor.

func (*Processor) DisplayPipeline

func (p *Processor) DisplayPipeline(w io.Writer, nfo *NFOConfig, ansiContent []byte, archivePath string) PipelineResult

DisplayPipeline shows the ZIPLAB.ANS screen and runs the pipeline, updating NFO status indicators in real time. This is the main entry point for the visual ZipLab experience.

func (*Processor) RunPipeline

func (p *Processor) RunPipeline(archivePath string, statusFn StatusCallback) PipelineResult

RunPipeline executes the full ZipLab processing pipeline on an archive file. The statusFn callback is invoked before/after each step to update the display. Returns a PipelineResult with the outcome and any extracted FILE_ID.DIZ.

func (*Processor) StepAddComment

func (p *Processor) StepAddComment(archivePath string) error

StepAddComment (Step 6) adds a ZIP comment from the configured comment file.

func (*Processor) StepExtract

func (p *Processor) StepExtract(archivePath string) (string, error)

StepExtract (Step 2) extracts the archive to a temporary work directory. Returns the path to the work directory.

func (*Processor) StepIncludeFile

func (p *Processor) StepIncludeFile(archivePath string) error

StepIncludeFile (Step 7) adds a file (e.g., BBS.AD) into the archive.

func (*Processor) StepRemoveAdsAndDIZ

func (p *Processor) StepRemoveAdsAndDIZ(workDir, archivePath string) (string, error)

StepRemoveAdsAndDIZ (Step 5) extracts FILE_ID.DIZ content and removes unwanted files matching patterns from REMOVE.TXT. workDir is used to find FILE_ID.DIZ; archivePath is the ZIP to strip ad files from.

func (*Processor) StepTestIntegrity

func (p *Processor) StepTestIntegrity(archivePath string) error

StepTestIntegrity (Step 1) tests the archive for corruption. For native ZIP, it opens and reads every file entry. For external formats, it runs the configured test command.

func (*Processor) StepVirusScan

func (p *Processor) StepVirusScan(workDir string) error

StepVirusScan (Step 3) runs a configurable external virus scanner.

type RemoveAdsConfig

type RemoveAdsConfig struct {
	StepConfig
	PatternsFile string `json:"patternsFile,omitempty"` // Path to REMOVE.TXT
}

RemoveAdsConfig extends StepConfig with a patterns file.

type Status

type Status string

Status represents the D/P/F state of a ZipLab step.

const (
	StatusDoing Status = "D"
	StatusPass  Status = "P"
	StatusFail  Status = "F"
)

type StatusCallback

type StatusCallback func(step StepNumber, status Status)

StatusCallback is called when a step's status changes, allowing the caller to update the ANSI display in real time.

type StepConfig

type StepConfig struct {
	Enabled bool     `json:"enabled"`
	Command string   `json:"command,omitempty"`        // External command path
	Args    []string `json:"args,omitempty"`           // Command arguments (supports {FILE}, {WORKDIR} placeholders)
	Timeout int      `json:"timeoutSeconds,omitempty"` // Timeout in seconds (0 = default 60s)
}

StepConfig holds the configuration for an individual ZipLab pipeline step.

type StepNumber

type StepNumber int

StepNumber maps to the original ZipLab step numbering (1-7, skip 4).

const (
	StepIntegrity  StepNumber = 1
	StepExtract    StepNumber = 2
	StepVirusScan  StepNumber = 3
	StepRemoveAds  StepNumber = 5
	StepAddComment StepNumber = 6
	StepInclude    StepNumber = 7
)

type StepResult

type StepResult struct {
	Step    StepNumber
	Name    string
	Status  Status // StatusDoing, StatusPass, StatusFail
	Elapsed time.Duration
	Error   error
}

StepResult records the outcome of a single pipeline step.

type StepsConfig

type StepsConfig struct {
	TestIntegrity StepConfig        `json:"testIntegrity"`
	ExtractToTemp StepConfig        `json:"extractToTemp"`
	VirusScan     StepConfig        `json:"virusScan"`
	RemoveAds     RemoveAdsConfig   `json:"removeAds"`
	AddComment    AddCommentConfig  `json:"addComment"`
	IncludeFile   IncludeFileConfig `json:"includeFile"`
}

StepsConfig holds all pipeline step configurations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址