md

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRemoteLink(link string) bool

IsRemoteLink 判断是否为远程链接

func LoadFileList

func LoadFileList(listPath string) ([]string, error)

LoadFileList 从 JSON/TXT 文件加载路径列表

func ReplaceImageLinkInContent

func ReplaceImageLinkInContent(content, original, replacement string) string

ReplaceImageLinkInContent 在内容中替换图片链接

func WriteFileAtomically

func WriteFileAtomically(filePath, content string) error

WriteFileAtomically 原子写入文件(先写临时文件再 rename)

Types

type ConvertResult

type ConvertResult struct {
	FilePath       string        // 文件路径
	Success        bool          // 是否成功
	Error          error         // 错误信息
	Duration       time.Duration // 处理耗时
	WorkerID       int           // 工作协程ID
	ConvertedCount int           // 转换的问答对数量
	OutputPath     string        // 输出路径
}

ConvertResult 转换结果

type DownloadConfig

type DownloadConfig struct {
	FilePath string // MD文件路径或目录
	Threads  int    // 并发线程数
}

DownloadConfig MD图片下载配置

type DownloadImageLink struct {
	Original string // 原始链接(文件中的内容)
	Decoded  string // 解码后的链接
	IsRemote bool   // 是否为远程链接
	FilePath string // 所属的MD文件路径
}

DownloadImageLink 下载图片链接信息

type DownloadProcessor

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

DownloadProcessor MD文件图片下载处理器

func NewDownloadProcessor

func NewDownloadProcessor(config *DownloadConfig, appConfig *models.AppConfig) (*DownloadProcessor, error)

NewDownloadProcessor 创建下载处理器

func (*DownloadProcessor) DownloadRemoteImages

func (p *DownloadProcessor) DownloadRemoteImages() (*DownloadResult, error)

DownloadRemoteImages 下载远程图片到本地

type DownloadResult

type DownloadResult struct {
	Success      bool              `json:"success"`
	FilePath     string            `json:"file_path"`
	TotalLinks   int               `json:"total_links"`
	RemoteLinks  int               `json:"remote_links"`
	Downloaded   int               `json:"downloaded"`
	Failed       int               `json:"failed"`
	LinkMappings map[string]string `json:"link_mappings,omitempty"` // 原始URL到本地文件名的映射
	ErrorMessage string            `json:"error_message,omitempty"`
	StartTime    time.Time         `json:"start_time"`
	EndTime      time.Time         `json:"end_time"`
	Duration     float64           `json:"duration"`
}

DownloadResult 图片下载结果

type ExtractImageLink struct {
	Original string `json:"original"`  // 原始链接(文件中的内容)
	Decoded  string `json:"decoded"`   // 解码后的链接
	IsRemote bool   `json:"is_remote"` // 是否为远程链接
	AbsPath  string `json:"abs_path"`  // 本地文件的绝对路径
}

ExtractImageLink 提取图片链接信息

type ExtractLinksConfig

type ExtractLinksConfig struct {
	FilePath string // MD文件路径
}

ExtractLinksConfig MD链接提取配置

type ExtractLinksProcessor

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

ExtractLinksProcessor MD文件链接提取处理器

func NewExtractLinksProcessor

func NewExtractLinksProcessor(config *ExtractLinksConfig, appConfig *models.AppConfig) (*ExtractLinksProcessor, error)

NewExtractLinksProcessor 创建链接提取处理器

func (p *ExtractLinksProcessor) ExtractLinks() (*ExtractLinksResult, error)

ExtractLinks 提取所有图片链接

type ExtractLinksResult

type ExtractLinksResult struct {
	Success      bool               `json:"success"`
	FilePath     string             `json:"file_path"`
	TotalLinks   int                `json:"total_links"`
	LocalLinks   int                `json:"local_links"`
	RemoteLinks  int                `json:"remote_links"`
	ImageLinks   []ExtractImageLink `json:"image_links"`
	ErrorMessage string             `json:"error_message,omitempty"`
	StartTime    time.Time          `json:"start_time"`
	EndTime      time.Time          `json:"end_time"`
	Duration     float64            `json:"duration"`
}

ExtractLinksResult 链接提取结果

type FileDownloadTask

type FileDownloadTask struct {
	FilePath string              // MD文件路径
	Content  string              // 文件内容
	Links    []DownloadImageLink // 图片链接列表
}

FileDownloadTask 文件下载任务

type FileUploadTask

type FileUploadTask struct {
	FilePath string            // MD文件路径
	Content  string            // 文件内容
	Links    []UploadImageLink // 图片链接列表
}

FileUploadTask 文件上传任务

type FixResult

type FixResult struct {
	FilePath   string        // 文件路径
	Success    bool          // 是否成功
	Error      error         // 错误信息
	Duration   time.Duration // 处理耗时
	WorkerID   int           // 工作协程ID
	FixedCount int           // 修复的问题数量
}

FixResult 修复结果

type ImageLink struct {
	Original string // 原始链接(文件中的内容)
	Decoded  string // 解码后的链接
	IsRemote bool   // 是否为远程链接
}

ImageLink 通用图片链接信息

func ExtractImageLinks(content string) []ImageLink

ExtractImageLinks 从内容中提取所有图片链接

type MDConfig

type MDConfig struct {
	ThreadCount   int    // 并发线程数
	InputPath     string // 输入路径
	InputListPath string // 输入文件列表路径
	OutputDir     string // 输出目录
}

MDConfig MD处理通用配置

type MDConverter

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

MDConverter JSON转MD转换器

func NewMDConverter

func NewMDConverter(config *MDConfig, aiConfig *models.AppConfig) *MDConverter

NewMDConverter 创建MD转换器

func (*MDConverter) ConvertFiles

func (c *MDConverter) ConvertFiles(ctx context.Context) error

ConvertFiles 转换文件(主入口)

type MDFixer

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

MDFixer MD文件修复器

func NewMDFixer

func NewMDFixer(config *MDConfig, aiConfig *models.AppConfig) *MDFixer

NewMDFixer 创建MD修复器

func (*MDFixer) FixFiles

func (p *MDFixer) FixFiles(ctx context.Context) error

FixFiles 修复文件(主入口)

type ProgressBar

type ProgressBar struct {
	Total int // 总任务数

	StartTime time.Time // 开始时间
	// contains filtered or unexported fields
}

ProgressBar 进度条

func (*ProgressBar) Finish

func (p *ProgressBar) Finish()

Finish 完成进度条

func (*ProgressBar) Increment

func (p *ProgressBar) Increment()

Increment 增加进度

func (*ProgressBar) Start

func (p *ProgressBar) Start()

Start 开始进度条

type QAItem

type QAItem struct {
	Question   string   `json:"question"`   // 问题
	Answer     string   `json:"answer"`     // 答案
	Category   string   `json:"category"`   // 分类
	Tags       []string `json:"tags"`       // 标签
	Difficulty int      `json:"difficulty"` // 难度等级(1-5)
}

QAItem 问答对项

type QAList

type QAList struct {
	QAItems []QAItem `json:"qa_items"` // 问答对列表
}

QAList 问答对列表

type UploadConfig

type UploadConfig struct {
	FilePath    string // MD文件路径或目录
	PicGoServer string // PicGo服务器地址,为空时使用配置文件
	Threads     int    // 并发线程数
}

UploadConfig MD图片上传配置

type UploadImageLink struct {
	Original string // 原始链接(文件中的内容)
	Decoded  string // 解码后的链接
	IsRemote bool   // 是否为远程链接
	AbsPath  string // 本地文件的绝对路径
	FilePath string // 所属的MD文件路径
}

UploadImageLink 上传图片链接信息

type UploadProcessor

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

UploadProcessor MD文件图片上传处理器

func NewUploadProcessor

func NewUploadProcessor(config *UploadConfig, appConfig *models.AppConfig) (*UploadProcessor, error)

NewUploadProcessor 创建上传处理器

func (*UploadProcessor) UploadLocalImages

func (p *UploadProcessor) UploadLocalImages() (*UploadResult, error)

UploadLocalImages 上传本地图片到PicGo(支持文件夹和多线程)

type UploadResult

type UploadResult struct {
	Success      bool      `json:"success"`
	FilePath     string    `json:"file_path"`
	TotalLinks   int       `json:"total_links"`
	LocalLinks   int       `json:"local_links"`
	Uploaded     int       `json:"uploaded"`
	Failed       int       `json:"failed"`
	ErrorMessage string    `json:"error_message,omitempty"`
	StartTime    time.Time `json:"start_time"`
	EndTime      time.Time `json:"end_time"`
	Duration     float64   `json:"duration"`
}

UploadResult 图片上传结果

Jump to

Keyboard shortcuts

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