Documentation ¶
Overview ¶
Document structs can either point to a url reference where the pdf is stored, or contain a blob of the data itself. The blob is compressed with zlib and then wrapped in Base64. These functions convert the encoded string to a []byte containing the pdf.
Package job provides the Job type and some methods on it. TODO caching s3 connection objects in a pool might speed things up. TODO use callback interface for different types of success notifications (e.g. command line and URL callbacks)
The downloaded docs list is generated in parallel, so it's not ordered correctly. These are functions to sort it in order of the original input.
Index ¶
- type Bookmark
- type BookmarkList
- type ByIndex
- type Document
- type Documents
- type Job
- func (j *Job) AddError(newErr error)
- func (j *Job) Cleanup()
- func (j *Job) CleanupBrokenDocs()
- func (j *Job) CombinedBookmarkList() string
- func (j *Job) CombinedTitle() string
- func (j *Job) CompleteCount() int
- func (j *Job) ComponentPaths() (paths []string)
- func (j *Job) Content() io.Reader
- func (j *Job) Dir() string
- func (j *Job) DocCount() int
- func (j *Job) DocsAreValid() bool
- func (j *Job) HasDownloadedDocs() bool
- func (j *Job) Id() string
- func (j *Job) IsSuccessful() bool
- func (j *Job) IsValid() bool
- func (j *Job) LocalPath() string
- func (j *Job) MarkComplete(doc *Document)
- func (j *Job) Recipient() string
- func (j *Job) SortDownloaded()
- func (j *Job) ToJSON() (jsonResponse []byte)
- func (j *Job) UploadCombinedFile() (err error)
- type JobResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BookmarkList ¶
type BookmarkList struct {
// contains filtered or unexported fields
}
func ExtractBookmarks ¶
func ExtractBookmarks(cmd cpdf.InfoCmd) (bookmarks BookmarkList, err error)
func (BookmarkList) InCombinedContext ¶
func (l BookmarkList) InCombinedContext(title string, offset int) (newBm BookmarkList)
InCombinedContext returns a new BookmarkList representing the document's bookmarks as they would appear in the context of a combined document. That is, a new level-0 bookmark is added with all existing bookmarks as children, and all pages are offset by the document's start position.
func (BookmarkList) String ¶
func (l BookmarkList) String() string
type Document ¶
type Document struct { Key string `json:"key"` Title string `json:"title"` Data string `json:"data,omitempty"` PageCount int `json:"page_count"` FileSize int `json:"file_size"` Bookmarks BookmarkList `json:"-"` // contains filtered or unexported fields }
A Document is a reference to one part of a combined PDF. it is is identified by its Key field, which is required. It can also have a Title, used for TOC bookmarks in the final combined document. The actual PDF data comes from one of two places:
- If the Data field is empty, the Key is treated as a S3 key that is fetched from the enclosing job's bucket.
- If the Data field is nonempty, it must contain a zlib-compressed and Base64-encoded string containing the PDF.
The bookmarks field is filled in by processing and is not serialized.
type Job ¶
type Job struct { BucketName string `json:"bucket_name"` DocList []Document `json:"doc_list"` Downloaded Documents `json:"downloaded"` CombinedKey string `json:"combined_key"` Title string `json:"title,omitempty"` Callback string `json:"callback"` Errors []error `json:"errors"` DequeuedAt time.Time DownloadsDoneAt time.Time // contains filtered or unexported fields }
A Job includes all the data necessary to execute a pdf combination. It is mainly constructed from a JSON string in a HTTP request, but the last two fields contain internal state.
func NewFromJSON ¶
NewFromJSON constructs a Job from an io.Reader containing JSON conforming to the required portion of the Job schema.
func (*Job) CleanupBrokenDocs ¶
func (j *Job) CleanupBrokenDocs()
For every doc that failed for whatever reason, replace it with a page containing an error message.
func (*Job) CombinedBookmarkList ¶
func (*Job) CombinedTitle ¶
Title returns the title of the document
func (*Job) CompleteCount ¶
CompleteCount returns the number of documents actually completed.
func (*Job) ComponentPaths ¶
Get the absolute paths to the completed docs.
func (*Job) DocsAreValid ¶
func (*Job) HasDownloadedDocs ¶
HasDownloadedDocs determines whether any documents been successfully downloaded.
func (*Job) IsSuccessful ¶
In test mode, randomly fail 10% of the time.
func (*Job) IsValid ¶
IsValid determines whether the job contains all the fields necessary to start the combination.
func (*Job) MarkComplete ¶
MarkComplete adds a document to the list of downloaded docs. TODO should be a Document.
func (*Job) SortDownloaded ¶
func (j *Job) SortDownloaded()
SortDownloaded ensures that the Downloaded list is in the correct order.
func (*Job) UploadCombinedFile ¶
UploadCombinedFile sends a file to the job's CombinedKey on S3.
type JobResponse ¶
type JobResponse struct { Success bool `json:"success"` Errors []string `json:"errors"` Downloaded []*Document `json:"downloaded"` Times metrics `json:"times"` }
A JobResponse is sent as a notification -- it includes the success status as well as a subset of the job fields.