ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 12m19s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / checks (push) Failing after 23m57s
ci / release (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: failure
GitHub / darwin arm64 native GitHub-hosted native CI: failure
GitHub / darwin amd64 native GitHub-hosted native CI: failure
GitHub / linux amd64 native GitHub-hosted native CI: success
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package artedit
|
|
|
|
import "aego/art"
|
|
|
|
// PreviewRevision is monotonically increasing for this binding, including a
|
|
// recovery that replaces its Document. A new Document's revision starts again
|
|
// at one, so publishing solely by that revision would accept pre-recovery jobs.
|
|
func (b *Document) PreviewRevision() uint64 {
|
|
if b.closed || b.Session == nil {
|
|
return 0
|
|
}
|
|
d := b.Session.Document
|
|
r := d.Revision()
|
|
if b.previewDocument != d || b.previewArtRevision != r {
|
|
b.previewDocument, b.previewArtRevision = d, r
|
|
b.previewRevision++
|
|
}
|
|
return b.previewRevision
|
|
}
|
|
|
|
func (b *Document) PreviewCurrent(revision uint64) bool {
|
|
return !b.closed && b.Asset.Binding.Model == b && revision != 0 && b.PreviewRevision() == revision
|
|
}
|
|
|
|
func (b *Document) PreviewSnapshot() ([]byte, uint64, error) {
|
|
if b.closed {
|
|
return nil, 0, art.ErrClosed
|
|
}
|
|
revision := b.PreviewRevision()
|
|
d := b.Session.Document
|
|
snapshot, err := d.Snapshot()
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
data, err := snapshot.Encode()
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if d != b.Session.Document || d.Revision() != snapshot.Revision() || !b.PreviewCurrent(revision) {
|
|
return nil, 0, art.ErrConflict
|
|
}
|
|
return data, revision, nil
|
|
}
|