mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-19 02:26:48 +00:00
M12: a postSign step that fails after signing is reported, and the signing stands
This commit is contained in:
1 parent
3eefcd5719
commit
9b8ae111b5
2 files changed
+14
-7
No files matched your search
@@ -309,11 +309,16 @@ impl Automation {
|
||||
let path = out.to_string_lossy().into_owned();
|
||||
self.session.mark_signed(doc_id, signed.clone(), Some(path.clone())).map_err(failed)?;
|
||||
// Then its postSign scripts; what they change is a change after signing, not saved yet.
|
||||
let after = match &signing {
|
||||
Some(f) if run_scripts => self.session.run_sign_event(doc_id, f, SignEvent::After).map_err(failed)?,
|
||||
_ => false,
|
||||
// The file is signed and saved by now: a postSign step that fails is reported, not an error.
|
||||
let (after, after_error) = match &signing {
|
||||
Some(f) if run_scripts => match self.session.run_sign_event(doc_id, f, SignEvent::After) {
|
||||
Ok(ran) => (ran, None),
|
||||
Err(e) => (true, Some(format!("the postSign step couldn't finish: {e}"))),
|
||||
},
|
||||
_ => (false, None),
|
||||
};
|
||||
let scripts = self.session.take_js_output(doc_id);
|
||||
let mut scripts = self.session.take_js_output(doc_id);
|
||||
scripts.errors.extend(after_error);
|
||||
let doc = self.doc(a)?;
|
||||
let newest = doc.signatures.iter().filter(|s| s.signed).max_by_key(|s| s.revision).cloned();
|
||||
let mut result = json!({ "path": path, "bytes": signed.len(), "signature": newest.map(|s| self.sig_json(a, &s)).transpose()? });
|
||||
|
||||
@@ -527,9 +527,8 @@ impl PdfCraftApp {
|
||||
app.session.mark_signed(doc_id, signed, Some(path.to_string_lossy().into_owned())).map_err(|e| e.to_string())?;
|
||||
// Then its postSign scripts; what they change is a change after signing, to save.
|
||||
// What they say shows once signing is done, after the notice that it was saved.
|
||||
if let Some(f) = &field {
|
||||
app.session.run_sign_event(doc_id, f, pdfcraft_engine::js::SignEvent::After).map_err(|e| e.to_string())?;
|
||||
}
|
||||
// The file is signed and saved by now: a postSign step that fails is said, not a failure.
|
||||
let after = field.as_deref().and_then(|f| app.session.run_sign_event(doc_id, f, pdfcraft_engine::js::SignEvent::After).err());
|
||||
let said = app.session.take_js_output(doc_id);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::macos_association::repair(&path);
|
||||
@@ -540,6 +539,9 @@ impl PdfCraftApp {
|
||||
app.right = Some(crate::RightPanel::Signatures);
|
||||
app.notify_fmt("Signed and saved to {path}", &[("path", &path.display().to_string())]);
|
||||
app.handle_js(doc_id, said);
|
||||
if let Some(e) = after {
|
||||
app.notify_fmt("Signed and saved, but the form's postSign script couldn't finish: {e}", &[("e", &e.to_string())]);
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
match self.save_override.clone() {
|
||||
|
||||
Reference in new issue
Block a user