add renew function
This commit is contained in:
parent
17ff666965
commit
038f014f9c
@ -208,6 +208,15 @@
|
||||
cloneBtn.addEventListener('click', () => cloneRec(key));
|
||||
actions.appendChild(cloneBtn);
|
||||
|
||||
if (isEdit || expired) {
|
||||
const renewBtn = document.createElement('button');
|
||||
renewBtn.className = 'btn btn-info btn-sm me-2';
|
||||
renewBtn.type = 'button';
|
||||
renewBtn.textContent = 'erneuern';
|
||||
renewBtn.addEventListener('click', () => renewRec(key));
|
||||
actions.appendChild(renewBtn);
|
||||
}
|
||||
|
||||
if (isEdit) {
|
||||
const saveBtn = document.createElement('button');
|
||||
saveBtn.className = 'btn btn-success btn-sm';
|
||||
@ -260,6 +269,38 @@
|
||||
editing.add(rec.secret);
|
||||
render();
|
||||
}
|
||||
async function renewRec(secret) {
|
||||
// find current record
|
||||
const rec = data.find(r => r.secret === secret);
|
||||
if (!rec) return;
|
||||
|
||||
// generate a fresh unique secret
|
||||
const existing = data.map(r => r.secret);
|
||||
const newSecret = generateSecret(existing);
|
||||
|
||||
// validity = today + 35 days, formatted as YYYY-MM-DD
|
||||
const future = new Date();
|
||||
future.setDate(future.getDate() + 35);
|
||||
const yyyy = future.getFullYear();
|
||||
const mm = String(future.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(future.getDate()).padStart(2, '0');
|
||||
const validity = `${yyyy}-${mm}-${dd}`;
|
||||
|
||||
// keep folders unchanged
|
||||
const folders = rec.folders.map(f => ({
|
||||
foldername: f.foldername,
|
||||
folderpath: f.folderpath
|
||||
}));
|
||||
|
||||
// persist via existing endpoint
|
||||
await sendAction({
|
||||
action: 'update',
|
||||
oldSecret: secret,
|
||||
newSecret,
|
||||
validity,
|
||||
folders
|
||||
});
|
||||
}
|
||||
function addFolder(secret) {
|
||||
data.find(r => r.secret === secret).folders.push({foldername:'', folderpath:''});
|
||||
render();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user