diff --git a/web/templates/new.html b/web/templates/new.html
index 48bd805..951d180 100644
--- a/web/templates/new.html
+++ b/web/templates/new.html
@@ -39,6 +39,18 @@
+
+
+
+
+
+
@@ -86,6 +99,43 @@ function toast(msg, kind) {
t._h = setTimeout(() => t.classList.remove('show'), 2000);
}
$('haspw').addEventListener('change', e => { $('pwrow').style.display = e.target.checked ? 'block' : 'none'; });
+$('burn').addEventListener('change', e => { $('burnrow').style.display = e.target.checked ? 'block' : 'none'; });
+document.querySelectorAll('input[name="exp"]').forEach(r => r.addEventListener('change', () => {
+ $('customexp-row').style.display = document.querySelector('input[name="exp"]:checked').value === 'custom' ? 'block' : 'none';
+ $('customexp-err').style.display = 'none';
+}));
+
+// compose the expires_in Go-duration string when Custom is checked (#48).
+// Returns the string, or null with an inline error shown.
+function composeCustomExpiry() {
+ const n = parseInt($('expnum').value, 10);
+ const unit = $('expunit').value;
+ let mins = NaN;
+ if (n > 0) {
+ if (unit === 'm') mins = n;
+ else if (unit === 'h') mins = n * 60;
+ else if (unit === 'd') mins = n * 1440;
+ else if (unit === 'w') mins = n * 10080;
+ else if (unit === 'mo') mins = n * 43200; // months counted as 30 days
+ }
+ const err = $('customexp-err');
+ if (!(mins >= 1)) {
+ err.textContent = 'Enter a duration of at least 1 minute.';
+ err.style.display = 'block';
+ return null;
+ }
+ if (mins > 525600) { // more than 1 year
+ err.textContent = 'Custom expiry cannot exceed 1 year.';
+ err.style.display = 'block';
+ return null;
+ }
+ err.style.display = 'none';
+ // compose as h (+d/m remainders); Go parses '336h', '90m', '6h30m' fine
+ const hours = Math.floor(mins / 60), rem = mins % 60;
+ if (rem === 0) return hours + 'h';
+ if (hours === 0) return rem + 'm';
+ return hours + 'h' + rem + 'm';
+
$('pwreveal').addEventListener('click', () => {
const pw = $('password');
const show = pw.type === 'password';
@@ -153,9 +203,16 @@ async function create() {
custom_slug: $('custom').value || null,
burn_after_read: $('burn').checked,
};
+ if ($('burn').checked) body.burn_after_reads = parseInt($('burnreads').value, 10) || 1;
if ($('haspw').checked) body.password = $('password').value;
const exp = document.querySelector('input[name="exp"]:checked').value;
- if (exp) body.expires_in = exp;
+ if (exp === 'custom') {
+ const dur = composeCustomExpiry();
+ if (dur === null) { toast('Check the custom expiry', 'error'); return; }
+ body.expires_in = dur;
+ } else if (exp) {
+ body.expires_in = exp;
+ }
const res = await fetch('/api/pastes', {
method: 'POST',