mirror of
https://github.com/kissyjpf/rtm-sync.git
synced 2026-07-22 17:50:26 +00:00
26 lines
19 KiB
JavaScript
26 lines
19 KiB
JavaScript
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var Q=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var ct=Object.prototype.hasOwnProperty;var lt=($,k)=>{for(var s in k)Q($,s,{get:k[s],enumerable:!0})},mt=($,k,s,d)=>{if(k&&typeof k=="object"||typeof k=="function")for(let e of at(k))!ct.call($,e)&&e!==s&&Q($,e,{get:()=>k[e],enumerable:!(d=ot(k,e))||d.enumerable});return $};var dt=$=>mt(Q({},"__esModule",{value:!0}),$);var gt={};lt(gt,{default:()=>q});module.exports=dt(gt);var h=require("obsidian");function V($){function k(t,f){return t<<f|t>>>32-f}function s(t,f){let y=t&1073741824,T=f&1073741824,R=t&2147483648,I=f&2147483648,C=(t&1073741823)+(f&1073741823);return y&T?C^2147483648^R^I:y|T?C&1073741824?C^3221225472^R^I:C^1073741824^R^I:C^R^I}function d(t,f,y){return t&f|~t&y}function e(t,f,y){return t&y|f&~y}function m(t,f,y){return t^f^y}function c(t,f,y){return f^(t|~y)}function w(t,f,y,T,R,I,C){return t=s(t,s(s(d(f,y,T),R),C)),s(k(t,I),f)}function g(t,f,y,T,R,I,C){return t=s(t,s(s(e(f,y,T),R),C)),s(k(t,I),f)}function p(t,f,y,T,R,I,C){return t=s(t,s(s(m(f,y,T),R),C)),s(k(t,I),f)}function u(t,f,y,T,R,I,C){return t=s(t,s(s(c(f,y,T),R),C)),s(k(t,I),f)}function A(t){var it,rt;let f,y=t.length,T=y+8,I=((T-T%64)/64+1)*16,C=new Array(I).fill(0),G=0,v=0;for(;v<y;)f=(v-v%4)/4,G=v%4*8,C[f]=((it=C[f])!=null?it:0)|t.charCodeAt(v)<<G,v++;return f=(v-v%4)/4,G=v%4*8,C[f]=((rt=C[f])!=null?rt:0)|128<<G,C[I-2]=y<<3,C[I-1]=y>>>29,C}function x(t){let f="",y="",T,R;for(R=0;R<=3;R++)T=t>>>R*8&255,y="0"+T.toString(16),f=f+y.slice(y.length-2);return f}function E(t){t=t.replace(/\r\n/g,`
|
|
`);let f="";for(let y=0;y<t.length;y++){let T=t.charCodeAt(y);T<128?f+=String.fromCharCode(T):T>127&&T<2048?(f+=String.fromCharCode(T>>6|192),f+=String.fromCharCode(T&63|128)):(f+=String.fromCharCode(T>>12|224),f+=String.fromCharCode(T>>6&63|128),f+=String.fromCharCode(T&63|128))}return f}function a(t,f){var y;return(y=t[f])!=null?y:0}let b=7,D=12,F=17,S=22,P=5,L=9,N=14,W=20,_=4,M=11,U=16,B=23,O=6,j=10,K=15,H=21;$=E($);let l=A($),tt,et,st,nt,n=1732584193,i=4023233417,r=2562383102,o=271733878;for(let t=0;t<l.length;t+=16)tt=n,et=i,st=r,nt=o,n=w(n,i,r,o,a(l,t+0),b,3614090360),o=w(o,n,i,r,a(l,t+1),D,3905402710),r=w(r,o,n,i,a(l,t+2),F,606105819),i=w(i,r,o,n,a(l,t+3),S,3250441966),n=w(n,i,r,o,a(l,t+4),b,4118548399),o=w(o,n,i,r,a(l,t+5),D,1200080426),r=w(r,o,n,i,a(l,t+6),F,2821735955),i=w(i,r,o,n,a(l,t+7),S,4249261313),n=w(n,i,r,o,a(l,t+8),b,1770035416),o=w(o,n,i,r,a(l,t+9),D,2336552879),r=w(r,o,n,i,a(l,t+10),F,4294925233),i=w(i,r,o,n,a(l,t+11),S,2304563134),n=w(n,i,r,o,a(l,t+12),b,1804603682),o=w(o,n,i,r,a(l,t+13),D,4254626195),r=w(r,o,n,i,a(l,t+14),F,2792965006),i=w(i,r,o,n,a(l,t+15),S,1236535329),n=g(n,i,r,o,a(l,t+1),P,4129170786),o=g(o,n,i,r,a(l,t+6),L,3225465664),r=g(r,o,n,i,a(l,t+11),N,643717713),i=g(i,r,o,n,a(l,t+0),W,3921069994),n=g(n,i,r,o,a(l,t+5),P,3593408605),o=g(o,n,i,r,a(l,t+10),L,38016083),r=g(r,o,n,i,a(l,t+15),N,3634488961),i=g(i,r,o,n,a(l,t+4),W,3889429448),n=g(n,i,r,o,a(l,t+9),P,568446438),o=g(o,n,i,r,a(l,t+14),L,3275163606),r=g(r,o,n,i,a(l,t+3),N,4107603335),i=g(i,r,o,n,a(l,t+8),W,1163531501),n=g(n,i,r,o,a(l,t+13),P,2850285829),o=g(o,n,i,r,a(l,t+2),L,4243563512),r=g(r,o,n,i,a(l,t+7),N,1735328473),i=g(i,r,o,n,a(l,t+12),W,2368359562),n=p(n,i,r,o,a(l,t+5),_,4294588738),o=p(o,n,i,r,a(l,t+8),M,2272392833),r=p(r,o,n,i,a(l,t+11),U,1839030562),i=p(i,r,o,n,a(l,t+14),B,4259657740),n=p(n,i,r,o,a(l,t+1),_,2763975236),o=p(o,n,i,r,a(l,t+4),M,1272893353),r=p(r,o,n,i,a(l,t+7),U,4139469664),i=p(i,r,o,n,a(l,t+10),B,3200236656),n=p(n,i,r,o,a(l,t+13),_,681279174),o=p(o,n,i,r,a(l,t+0),M,3936430074),r=p(r,o,n,i,a(l,t+3),U,3572445317),i=p(i,r,o,n,a(l,t+6),B,76029189),n=p(n,i,r,o,a(l,t+9),_,3654602809),o=p(o,n,i,r,a(l,t+12),M,3873151461),r=p(r,o,n,i,a(l,t+15),U,530742520),i=p(i,r,o,n,a(l,t+2),B,3299628645),n=u(n,i,r,o,a(l,t+0),O,4096336452),o=u(o,n,i,r,a(l,t+7),j,1126891415),r=u(r,o,n,i,a(l,t+14),K,2878612391),i=u(i,r,o,n,a(l,t+5),H,4237533241),n=u(n,i,r,o,a(l,t+12),O,1700485571),o=u(o,n,i,r,a(l,t+3),j,2399980690),r=u(r,o,n,i,a(l,t+10),K,4293915773),i=u(i,r,o,n,a(l,t+1),H,2240044497),n=u(n,i,r,o,a(l,t+8),O,1873313359),o=u(o,n,i,r,a(l,t+15),j,4264355552),r=u(r,o,n,i,a(l,t+6),K,2734768916),i=u(i,r,o,n,a(l,t+13),H,1309151649),n=u(n,i,r,o,a(l,t+4),O,4149444226),o=u(o,n,i,r,a(l,t+11),j,3174756917),r=u(r,o,n,i,a(l,t+2),K,718787259),i=u(i,r,o,n,a(l,t+9),H,3951481745),n=s(n,tt),i=s(i,et),r=s(r,st),o=s(o,nt);return(x(n)+x(i)+x(r)+x(o)).toLowerCase()}var ut="https://www.rememberthemilk.com/services/auth/",Z="https://api.rememberthemilk.com/services/rest/",ht={apiKey:"",sharedSecret:"",authToken:"",defaultDueForNewTask:"none",noteCreationFolder:"",importWithNotesAndLink:!1},q=class extends h.Plugin{constructor(){super(...arguments);this.timeline=null}async onload(){await this.loadSettings(),this.addSettingTab(new X(this.app,this)),this.addCommand({id:"import-rtm-tasks",name:"Download all incomplete tasks",editorCallback:async(s,d)=>{this.checkAuth()&&await this.fetchAndProcessTasks("status:incomplete",!1,e=>{this.insertTasksToEditor(s,e)})}}),this.addCommand({id:"select-rtm-tasks",name:"Select and import tasks",editorCallback:async(s,d)=>{this.checkAuth()&&await this.fetchAndProcessTasks("status:incomplete",!0,e=>{this.insertTasksToEditor(s,e)})}}),this.addCommand({id:"import-rtm-tasks-custom",name:"Download tasks (Custom Filter)",editorCallback:async(s,d)=>{this.checkAuth()&&new J(this.app,e=>{this.fetchAndProcessTasks(e,!0,m=>{this.insertTasksToEditor(s,m)})}).open()}}),this.addCommand({id:"create-note-from-rtm-task",name:"Create note from RTM task",callback:async()=>{this.checkAuth()&&await this.fetchAndProcessTasks("status:incomplete",!0,s=>{this.createNotesFromTasks(s)})}}),this.addCommand({id:"add-rtm-task",name:"Add cursor line to RTM",editorCallback:async(s,d)=>{this.checkAuth()&&await this.addTaskFromEditor(s,d)}}),this.addCommand({id:"complete-rtm-task",name:"Complete task at cursor",editorCallback:async(s,d)=>{this.checkAuth()&&await this.completeTaskInEditor(s)}})}checkAuth(){return!this.settings.apiKey||!this.settings.sharedSecret?(new h.Notice("Please set your API Key and Secret in settings."),!1):this.settings.authToken?!0:(new h.Notice("Please authenticate with RTM from settings."),!1)}async fetchListsMap(){var d;let s={};try{let e=await this.callRtmApi("rtm.lists.getList");if((d=e.rsp.lists)!=null&&d.list){let m=Array.isArray(e.rsp.lists.list)?e.rsp.lists.list:[e.rsp.lists.list];for(let c of m)c!=null&&c.id&&(c!=null&&c.name)&&(s[c.id]=c.name)}}catch(e){console.error("List fetch error:",e)}return s}async fetchAndProcessTasks(s,d,e){var m,c,w,g;new h.Notice("Fetching tasks...");try{let p=await this.fetchListsMap(),u=await this.callRtmApi("rtm.tasks.getList",{filter:s,notes:"1"});if(!((m=u.rsp.tasks)!=null&&m.list)){new h.Notice("No tasks found.");return}let A=[],x=Array.isArray(u.rsp.tasks.list)?u.rsp.tasks.list:[u.rsp.tasks.list];for(let E of x){if(!E.taskseries)continue;let a=Array.isArray(E.taskseries)?E.taskseries:[E.taskseries];for(let b of a){let D=b.name,F=Array.isArray(b.task)?b.task[0]:b.task,S=E.id;!S&&b.list_id&&(S=b.list_id),S||(S="MISSING");let P="";F.due&&F.due!==""&&(P=`\u{1F4C5} ${F.due.split("T")[0]}`);let L="";F.start&&F.start!==""&&(L=`\u{1F6EB} ${F.start.split("T")[0]}`);let N="";switch(F.priority){case"1":N="\u{1F53A}";break;case"2":N="\u{1F53C}";break;case"3":N="\u{1F53D}";break}let W=(c=p[S])!=null?c:"",_=[];(w=b.tags)!=null&&w.tag&&(Array.isArray(b.tags.tag)?b.tags.tag:[b.tags.tag]).forEach(B=>_.push(B));let M=[];(g=b.notes)!=null&&g.note&&(Array.isArray(b.notes.note)?b.notes.note:[b.notes.note]).forEach(B=>{var j;let O=(j=B.$t)!=null?j:String(B);O&&M.push(O)}),A.push({name:D,due:P,start:L,priority:N,listName:W,tags:_,notes:M,rtmId:{list:S,series:b.id,task:F.id},rawPriority:F.priority,rawDue:F.due})}}d?new z(this.app,A,E=>{e(E)}).open():e(A)}catch(p){console.error(p),new h.Notice("Fetch error.")}}insertTasksToEditor(s,d){if(d.length===0){new h.Notice("No tasks selected.");return}let e="";for(let m of d){let c="";m.listName&&(c=` #${m.listName.replace(/[\s,.]+/g,"_")}`);let w=m.tags.map(A=>` #${A}`).join(""),g=`[\u{1F42E}](rtm:${m.rtmId.list}:${m.rtmId.series}:${m.rtmId.task})`,p=m.priority?` ${m.priority}`:"",u=m.due?` ${m.due}`:"";if(e+=`- [ ] ${g} ${m.name}${p}${u}${c}${w}
|
|
`,this.settings.importWithNotesAndLink){let A=`https://www.rememberthemilk.com/app/#all/${m.rtmId.task}`;e+=` - RTM Link: ${A}
|
|
`,m.notes&&m.notes.length>0&&m.notes.forEach(x=>{x.split(`
|
|
`).forEach(a=>{a.trim()!==""&&(e+=` - Note: ${a}
|
|
`)})})}}s.replaceSelection(e),new h.Notice(`${d.length} tasks inserted.`)}async createNotesFromTasks(s){if(s.length===0){new h.Notice("No tasks selected.");return}let d=0;for(let e of s){let m=e.name.replace(/[\\/:*?"<>|]/g,"-"),c=this.settings.noteCreationFolder.trim();c.endsWith("/")&&(c=c.slice(0,-1)),c.startsWith("/")&&(c=c.slice(1)),c&&await this.ensureFolderExists(c);let w=c?`${c}/${m}.md`:`${m}.md`;this.app.vault.getAbstractFileByPath(w)&&(w=c?`${c}/${m}-${Date.now()}.md`:`${m}-${Date.now()}.md`);let g=e.tags.map(A=>`#${A}`).join(" "),p=e.listName?`#${e.listName.replace(/[\s,.]+/g,"_")}`:"",u=`# ${e.name}
|
|
|
|
`;u+=`- **RTM Link**: [\u{1F42E} Open Task](rtm:${e.rtmId.list}:${e.rtmId.series}:${e.rtmId.task})
|
|
`,e.due&&(u+=`- **Due**: ${e.due}
|
|
`),e.start&&(u+=`- **Start**: ${e.start}
|
|
`),e.priority&&(u+=`- **Priority**: ${e.priority}
|
|
`),(p||g)&&(u+=`- **Tags**: ${p} ${g}
|
|
`),u+=`
|
|
---
|
|
|
|
`,e.notes.length>0?(u+=`## Notes
|
|
|
|
`,e.notes.forEach(A=>{u+=`${A}
|
|
|
|
`})):u+=`(No notes in RTM)
|
|
`;try{await this.app.vault.create(w,u),d++}catch(A){console.error(`Failed to create file: ${w}`,A),new h.Notice(`Failed to create note for "${e.name}"`)}}new h.Notice(`${d} notes created.`)}async addTaskFromEditor(s,d){let e=s.getCursor(),c=s.getLine(e.line).replace(/^[-*] \[[ x]\] /,"").replace(/^[-*] /,"").trim();if(!c){new h.Notice("Task name is empty.");return}new h.Notice(`Adding: ${c}`);let w=d.file?d.file.basename:"";try{let g=await this.getTimeline(),p=await this.callRtmApi("rtm.tasks.add",{timeline:g,name:c,parse:"1"}),u=p.rsp.list;if(!u)throw console.error("API Response does not contain 'list':",p),new Error("API Response missing 'list'. Check console for details.");let A=Array.isArray(u)?u[0]:u;if(!A.id)throw console.error("API Response list missing 'id':",p),new Error("API Response list missing 'id'. Check console for details.");let x=A.id,E=A.taskseries;if(!E)throw console.error("API Response does not contain 'taskseries':",p),new Error("API Response missing 'taskseries'. Check console for details.");let a=Array.isArray(E)?E[0]:E;if(!a.id)throw console.error("API Response series missing 'id':",p),new Error("API Response series missing 'id'. Check console for details.");let b=a.id,D=a.task;if(!D)throw console.error("API Response does not contain 'task':",p),new Error("API Response missing 'task'. Check console for details.");let F=Array.isArray(D)?D[0]:D;if(!F.id)throw console.error("API Response taskObj missing 'id':",p),new Error("API Response taskObj missing 'id'. Check console for details.");let S=F.id;if(this.settings.defaultDueForNewTask==="today")try{await this.callRtmApi("rtm.tasks.setDueDate",{timeline:g,list_id:x,taskseries_id:b,task_id:S,due:"today",parse:"1"})}catch(N){console.error("Failed to set due date",N)}if(w)try{await this.callRtmApi("rtm.tasks.notes.add",{timeline:g,list_id:x,taskseries_id:b,task_id:S,note_title:"Obsidian Link",note_text:`From Obsidian Note: [[${w}]]`})}catch(N){console.error("Failed to add note to RTM task",N)}let L=`- [ ] ${`[\u{1F42E}](rtm:${x}:${b}:${S})`} ${c}`;s.setLine(e.line,L),new h.Notice("Added to RTM!")}catch(g){console.error("Add Task Error:",g),new h.Notice("Add error.")}}async completeTaskInEditor(s){let d=s.getCursor(),e=s.getLine(d.line),m=/\(rtm:([\w\d]+):([\w\d]+):([\w\d]+)\)/,c=e.match(m);if(!c){new h.Notice("Error: No RTM Link found.");return}let w=c[1],g=c[2],p=c[3];if(!w||w==="MISSING"){new h.Notice("Error: List ID invalid.");return}new h.Notice("Completing task...");try{let u=await this.getTimeline();await this.callRtmApi("rtm.tasks.complete",{timeline:u,list_id:w,taskseries_id:g,task_id:p});let A=e.replace("- [ ]","- [x]");s.setLine(d.line,A),new h.Notice("Task completed!")}catch(u){console.error("Completion Error:",u),new h.Notice("Completion error.")}}async getTimeline(){var e;if(this.timeline)return this.timeline;let d=(e=(await this.callRtmApi("rtm.timelines.create")).rsp.timeline)!=null?e:"";return this.timeline=d,d}async callRtmApi(s,d={}){var E,a,b,D,F;let e=(E=this.settings.apiKey)==null?void 0:E.trim(),m=(a=this.settings.sharedSecret)==null?void 0:a.trim();if(!e||!m)throw new Error("API Key/Secret missing");let c={...d,method:s,api_key:e,format:"json",auth_token:(D=(b=this.settings.authToken)==null?void 0:b.trim())!=null?D:""},w=Object.keys(c).sort(),g=m;for(let S of w)g+=S+c[S];c.api_sig=V(g);let p=Object.keys(c).map(S=>{var P;return`${encodeURIComponent(S)}=${encodeURIComponent((P=c[S])!=null?P:"")}`}).join("&"),u=`${Z}?${p}`,x=(await(0,h.requestUrl)({url:u})).json;if(x.rsp.stat!=="ok")throw console.error("API Error:",x),new Error(`API Error: ${(F=x.rsp.err)==null?void 0:F.msg}`);return x}async ensureFolderExists(s){if(!s)return;let d=s.split("/"),e="";for(let m of d)if(m&&(e=e===""?m:`${e}/${m}`,!this.app.vault.getAbstractFileByPath(e)))try{await this.app.vault.adapter.mkdir(e)}catch(c){console.error(`Failed to create folder: ${e}`,c)}}async loadSettings(){this.settings=Object.assign({},ht,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}},z=class extends h.Modal{constructor(k,s,d){super(k),this.tasks=s,this.selected=new Array(s.length).fill(!1),this.onSubmit=d}onOpen(){let{contentEl:k}=this;new h.Setting(k).setName(`Select Tasks (${this.tasks.length})`).setHeading();let s=k.createDiv({cls:"rtm-task-list"});this.tasks.forEach((c,w)=>{var A;let g=s.createDiv({cls:"rtm-task-item"}),p=g.createEl("input",{type:"checkbox"});p.checked=(A=this.selected[w])!=null?A:!1,p.onchange=x=>{this.selected[w]=x.target.checked};let u=g.createSpan({cls:"rtm-task-label"});u.createEl("b",{text:c.name}),c.listName&&u.createEl("small",{text:` [${c.listName}]`,cls:"rtm-task-list-name"}),c.due&&u.createEl("small",{text:` ${c.due}`,cls:"rtm-task-due"}),c.notes&&c.notes.length>0&&u.createEl("small",{text:" \u{1F4DD}"})});let d=k.createDiv({cls:"rtm-btn-row"}),e=d.createEl("button",{text:"Select All"});e.onclick=()=>{let c=this.selected.every(Boolean);this.selected.fill(!c),s.querySelectorAll('input[type="checkbox"]').forEach(g=>g.checked=!c),e.textContent=c?"Select All":"Deselect All"};let m=d.createEl("button",{text:"Process Selected"});m.className="mod-cta",m.onclick=()=>{let c=this.tasks.filter((w,g)=>this.selected[g]);this.onSubmit(c),this.close()}}onClose(){this.contentEl.empty()}},J=class extends h.Modal{constructor(k,s){super(k),this.onSubmit=s}onOpen(){let{contentEl:k}=this;k.createEl("h3",{text:"Filter RTM Tasks"}),new h.Setting(k).setName("Search Query").setDesc("e.g. list:Inbox, due:today").addText(s=>s.setValue("status:incomplete").onChange(d=>{}).inputEl.addEventListener("keydown",d=>{d.key==="Enter"&&(this.onSubmit(s.getValue()),this.close())})),new h.Setting(k).addButton(s=>s.setButtonText("Search").setCta().onClick(()=>{let d=k.querySelector("input");d&&(this.onSubmit(d.value),this.close())}))}onClose(){this.contentEl.empty()}},X=class extends h.PluginSettingTab{constructor(k,s){super(k,s),this.plugin=s}display(){let{containerEl:k}=this;k.empty(),new h.Setting(k).setName("Connection").setHeading(),k.createEl("p",{text:`Version: ${this.plugin.manifest.version} (Build: 6/24/2026, 3:02:09 PM)`,cls:"setting-item-description rtm-version-info"}),new h.Setting(k).setName("API Key").addText(e=>e.setValue(this.plugin.settings.apiKey).onChange(async m=>{this.plugin.settings.apiKey=m,await this.plugin.saveSettings()})),new h.Setting(k).setName("Shared Secret").addText(e=>e.setValue(this.plugin.settings.sharedSecret).onChange(async m=>{this.plugin.settings.sharedSecret=m,await this.plugin.saveSettings()}));let d=new h.Setting(k).setName("Auth");this.plugin.settings.authToken&&d.setDesc("\u2705 Authorized"),d.addButton(e=>e.setButtonText("Start Auth").onClick(async()=>await this.startAuthProcess())),new h.Setting(k).setName("Default Due Date").setDesc("Setting for new tasks created from editor").addDropdown(e=>e.addOption("none","No Due Date").addOption("today","Today").setValue(this.plugin.settings.defaultDueForNewTask).onChange(async m=>{this.plugin.settings.defaultDueForNewTask=m,await this.plugin.saveSettings()})),new h.Setting(k).setName("Note Creation Folder").setDesc("Folder to create notes from RTM tasks.").addDropdown(e=>{e.addOption("","/ (Vault Root)"),this.app.vault.getAllLoadedFiles().filter(c=>c instanceof h.TFolder).forEach(c=>{c.path!=="/"&&e.addOption(c.path,c.path)}),e.setValue(this.plugin.settings.noteCreationFolder),e.onChange(async c=>{this.plugin.settings.noteCreationFolder=c,await this.plugin.saveSettings()})}),new h.Setting(k).setName("Import with Notes and RTM Link").setDesc("When inserting tasks to the editor, also include RTM task notes and links as sub-items.").addToggle(e=>e.setValue(this.plugin.settings.importWithNotesAndLink).onChange(async m=>{this.plugin.settings.importWithNotesAndLink=m,await this.plugin.saveSettings()}))}async startAuthProcess(){var x,E,a;let k=this.plugin,s=(x=k.settings.apiKey)==null?void 0:x.trim(),d=(E=k.settings.sharedSecret)==null?void 0:E.trim();if(!s||!d){new h.Notice("Enter keys first");return}let e={method:"rtm.auth.getFrob",api_key:s,format:"json"},m=d;Object.keys(e).sort().forEach(b=>m+=b+e[b]),e.api_sig=V(m);let c=Object.keys(e).map(b=>{var D;return`${encodeURIComponent(b)}=${encodeURIComponent((D=e[b])!=null?D:"")}`}).join("&"),g=(a=(await(0,h.requestUrl)({url:`${Z}?${c}`})).json.rsp.frob)!=null?a:"",p={api_key:s,perms:"delete",frob:g},u=d;Object.keys(p).sort().forEach(b=>u+=b+p[b]);let A=V(u);window.open(`${ut}?api_key=${s}&perms=delete&frob=${g}&api_sig=${A}`),new Y(this.app,g,k,()=>{this.display()}).open()}},Y=class extends h.Modal{constructor(k,s,d,e){super(k),this.frob=s,this.plugin=d,this.onSuccess=e}onOpen(){let{contentEl:k}=this;new h.Setting(k).addButton(s=>s.setButtonText("Finish Auth").setCta().onClick(async()=>{var w,g;let d=(w=this.plugin.settings.apiKey)==null?void 0:w.trim(),e=(g=this.plugin.settings.sharedSecret)==null?void 0:g.trim(),m={method:"rtm.auth.getToken",api_key:d!=null?d:"",format:"json",frob:this.frob},c=e;Object.keys(m).sort().forEach(p=>c+=p+m[p]),m.api_sig=V(c);try{let p=Object.keys(m).map(x=>{var E;return`${encodeURIComponent(x)}=${encodeURIComponent((E=m[x])!=null?E:"")}`}).join("&"),A=(await(0,h.requestUrl)({url:`${Z}?${p}`})).json;A.rsp.auth?(this.plugin.settings.authToken=A.rsp.auth.token,await this.plugin.saveSettings(),new h.Notice("Success!"),this.onSuccess(),this.close()):new h.Notice("Failed.")}catch(p){new h.Notice("Error.")}}))}onClose(){this.contentEl.empty()}};
|