diff --git a/src/FileListModal.ts b/src/FileListModal.ts deleted file mode 100644 index e5c0811..0000000 --- a/src/FileListModal.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { App, SuggestModal, Notice, MarkdownView } from 'obsidian'; -import { SupernotePluginSettings } from './main'; - -interface SupernoteFile { - name: string; - size: number; - date: string; - uri: string; - extension: string; - isDirectory: boolean; -} - -interface SupernoteResponse { - deviceName: string; - fileList: SupernoteFile[]; - routeList: { name: string; path: string; }[]; - totalByteSize: number; - totalMemory: number; - usedMemory: number; -} - -export class FileListModal extends SuggestModal { - settings: SupernotePluginSettings; - files: SupernoteFile[] = []; - currentPath: string = '/'; - - constructor(app: App, settings: SupernotePluginSettings) { - super(app); - this.settings = settings; - this.setPlaceholder("Select a file to download or directory to open"); - } - - private async loadFiles() { - try { - const response = await fetch(`http://${this.settings.mirrorIP}:8089${this.currentPath}`); - if (!response.ok) { - throw new Error(`Failed to fetch file list: ${response.statusText}`); - } - const html = await response.text(); - - // Extract the JSON data from the script tag - const match = html.match(/const json = '(.+?)'/); - if (!match) { - throw new Error("Could not find file list data"); - } - - const data: SupernoteResponse = JSON.parse(match[1]); - this.files = data.fileList; - } catch (err) { - new Notice(`Failed to load files: ${err.message}`); - this.close(); - } - } - - async getSuggestions(query: string): Promise { - if (this.files.length === 0) { - await this.loadFiles(); - } - return this.files.filter(file => - file.name.toLowerCase().includes(query.toLowerCase()) - ); - } - - renderSuggestion(file: SupernoteFile, el: HTMLElement) { - const container = el.createDiv({ cls: "suggestion-item" }); - - // Add directory icon or file icon - const iconEl = container.createSpan({ cls: "suggestion-icon" }); - iconEl.textContent = file.isDirectory ? "📁" : "📄"; - - const contentEl = container.createDiv({ cls: "suggestion-content" }); - contentEl.createDiv({ text: file.name, cls: "suggestion-title" }); - - if (!file.isDirectory) { - contentEl.createDiv({ - text: `${this.formatSize(file.size)} - ${file.date}`, - cls: "suggestion-note" - }); - } else { - contentEl.createDiv({ - text: file.date, - cls: "suggestion-note" - }); - } - } - - private formatSize(bytes: number): string { - if (bytes < 1024) return bytes + ' B'; - if (bytes < 1048576) return (bytes / 1024).toFixed(2) + ' KB'; - if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + ' MB'; - return (bytes / 1073741824).toFixed(2) + ' GB'; - } - - async onChooseSuggestion(file: SupernoteFile) { - if (file.isDirectory) { - // Navigate into directory - this.currentPath = file.uri; - await this.loadFiles(); - // Reopen the modal to show new directory contents - this.open(); - } else { - try { - const fileResponse = await fetch(`http://${this.settings.mirrorIP}:8089${file.uri}`); - if (!fileResponse.ok) { - throw new Error(`Failed to download file: ${fileResponse.statusText}`); - } - - const buffer = await fileResponse.arrayBuffer(); - const filename = await this.app.fileManager.getAvailablePathForAttachment(file.name); - const tfile = await this.app.vault.createBinary(filename, buffer); - new Notice(`Downloaded ${file.name}`); - const view = this.app.workspace.getActiveViewOfType(MarkdownView); - if (view) { - const link = this.app.fileManager.generateMarkdownLink(tfile, filename); - view.editor.replaceSelection(link); - } - } catch (err) { - new Notice(`Failed to download file: ${err.message}`); - } - } - } -} diff --git a/src/myworker.worker.ts b/src/myworker.worker.ts deleted file mode 100644 index 87752af..0000000 --- a/src/myworker.worker.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { SupernoteX, toImage } from 'supernote-typescript'; -import { Image } from 'image-js' - -export {}; - -export type SupernoteWorkerMessage = { - type: 'convert'; - note: SupernoteX; - pageNumbers?: number[]; -} - -export type SupernoteWorkerResponse = { - type: 'result'; - images: string[]; - error?: string; -} - -self.onmessage = async (e: MessageEvent) => { - try { - const { type, note, pageNumbers } = e.data; - - if (type === 'convert') { - const results = await toImage(note, pageNumbers); - // Convert canvas/images to data URLs before sending - const dataUrls = results.map(result => { - if (result && typeof result.toDataURL === 'function') { - return result.toDataURL(); - } - console.error('Result is not a canvas or does not support toDataURL'); - return null; - }); - - self.postMessage({ - type: 'result', - images: dataUrls - }); - } - } catch (error) { - self.postMessage({ - type: 'result', - images: [], - error: error instanceof Error ? error.message : 'Unknown error occurred' - }); - } -}; \ No newline at end of file diff --git a/src/worker.d.ts b/src/worker.d.ts deleted file mode 100644 index 7e0df84..0000000 --- a/src/worker.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'myworker.worker' { - const WorkerFactory: new () => Worker; - export default WorkerFactory; -} \ No newline at end of file