-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
6 lines (5 loc) · 3.95 KB
/
main.js
File metadata and controls
6 lines (5 loc) · 3.95 KB
1
2
3
4
5
6
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var m=(r,n)=>{for(var t in n)p(r,t,{get:n[t],enumerable:!0})},E=(r,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of f(n))!P.call(r,a)&&a!==t&&p(r,a,{get:()=>n[a],enumerable:!(e=w(n,a))||e.enumerable});return r};var S=r=>E(p({},"__esModule",{value:!0}),r);var y={};m(y,{default:()=>d});module.exports=S(y);var s=require("obsidian"),h=require("fs"),g=require("path"),T={inputFolderPath:"_input",noteFolderPath:"_unsortiert",attachementFolderPath:"_unsortiert/_files"},d=class extends s.Plugin{async onload(){await this.loadSettings(),this.addRibbonIcon("dice","Import Files",a=>{this.processFiles()}).addClass("my-plugin-ribbon-class"),this.addStatusBarItem().setText("Status Bar Text"),this.addSettingTab(new c(this.app,this))}onunload(){}async loadSettings(){this.settings=Object.assign({},T,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}async processFiles(){try{if(!await this.ensureAllFoldersExist(this.settings)){new s.Notice("Import aborted");return}let t=(0,s.normalizePath)(this.app.vault.adapter.basePath),e=t+(0,s.normalizePath)("/"+this.settings.inputFolderPath),a=(0,h.readdirSync)(e);console.error("List of files:"+a);let i=0;for(let l of a){let u=(0,g.join)(e,l);(0,h.statSync)(u).isDirectory()||(await this.processFile(u,l,t),i++)}new s.Notice(`Processed ${i} files`)}catch(t){console.error("Error processing files:",t),new s.Notice(`Error: ${t.message}`)}}async processFile(t,e,a){try{let i=this.app.vault.getFileByPath(t);if(!i)throw new Error(`File not found: ${t}`);let l=`${a}/${this.settings.attachementFolderPath}/${e}`;await this.app.vault.rename(i,l),new s.Notice(`Created note for: ${e}`)}catch(i){console.error(`Error processing file ${e}:`,i),new s.Notice(`Error processing ${e}: ${i.message}`)}}async ensureAllFoldersExist(t){return await this.app.vault.adapter.exists(t.attachementFolderPath)?await this.app.vault.adapter.exists(t.inputFolderPath)?await this.app.vault.adapter.exists(t.noteFolderPath)?!0:(new s.Notice(`Folder ${t.noteFolderPath} does not exists`),!1):(new s.Notice(`Folder ${t.inputFolderPath} does not exists`),!1):(new s.Notice(`Folder ${t.attachementFolderPath} does not exists`),!1)}},o=class extends s.AbstractInputSuggest{constructor(t,e){super(t,e);this.inputEl=e}getSuggestions(t){let e=[];return F(this.app.vault.getRoot(),e),e.filter(a=>a.path.toLowerCase().includes(t.toLowerCase()))}renderSuggestion(t,e){e.setText(t.path)}selectSuggestion(t){this.inputEl.value=t.path,this.inputEl.trigger("input"),this.close()}};function F(r,n){n.push(r);for(let t of r.children)t instanceof s.TFolder&&F(t,n)}var c=class extends s.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){let{containerEl:t}=this;t.empty(),new s.Setting(t).setName("Input Folder").setDesc("Folder with new files").addText(e=>{var a;e.inputEl.placeholder="Start typing to search folders",e.setValue((a=this.plugin.settings.inputFolderPath)!=null?a:""),new o(this.app,e.inputEl),e.onChange(async i=>{this.plugin.settings.inputFolderPath=i,await this.plugin.saveSettings()})}),new s.Setting(t).setName("Note Folder").setDesc("Folder where new notes are placed").addText(e=>{var a;e.inputEl.placeholder="Start typing to search folders",e.setValue((a=this.plugin.settings.noteFolderPath)!=null?a:""),new o(this.app,e.inputEl),e.onChange(async i=>{this.plugin.settings.noteFolderPath=i,await this.plugin.saveSettings()})}),new s.Setting(t).setName("Attachement folder").setDesc("Folder where attachements are stored").addText(e=>{var a;e.inputEl.placeholder="Start typing to search folders",e.setValue((a=this.plugin.settings.attachementFolderPath)!=null?a:""),new o(this.app,e.inputEl),e.onChange(async i=>{this.plugin.settings.attachementFolderPath=i,await this.plugin.saveSettings()})})}};