mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-28 07:44:56 +00:00
update: packages,lua,stream (5 files)
This commit is contained in:
151
packages/media_center/seed/scripts/lua/document_converter.lua
Normal file
151
packages/media_center/seed/scripts/lua/document_converter.lua
Normal file
@@ -0,0 +1,151 @@
|
||||
--[[
|
||||
Document conversion functions
|
||||
]]
|
||||
|
||||
---@class DocumentConverterModule
|
||||
local M = {}
|
||||
|
||||
local config = {
|
||||
base_url = "http://localhost:8090"
|
||||
}
|
||||
|
||||
---Configure the converter
|
||||
---@param opts table Configuration options
|
||||
function M.configure(opts)
|
||||
if opts.base_url then config.base_url = opts.base_url end
|
||||
end
|
||||
|
||||
---Generate output path from input path
|
||||
---@param input_path string Input file path
|
||||
---@param output_format string Output format extension
|
||||
---@return string output_path Generated output path
|
||||
local function generate_output_path(input_path, output_format)
|
||||
-- Remove extension and add new one
|
||||
local base = input_path:match("(.+)%.[^%.]+$") or input_path
|
||||
return base .. "." .. output_format
|
||||
end
|
||||
|
||||
---Convert a document
|
||||
---@param input_path string Path to input file
|
||||
---@param output_format DocumentFormat Target format
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.convert(input_path, output_format, options)
|
||||
if not input_path or input_path == "" then
|
||||
return nil, "Input path is required"
|
||||
end
|
||||
|
||||
if not output_format or output_format == "" then
|
||||
return nil, "Output format is required"
|
||||
end
|
||||
|
||||
options = options or {}
|
||||
|
||||
local output_path = options.output_path or generate_output_path(input_path, output_format)
|
||||
|
||||
-- Build request body
|
||||
local body = {
|
||||
type = "document_convert",
|
||||
params = {
|
||||
input_path = input_path,
|
||||
output_path = output_path,
|
||||
output_format = output_format,
|
||||
variables = {}
|
||||
},
|
||||
notify_user = true
|
||||
}
|
||||
|
||||
-- Add options as variables
|
||||
if options.toc then
|
||||
body.params.variables.toc = "true"
|
||||
end
|
||||
if options.template then
|
||||
body.params.template_path = options.template
|
||||
end
|
||||
if options.title then
|
||||
body.params.variables.title = options.title
|
||||
end
|
||||
if options.author then
|
||||
body.params.variables.author = options.author
|
||||
end
|
||||
if options.date then
|
||||
body.params.variables.date = options.date
|
||||
end
|
||||
if options.paper_size then
|
||||
body.params.variables.papersize = options.paper_size
|
||||
end
|
||||
if options.margin then
|
||||
body.params.variables["geometry:margin"] = options.margin
|
||||
end
|
||||
|
||||
-- HTTP POST /api/jobs would go here
|
||||
-- Return mock response for now
|
||||
return {
|
||||
id = "doc_" .. tostring(os.time()),
|
||||
status = "pending",
|
||||
progress = 0
|
||||
}
|
||||
end
|
||||
|
||||
---Convert Markdown to PDF
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for PDF output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
---Convert Markdown to HTML
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for HTML output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_html(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "html", options)
|
||||
end
|
||||
|
||||
---Convert Markdown to DOCX
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for DOCX output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_docx(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "docx", options)
|
||||
end
|
||||
|
||||
---Convert HTML to PDF
|
||||
---@param input_path string Path to HTML file
|
||||
---@param output_path? string Path for PDF output
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.html_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
---Convert DOCX to PDF
|
||||
---@param input_path string Path to DOCX file
|
||||
---@param output_path? string Path for PDF output
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.docx_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -23,255 +23,28 @@
|
||||
---@field markdown_to_html fun(input_path: string, output_path?: string, options?: DocumentConvertOptions): DocumentJob|nil, string?
|
||||
---@field markdown_to_docx fun(input_path: string, output_path?: string, options?: DocumentConvertOptions): DocumentJob|nil, string?
|
||||
---@field get_supported_formats fun(): table
|
||||
|
||||
-- Unified document helpers module - combines format definitions and conversion
|
||||
local formats = require("lua.document_formats")
|
||||
local converter = require("lua.document_converter")
|
||||
|
||||
local M = {}
|
||||
|
||||
local config = {
|
||||
base_url = "http://localhost:8090"
|
||||
}
|
||||
-- Re-export format functions
|
||||
M.get_input_formats = formats.get_input_formats
|
||||
M.get_output_formats = formats.get_output_formats
|
||||
M.get_supported_formats = formats.get_supported_formats
|
||||
M.supports_conversion = formats.supports_conversion
|
||||
M.get_format_name = formats.get_format_name
|
||||
M.get_format_icon = formats.get_format_icon
|
||||
|
||||
---Configure the helper
|
||||
---@param opts table Configuration options
|
||||
function M.configure(opts)
|
||||
if opts.base_url then config.base_url = opts.base_url end
|
||||
end
|
||||
|
||||
---Get supported input formats
|
||||
---@return string[] formats List of input formats
|
||||
function M.get_input_formats()
|
||||
return {
|
||||
"md", "markdown", "gfm", "commonmark",
|
||||
"html", "htm",
|
||||
"tex", "latex",
|
||||
"docx", "odt",
|
||||
"rst", "org", "txt",
|
||||
"json", "yaml"
|
||||
}
|
||||
end
|
||||
|
||||
---Get supported output formats
|
||||
---@return string[] formats List of output formats
|
||||
function M.get_output_formats()
|
||||
return {
|
||||
"pdf", "html", "html5",
|
||||
"docx", "odt", "rtf",
|
||||
"epub", "epub3",
|
||||
"latex", "beamer",
|
||||
"markdown", "gfm",
|
||||
"plain", "json"
|
||||
}
|
||||
end
|
||||
|
||||
---Get supported format conversions as a table
|
||||
---@return table formats { input = {...}, output = {...} }
|
||||
function M.get_supported_formats()
|
||||
return {
|
||||
input = M.get_input_formats(),
|
||||
output = M.get_output_formats()
|
||||
}
|
||||
end
|
||||
|
||||
---Check if a conversion is supported
|
||||
---@param from_format DocumentFormat Input format
|
||||
---@param to_format DocumentFormat Output format
|
||||
---@return boolean supported Whether conversion is supported
|
||||
function M.supports_conversion(from_format, to_format)
|
||||
local input_formats = M.get_input_formats()
|
||||
local output_formats = M.get_output_formats()
|
||||
|
||||
local input_ok = false
|
||||
for _, fmt in ipairs(input_formats) do
|
||||
if fmt == from_format then
|
||||
input_ok = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local output_ok = false
|
||||
for _, fmt in ipairs(output_formats) do
|
||||
if fmt == to_format then
|
||||
output_ok = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return input_ok and output_ok
|
||||
end
|
||||
|
||||
---Generate output path from input path
|
||||
---@param input_path string Input file path
|
||||
---@param output_format string Output format extension
|
||||
---@return string output_path Generated output path
|
||||
local function generate_output_path(input_path, output_format)
|
||||
-- Remove extension and add new one
|
||||
local base = input_path:match("(.+)%.[^%.]+$") or input_path
|
||||
return base .. "." .. output_format
|
||||
end
|
||||
|
||||
---Convert a document
|
||||
---@param input_path string Path to input file
|
||||
---@param output_format DocumentFormat Target format
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.convert(input_path, output_format, options)
|
||||
if not input_path or input_path == "" then
|
||||
return nil, "Input path is required"
|
||||
end
|
||||
|
||||
if not output_format or output_format == "" then
|
||||
return nil, "Output format is required"
|
||||
end
|
||||
|
||||
options = options or {}
|
||||
|
||||
local output_path = options.output_path or generate_output_path(input_path, output_format)
|
||||
|
||||
-- Build request body
|
||||
local body = {
|
||||
type = "document_convert",
|
||||
params = {
|
||||
input_path = input_path,
|
||||
output_path = output_path,
|
||||
output_format = output_format,
|
||||
variables = {}
|
||||
},
|
||||
notify_user = true
|
||||
}
|
||||
|
||||
-- Add options as variables
|
||||
if options.toc then
|
||||
body.params.variables.toc = "true"
|
||||
end
|
||||
if options.template then
|
||||
body.params.template_path = options.template
|
||||
end
|
||||
if options.title then
|
||||
body.params.variables.title = options.title
|
||||
end
|
||||
if options.author then
|
||||
body.params.variables.author = options.author
|
||||
end
|
||||
if options.date then
|
||||
body.params.variables.date = options.date
|
||||
end
|
||||
if options.paper_size then
|
||||
body.params.variables.papersize = options.paper_size
|
||||
end
|
||||
if options.margin then
|
||||
body.params.variables["geometry:margin"] = options.margin
|
||||
end
|
||||
|
||||
-- HTTP POST /api/jobs would go here
|
||||
-- Return mock response for now
|
||||
return {
|
||||
id = "doc_" .. tostring(os.time()),
|
||||
status = "pending",
|
||||
progress = 0
|
||||
}
|
||||
end
|
||||
|
||||
---Convert Markdown to PDF
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for PDF output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
---Convert Markdown to HTML
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for HTML output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_html(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "html", options)
|
||||
end
|
||||
|
||||
---Convert Markdown to DOCX
|
||||
---@param input_path string Path to markdown file
|
||||
---@param output_path? string Path for DOCX output (auto-generated if nil)
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.markdown_to_docx(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "docx", options)
|
||||
end
|
||||
|
||||
---Convert HTML to PDF
|
||||
---@param input_path string Path to HTML file
|
||||
---@param output_path? string Path for PDF output
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.html_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
---Convert DOCX to PDF
|
||||
---@param input_path string Path to DOCX file
|
||||
---@param output_path? string Path for PDF output
|
||||
---@param options? DocumentConvertOptions Conversion options
|
||||
---@return DocumentJob|nil job Job info if successful
|
||||
---@return string? error Error message if failed
|
||||
function M.docx_to_pdf(input_path, output_path, options)
|
||||
options = options or {}
|
||||
options.output_path = output_path
|
||||
return M.convert(input_path, "pdf", options)
|
||||
end
|
||||
|
||||
---Get format display name
|
||||
---@param format string Format code
|
||||
---@return string name Display name
|
||||
function M.get_format_name(format)
|
||||
local names = {
|
||||
md = "Markdown",
|
||||
markdown = "Markdown",
|
||||
gfm = "GitHub Flavored Markdown",
|
||||
html = "HTML",
|
||||
htm = "HTML",
|
||||
pdf = "PDF",
|
||||
docx = "Word Document",
|
||||
odt = "OpenDocument Text",
|
||||
rtf = "Rich Text Format",
|
||||
epub = "EPUB",
|
||||
latex = "LaTeX",
|
||||
tex = "LaTeX",
|
||||
rst = "reStructuredText",
|
||||
org = "Org-mode",
|
||||
txt = "Plain Text",
|
||||
json = "JSON",
|
||||
yaml = "YAML"
|
||||
}
|
||||
return names[format] or format:upper()
|
||||
end
|
||||
|
||||
---Get format icon name (for UI)
|
||||
---@param format string Format code
|
||||
---@return string icon MUI icon name
|
||||
function M.get_format_icon(format)
|
||||
local icons = {
|
||||
md = "Description",
|
||||
markdown = "Description",
|
||||
html = "Code",
|
||||
pdf = "PictureAsPdf",
|
||||
docx = "Article",
|
||||
odt = "Article",
|
||||
epub = "MenuBook",
|
||||
latex = "Functions",
|
||||
tex = "Functions"
|
||||
}
|
||||
return icons[format] or "InsertDriveFile"
|
||||
end
|
||||
-- Re-export converter functions
|
||||
M.configure = converter.configure
|
||||
M.convert = converter.convert
|
||||
M.markdown_to_pdf = converter.markdown_to_pdf
|
||||
M.markdown_to_html = converter.markdown_to_html
|
||||
M.markdown_to_docx = converter.markdown_to_docx
|
||||
M.html_to_pdf = converter.html_to_pdf
|
||||
M.docx_to_pdf = converter.docx_to_pdf
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
--- Scene management facade
|
||||
--- Re-exports single-function modules for backward compatibility
|
||||
---@module scenes
|
||||
|
||||
---@class ScenesModule
|
||||
---@field render_scene fun(scene: table): string Render single scene
|
||||
---@field render_list fun(scenes: table[]): string Render scene list
|
||||
---@field switch fun(scene_id: string): boolean Switch to scene
|
||||
---@field create fun(scene: table): string Create new scene
|
||||
local M = {}
|
||||
|
||||
M.render_scene = require("render_scene")
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
--- Stream scheduling facade
|
||||
--- Re-exports single-function modules for backward compatibility
|
||||
---@module schedule
|
||||
|
||||
---@class ScheduleModule
|
||||
---@field render_item fun(item: table): string Render schedule item
|
||||
---@field render_list fun(items: table[]): string Render schedule list
|
||||
---@field create fun(stream: table): string Schedule new stream
|
||||
---@field cancel fun(stream_id: string): boolean Cancel scheduled stream
|
||||
local M = {}
|
||||
|
||||
M.render_item = require("render_schedule_item")
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
-- Level 6 layout module facade
|
||||
-- Re-exports all supergod layout functions for backward compatibility
|
||||
--- Level 6 layout module facade
|
||||
--- Re-exports all supergod layout functions for backward compatibility
|
||||
---@module layout.init
|
||||
|
||||
---@class Level6LayoutModule
|
||||
---@field supergod_sidebar fun(): string Render supergod sidebar
|
||||
---@field supergod_toolbar fun(): string Render supergod toolbar
|
||||
---@field supergod_content fun(content: string): string Render supergod content area
|
||||
local M = {}
|
||||
|
||||
M.supergod_sidebar = require("layout.supergod_sidebar")
|
||||
|
||||
Reference in New Issue
Block a user