session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package session 管理阅读器的文档生命周期和有界页面渲染。

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("阅读会话已经关闭")
View Source
var ErrStaleDocument = errors.New("文档已关闭或已切换")

Functions

This section is empty.

Types

type AnnotationReport

type AnnotationReport struct {
	Items     []reader.AnnotationInfo `json:"items"`
	Scanned   int                     `json:"scanned"`
	Truncated bool                    `json:"truncated"`
}

AnnotationReport 是有界注解扫描的结果;Truncated 表示可能还有未扫描的注解。

type OpenResult

type OpenResult struct {
	Pages       []reader.PageInfo            `json:"pages"`
	PagePrefix  string                       `json:"page_prefix"`
	Permissions []reader.DocumentPermissions `json:"permissions"`
}

OpenResult 是宿主打开文档后向前端返回的页面快照和预览路径。

type Options

type Options struct {
	Reader               reader.OpenOptions
	MaxConcurrentRenders int
}

Options 配置单个文档会话。MaxConcurrentRenders 为零时使用默认值,最大为 32。

type PageHandler

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

PageHandler 为单个会话提供预览图片;不监听网络,由宿主挂载到受信任的资源服务。 路径中含随机能力标识,宿主仍须限制导航和不可信内容对处理器的访问。

func NewPageHandler

func NewPageHandler(session *Session) (*PageHandler, error)

NewPageHandler 创建带随机路径的会话图片处理器。

func (*PageHandler) Prefix

func (h *PageHandler) Prefix() string

Prefix 返回本会话的页面路径前缀,末尾包含斜杠;后接零起始页码。

func (*PageHandler) ServeHTTP

func (h *PageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 返回指定页的 PNG、JPG 或 SVG。purpose 可指定 export 或 print, 相应权限由 Reader 在实际渲染时检查;不指定时只允许预览。

type PlaybackPreview

type PlaybackPreview struct {
	MIME string `json:"mime"`
	Data []byte `json:"data"`
}

PlaybackPreview 只包含受限的包内媒体,不含网络地址或播放列表。

type Service

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

Service 管理一个当前文档;资源处理器可直接挂载到宿主的资源服务。 Open 的输入由宿主提供,不应将任意文件路径直接暴露给不可信前端。

func (*Service) Annotations

func (s *Service) Annotations(ctx context.Context, prefix string) (AnnotationReport, error)

Annotations 有界扫描指定会话的注解。

func (*Service) AnnotationsForPage

func (s *Service) AnnotationsForPage(ctx context.Context, prefix string, index int) ([]reader.AnnotationInfo, error)

AnnotationsForPage 查询指定会话单页的注解。

func (*Service) AttachmentData

func (s *Service) AttachmentData(ctx context.Context, prefix string, scope int, id string) ([]byte, error)

AttachmentData 为原生保存操作读取指定会话的受限附件。

func (*Service) AttachmentImagePreview

func (s *Service) AttachmentImagePreview(ctx context.Context, prefix string, scope int, id string) (preview.Image, error)

AttachmentImagePreview 按导出权限读取附件图像,额外格式以静态 PNG 返回。

func (*Service) AttachmentPlayback

func (s *Service) AttachmentPlayback(ctx context.Context, prefix string, scope int, id string) (PlaybackPreview, error)

AttachmentPlayback 按导出权限读取附件中的受限音视频。

func (*Service) AttachmentTextPreview

func (s *Service) AttachmentTextPreview(ctx context.Context, prefix string, scope int, id string) (string, error)

AttachmentTextPreview 读取当前指定会话的受限文本附件。

func (*Service) Attachments

func (s *Service) Attachments(ctx context.Context, prefix string) ([]reader.AttachmentInfo, error)

Attachments 查询指定会话的附件声明。

func (*Service) CheckDocumentPermission

func (s *Service) CheckDocumentPermission(prefix string, scope int, action reader.PermissionAction) error

CheckDocumentPermission 检查指定会话的文档体权限,不依赖页面列表或前端快照。

func (*Service) CheckPermission

func (s *Service) CheckPermission(prefix string, action reader.PermissionAction, indices []int) error

CheckPermission 在操作执行前重新检查当前会话的页面权限。

func (*Service) Close

func (s *Service) Close() error

Close 撤销当前文档的资源地址,取消并等待渲染,并释放文档。 Close 后可以重新打开文档。

func (*Service) CloseCurrent

func (s *Service) CloseCurrent(prefix string) error

CloseCurrent 仅关闭指定地址对应的文档,避免过期请求关闭新文档。

func (*Service) CustomTags

func (s *Service) CustomTags(ctx context.Context, prefix string) ([]reader.CustomTagTree, error)

CustomTags 返回指定会话的标签快照,不进行前端字段转换。

func (*Service) FontList

func (s *Service) FontList(prefix string) ([]reader.FontInfo, error)

FontList 查询指定会话的字体声明。

func (*Service) FontUsage

func (s *Service) FontUsage(ctx context.Context, prefix string, ref reader.FontRef, options reader.FontUsageOptions) (reader.FontUsage, error)

FontUsage 查询指定会话中某字体的使用页。

func (*Service) FontUsageAll

func (s *Service) FontUsageAll(ctx context.Context, prefix string, options reader.FontUsageOptions) (reader.FontUsageReport, error)

FontUsageAll 查询指定会话的批量字体使用页。

func (*Service) Info

Info 查询指定会话的元数据和权限快照。

func (*Service) Layers

func (s *Service) Layers(ctx context.Context, prefix string, index int) ([]reader.LayerInfo, error)

Layers 查询指定会话单页的图层。

func (*Service) Media

func (s *Service) Media(ctx context.Context, prefix string) ([]reader.MediaInfo, error)

Media 查询指定会话的多媒体声明。

func (*Service) MediaExportData

func (s *Service) MediaExportData(ctx context.Context, prefix string, scope int, id uint64) ([]byte, error)

MediaExportData 为原生保存操作读取指定会话的资源,并检查导出权限。

func (*Service) MediaImagePreview

func (s *Service) MediaImagePreview(ctx context.Context, prefix string, scope int, id uint64) (preview.Image, error)

MediaImagePreview 读取指定会话中的受限图片预览。

func (*Service) MediaPlayback

func (s *Service) MediaPlayback(ctx context.Context, prefix string, scope int, id, templateID uint64) (PlaybackPreview, error)

MediaPlayback 按访问权限读取受限的包内音视频,支持模板独立资源视图。

func (*Service) MediaThumbnail

func (s *Service) MediaThumbnail(ctx context.Context, prefix string, scope int, id uint64) (preview.Thumbnail, error)

MediaThumbnail 读取指定会话的有界资源缩略图。

func (*Service) Open

func (s *Service) Open(input any, options Options) (OpenResult, error)

Open 打开普通文档或已解锁的只读视图;打开或读取页面失败时,保留原有文档。 成功替换时先撤销旧资源路径,取消旧渲染并等待释放,再发布新文档。 历史版本切换需要可重复打开的 input(字节、路径或仍由宿主持有的解密视图)。

func (*Service) Outline

func (s *Service) Outline(prefix string) (reader.OutlineTree, error)

Outline 返回指定会话的大纲;旧会话地址不能读取新文档。

func (*Service) Page

func (s *Service) Page(prefix string, index int) (reader.PageInfo, error)

Page 查询指定会话的页面尺寸。旧地址不会访问新文档。

func (*Service) PageLinksForPage

func (s *Service) PageLinksForPage(ctx context.Context, prefix string, index int) ([]reader.PageLink, error)

PageLinksForPage 查询指定会话单页的链接。

func (*Service) Permissions

func (s *Service) Permissions(prefix string) ([]reader.DocumentPermissions, error)

Permissions 返回当前会话的文档体权限快照。

func (*Service) Preferences

func (s *Service) Preferences(prefix string) (reader.ViewPreferences, error)

Preferences 查询指定会话的显示偏好。

func (*Service) RenderPDF

func (s *Service) RenderPDF(ctx context.Context, prefix string, output io.Writer, indices []int, options reader.RenderOptions) error

RenderPDF 为宿主导出选定页面的矢量 PDF。

func (*Service) RenderPage

func (s *Service) RenderPage(ctx context.Context, prefix string, output io.Writer, index int, options reader.RenderOptions) error

RenderPage 为原生保存等宿主操作渲染指定会话的一页。

func (*Service) Search

func (s *Service) Search(ctx context.Context, prefix, query string, options reader.SearchOptions) (reader.SearchReport, error)

Search 搜索指定会话;旧会话地址不能访问新文档。

func (*Service) SelectVersion

func (s *Service) SelectVersion(prefix string, scope int, id string) (OpenResult, error)

SelectVersion 先独立准备目标版本;失败保留当前会话,成功才撤销旧地址。 发布属于不可撤销的状态写入,调用方应等待真实结果,不能仅取消前端 Promise。

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 仅分发当前文档的预览地址,不提供其他文件访问。

func (*Service) SetHiddenLayers

func (s *Service) SetHiddenLayers(prefix string, index int, ids []string) error

SetHiddenLayers 更新指定会话的图层,过期会话不能修改新文档。

func (*Service) SignatureCertificate

func (s *Service) SignatureCertificate(ctx context.Context, prefix string, scope int, id, slot string) ([]byte, error)

SignatureCertificate 读取指定会话中的证书 DER,不将二进制数据交给网页。

func (*Service) SignatureDetails

func (s *Service) SignatureDetails(ctx context.Context, prefix string) ([]reader.SignatureInfo, error)

SignatureDetails 查询指定会话的签名验证明细。

func (*Service) SignatureSealPreview

func (s *Service) SignatureSealPreview(ctx context.Context, prefix string, scope int, id string, stampIndex int) (preview.Image, error)

SignatureSealPreview 查询指定会话的受限印章图片预览,旧会话不能访问新文档。

func (*Service) SignatureSealThumbnail

func (s *Service) SignatureSealThumbnail(ctx context.Context, prefix string, scope int, id string, index int) (preview.Thumbnail, error)

SignatureSealThumbnail 读取指定会话的有界印章缩略图。

func (*Service) SignatureSummaries

func (s *Service) SignatureSummaries(ctx context.Context, prefix string) ([]SignatureSummary, error)

SignatureSummaries 查询指定会话的签名声明。

func (*Service) SignatureValue

func (s *Service) SignatureValue(ctx context.Context, prefix string, scope int, id string) ([]byte, error)

SignatureValue 读取指定会话中的签名值,不将二进制数据交给网页。

func (*Service) Stats

func (s *Service) Stats(prefix string) (reader.DocumentStats, error)

Stats 查询指定会话的资源声明统计。

func (*Service) Text

func (s *Service) Text(prefix string, index int) ([]reader.TextRun, error)

Text 返回指定会话的文字;权限检查由 Reader 执行。

func (*Service) Versions

func (s *Service) Versions(ctx context.Context, prefix string) ([]reader.VersionInfo, error)

Versions 返回指定会话的版本快照,不进行前端字段转换。

type Session

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

Session 持有一个文档,关闭时取消渲染并等待所有操作退出。

func Open

func Open(input any, options Options) (*Session, error)

Open 打开普通文档或已解锁的只读视图。input 的支持类型和资源所有权与 reader.Open 相同。

func (*Session) Annotations

func (s *Session) Annotations(ctx context.Context) (AnnotationReport, error)

Annotations 扫描最多 2000 页、返回最多 5000 条注解;取消或出错时不返回部分结果。

func (*Session) AnnotationsForPage

func (s *Session) AnnotationsForPage(ctx context.Context, index int) ([]reader.AnnotationInfo, error)

AnnotationsForPage 使用有界的逐页元数据名额。取消发生在读取期间时丢弃结果。

func (*Session) AttachmentData

func (s *Session) AttachmentData(ctx context.Context, scope int, id string) ([]byte, error)

AttachmentData 在导出权限检查后读取附件,供原生宿主保存,最多 64 MiB。

func (*Session) AttachmentTextPreview

func (s *Session) AttachmentTextPreview(ctx context.Context, scope int, id string) (string, error)

AttachmentTextPreview 按导出权限读取至多 1 MiB 的 UTF-8 文本,不解析标记或执行内容。

func (*Session) Attachments

func (s *Session) Attachments(ctx context.Context) ([]reader.AttachmentInfo, error)

Attachments 返回附件清单快照,不读取附件内容;取消后丢弃正在读取的结果。

func (*Session) CheckPermission

func (s *Session) CheckPermission(action reader.PermissionAction, indices []int) error

CheckPermission 按当前时间检查所选页面的操作权限。

func (*Session) Close

func (s *Session) Close() error

Close 取消进行中的渲染,等待操作退出并释放文档;可并发和重复调用。

func (*Session) CustomTags

func (s *Session) CustomTags(ctx context.Context) ([]reader.CustomTagTree, error)

CustomTags 按有界后台名额读取标签;取消后不发布迟到结果。

func (*Session) FontList

func (s *Session) FontList() ([]reader.FontInfo, error)

FontList 返回字体声明,不读取或传输字体文件。

func (*Session) FontUsage

func (s *Session) FontUsage(ctx context.Context, ref reader.FontRef, options reader.FontUsageOptions) (reader.FontUsage, error)

FontUsage 统计指定字体的使用页;与搜索共享单个后台扫描名额。

func (*Session) FontUsageAll

func (s *Session) FontUsageAll(ctx context.Context, options reader.FontUsageOptions) (reader.FontUsageReport, error)

FontUsageAll 批量统计字体使用页;会话关闭时取消扫描。

func (*Session) Info

Info 返回文档元数据和权限快照。

func (*Session) Layers

func (s *Session) Layers(ctx context.Context, index int) ([]reader.LayerInfo, error)

Layers 按需读取单页图层,取消或关闭时丢弃结果。

func (*Session) Media

func (s *Session) Media(ctx context.Context) ([]reader.MediaInfo, error)

Media 返回多媒体声明的独立快照,不读取资源内容。

func (*Session) MediaExportData

func (s *Session) MediaExportData(ctx context.Context, scope int, id uint64) ([]byte, error)

MediaExportData 读取供原生保存的资源;预览权限不能代替导出权限。

func (*Session) MediaImagePreview

func (s *Session) MediaImagePreview(ctx context.Context, scope int, id uint64) (preview.Image, error)

MediaImagePreview 读取不超过 8 MiB、2500 万像素的光栅图片;额外格式返回静态 PNG。

func (*Session) MediaThumbnail

func (s *Session) MediaThumbnail(ctx context.Context, scope int, id uint64) (preview.Thumbnail, error)

MediaThumbnail 在读取前后检查访问权限,最多同时处理两张资源或印章缩略图。

func (*Session) Outline

func (s *Session) Outline() (reader.OutlineTree, error)

Outline 返回当前文档的大纲与书签快照。

func (*Session) Page

func (s *Session) Page(index int) (reader.PageInfo, error)

Page 查询指定页的完整尺寸信息。

func (*Session) PageLinksForPage

func (s *Session) PageLinksForPage(ctx context.Context, index int) ([]reader.PageLink, error)

PageLinksForPage 按需读取一页链接,关闭或取消时不返回结果。

func (*Session) Pages

func (s *Session) Pages() ([]reader.PageInfo, error)

Pages 返回页面尺寸快照,单位为毫米。

func (*Session) Permissions

func (s *Session) Permissions() ([]reader.DocumentPermissions, error)

Permissions 返回权限快照;有效期相关授权必须在执行操作时重新检查。

func (*Session) Preferences

func (s *Session) Preferences() (reader.ViewPreferences, error)

Preferences 返回文档声明的显示偏好。

func (*Session) RenderPDF

func (s *Session) RenderPDF(ctx context.Context, output io.Writer, indices []int, options reader.RenderOptions) error

RenderPDF 与页面图片共用有界渲染名额;取消或出错时 output 可能包含部分数据,调用方应丢弃。

func (*Session) RenderPage

func (s *Session) RenderPage(ctx context.Context, output io.Writer, index int, options reader.RenderOptions) error

RenderPage 渲染单页;取消或出错时 output 可能包含部分数据,调用方应丢弃。 排队及渲染都受 ctx 和会话关闭控制,底层绘制的取消粒度由 reader.RenderPage 决定。

func (*Session) Search

func (s *Session) Search(ctx context.Context, query string, options reader.SearchOptions) (reader.SearchReport, error)

Search 执行有界搜索;关闭会话时取消排队和运行中的搜索。

func (*Session) SetHiddenLayers

func (s *Session) SetHiddenLayers(index int, ids []string) error

SetHiddenLayers 原子更新页面显示状态;关闭会等待已经开始的更新完成。

func (*Session) SignatureCertificate

func (s *Session) SignatureCertificate(ctx context.Context, scope int, id, slot string) ([]byte, error)

SignatureCertificate 为宿主保存读取证书 DER,额外检查所属文档体的导出权限。

func (*Session) SignatureDetails

func (s *Session) SignatureDetails(ctx context.Context) ([]reader.SignatureInfo, error)

SignatureDetails 返回解析器已有的签名验证明细;未执行的检查保留未完成状态。

func (*Session) SignatureSealPreview

func (s *Session) SignatureSealPreview(ctx context.Context, scope int, id string, stampIndex int) (preview.Image, error)

SignatureSealPreview 按所属文档体的访问权限读取原始印章图片;不代表验签结论。 PNG/JPEG 检查原图;OFD 子文档第一页渲染为长边最多 2048 像素的 PNG。

func (*Session) SignatureSealThumbnail

func (s *Session) SignatureSealThumbnail(ctx context.Context, scope int, id string, index int) (preview.Thumbnail, error)

SignatureSealThumbnail 生成印章缩略图,不复用签名清单的权限快照。

func (*Session) SignatureSummaries

func (s *Session) SignatureSummaries(ctx context.Context) ([]SignatureSummary, error)

SignatureSummaries 返回签名声明和位置,不执行或输出验签结果。

func (*Session) SignatureValue

func (s *Session) SignatureValue(ctx context.Context, scope int, id string) ([]byte, error)

SignatureValue 为宿主保存读取签名值,额外检查所属文档体的导出权限。

func (*Session) Stats

func (s *Session) Stats() (reader.DocumentStats, error)

Stats 返回文档声明资源数量,并在会话关闭前保持读取有效。

func (*Session) Text

func (s *Session) Text(index int) ([]reader.TextRun, error)

Text 返回文字快照;底层 Reader 在读取前检查复制权限。

func (*Session) Versions

func (s *Session) Versions(ctx context.Context) ([]reader.VersionInfo, error)

Versions 返回当前会话可用的历史版本。

type SignatureStampSummary

type SignatureStampSummary struct {
	ID              string                     `json:"id"`
	Page            int                        `json:"page"`
	Boundary        *reader.AnnotationBoundary `json:"boundary"`
	VisibleBoundary *reader.AnnotationBoundary `json:"visible_boundary"`
}

SignatureStampSummary 是签章声明的位置,不包含印章数据或验签结果。

type SignatureSummary

type SignatureSummary struct {
	Scope    int                     `json:"scope"`
	ID       string                  `json:"id"`
	Provider string                  `json:"provider"`
	Company  string                  `json:"company"`
	Version  string                  `json:"version"`
	Method   string                  `json:"method"`
	Date     string                  `json:"date"`
	Stamps   []SignatureStampSummary `json:"stamps"`
}

SignatureSummary 仅包含签名声明,不代表任何验签结论。

Jump to

Keyboard shortcuts

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