Add private CardDAV synchronization and contact revision recovery
Build and publish container images / images (push) Successful in 13m39s
Release container images / release (push) Successful in 18s

This commit is contained in:
Anya Tokugawa committed 2026-11-02 08:41:15 +09:00
1 parent 433169c7e7
commit 19e12f96a8
32 files changed
+1855 -47

No files matched your search

+1 -1
View File
@@ -7,4 +7,4 @@ const actions=el('div'),save=el('button',t('Save','保存'));save.type='submit';
form.append(actions);form.onsubmit=async e=>{e.preventDefault();if(busy)return;const draft={...c};for(const key of Object.keys(inputs))draft[key]=['emails','phones'].includes(key)?inputs[key].value.split('\n').map(v=>v.trim()).filter(Boolean):inputs[key].value;busy=true;save.disabled=true;try{const d=await request('items'+(c.version?'/'+c.uuid:''),{method:c.version?'PUT':'POST',headers:c.version?{'If-Match':'"'+c.version+'"'}:{},body:JSON.stringify(draft)});show(d.item);status.textContent=t('Saved','保存しました');await load();}catch(e){status.textContent=e.message;}finally{busy=false;save.disabled=!writable;}};editor.append(form);if(c.vcard){const d=el('details'),summary=el('summary',t('Original vCard (unsupported properties are retained)','vCard(未対応プロパティも保持)'));d.append(summary,el('pre',c.vcard));editor.append(d);}inputs.name.focus();}
async function load(after='',append=false){const id=++ticket;try{const d=await request('items?'+new URLSearchParams({q:search.value,after,deleted:trash.value}));if(id!==ticket)return;if(!append)list.replaceChildren();list.querySelector('[data-more]')?.remove();for(const c of d.items){const b=button(c.name+' · '+(c.emails[0]||c.organization||''),async()=>{if(!allowLeave())return;try{const d=await request('items/'+c.uuid);show(d.item);}catch(e){status.textContent=e.message;}});list.append(b);}if(d.next){const b=button(t('More','続き'),()=>load(d.next,true));b.dataset.more='true';list.append(b);}if(!list.children.length)list.append(el('p',t('No contacts','連絡先がありません')));}catch(e){status.textContent=e.message;}}
let timer;search.oninput=()=>{clearTimeout(timer);timer=setTimeout(()=>load(),200);};if(writable){controls.append(button(t('New contact','連絡先を追加'),()=>{if(allowLeave())show({uuid:crypto.randomUUID(),version:0,emails:[],phones:[],deleted:false});}));const file=el('input');file.type='file';file.accept='.vcf,text/vcard';file.hidden=true;controls.append(button(t('Import vCard','vCardを取り込む'),()=>file.click()),file);file.onchange=async()=>{const f=file.files[0];if(!f)return;try{if(f.size>2*1024*1024)throw Error(t('Maximum 2 MiB','上限は2 MiBです'));const text=await f.text();const cards=text.match(/BEGIN:VCARD\r?\n[\s\S]*?END:VCARD(?:\r?\n|$)/g)||[];if(!cards.length||cards.length>200||text.replace(/BEGIN:VCARD\r?\n[\s\S]*?END:VCARD(?:\r?\n|$)/g,'').trim())throw Error(t('Expected up to 200 UTF-8 vCards (3.0/4.0).','UTF-8のvCard 3.0/4.0(最大200件)を指定してください。'));if(!confirm(t('Import contacts: ','連絡先を取り込みます:')+cards.length+'\n'+t('Existing identical UID/content is skipped. Conflicts are not overwritten.','同一UID・内容は重複登録しません。競合は上書きせず報告します。')))return;let success=0,failed=[];for(let i=0;i<cards.length;i++){try{await request('import',{method:'POST',headers:{'Content-Type':'text/vcard'},body:cards[i]});success++;}catch(e){failed.push(i+1);}}status.textContent=t('Imported/existing: ','取り込み済み・既存:')+success+(failed.length?t(' / Failed card numbers: ',' / 失敗したカード番号:')+failed.join(', '):'');await load();}catch(e){status.textContent=e.message;}finally{file.value='';}};}
window.addEventListener('beforeunload',e=>{if(dirty){e.preventDefault();e.returnValue='';}});load();})();
app.addEventListener('contact-restored',e=>{show(e.detail);load();status.textContent=t('Revision restored as a new version','履歴を新しい版として復元しました');});window.addEventListener('beforeunload',e=>{if(dirty){e.preventDefault();e.returnValue='';}});load();})();