UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

178 lines (177 loc) 5.21 kB
/** * @packageDocumentation * * Provides utility functions for working with attachment paths. */ import type { App, FileStats, Vault } from 'obsidian'; import type { PathOrFile } from './FileSystem.cjs'; /** * A context for an attachment path. */ export declare enum AttachmentPathContext { /** * A context for a delete note. */ DeleteNote = "DeleteNote", /** * A context for a rename note. */ RenameNote = "RenameNote", /** * An unknown context. */ Unknown = "Unknown" } /** * Options for the get available path for attachments extended function. */ export interface GetAvailablePathForAttachmentsExtendedFnOptions { /** * A base name of the attachment. */ attachmentFileBaseName: string; /** * A content of the attachment file. */ attachmentFileContent?: ArrayBuffer | undefined; /** * An extension of the attachment. */ attachmentFileExtension: string; /** * A stats of the attachment file. */ attachmentFileStat?: FileStats | undefined; /** * A context. */ context: AttachmentPathContext; /** * A path or file of the note. */ notePathOrFile: null | PathOrFile; /** * A path or file of the old note. */ oldNotePathOrFile?: PathOrFile | undefined; /** * Should the duplicate check be skipped. */ shouldSkipDuplicateCheck?: boolean; /** * Should the generated attachment file name be skipped. */ shouldSkipGeneratedAttachmentFileName?: boolean; /** * Should missing attachment folder creation be skipped. */ shouldSkipMissingAttachmentFolderCreation: boolean | undefined; } /** * {@link Vault.getAvailablePathForAttachments} extended wrapper. */ export interface GetAvailablePathForAttachmentsFnExtended extends GetAvailablePathForAttachmentsFn { /** * Get available path for attachments with additional options. * * @param options - Options for the get available path for attachments. * @returns A {@link Promise} that resolves to the available path for attachments. */ extended(options: GetAvailablePathForAttachmentsExtendedFnOptions): Promise<string>; } type GetAvailablePathForAttachmentsFn = Vault['getAvailablePathForAttachments']; /** * Dummy path. */ export declare const DUMMY_PATH = "__DUMMY__"; /** * Options for the getAttachmentFilePath function. */ export interface GetAttachmentFilePathOptions { /** * An Obsidian application instance. */ app: App; /** * A path of the attachment. */ attachmentPathOrFile: PathOrFile; /** * A context. */ context: AttachmentPathContext; /** * A path of the note. */ notePathOrFile: PathOrFile; /** * A path of the old note. */ oldNotePathOrFile?: PathOrFile | undefined; /** * Should the duplicate check be skipped. */ shouldSkipDuplicateCheck: boolean; } /** * Options for the getAvailablePathForAttachments function. */ export interface GetAvailablePathForAttachmentsOptions { /** * An Obsidian application instance. */ app: App; /** * A base name of the attachment. */ attachmentFileBaseName: string; /** * An extension of the attachment. */ attachmentFileExtension: string; /** * A file to attach to. */ notePathOrFile: null | PathOrFile; /** * Should the duplicate check be skipped. */ shouldSkipDuplicateCheck?: boolean; /** * Should missing attachment folder creation be skipped. */ shouldSkipMissingAttachmentFolderCreation?: boolean; } /** * Retrieves the file path for an attachment within a note. * * @param options - Options for the get attachment file path function. * @returns A {@link Promise} that resolves to the file path of the attachment. */ export declare function getAttachmentFilePath(options: GetAttachmentFilePathOptions): Promise<string>; /** * Retrieves the attachment folder path for a given note. * * @param app - The Obsidian application instance. * @param notePathOrFile - The path of the note. * @param context - The context. * @returns A {@link Promise} that resolves to the attachment folder path. */ export declare function getAttachmentFolderPath(app: App, notePathOrFile: PathOrFile, context?: AttachmentPathContext): Promise<string>; /** * Retrieves the available path for attachments. * * @param options - Options for the get available path for attachments function. * @returns A {@link Promise} that resolves to the available path for attachments. */ export declare function getAvailablePathForAttachments(options: GetAvailablePathForAttachmentsOptions): Promise<string>; /** * Checks if a note has its own attachment folder. * * @param app - The Obsidian application instance. * @param path - The path of the note. * @param context - The context. * @returns A {@link Promise} that resolves to a boolean indicating whether the note has its own attachment folder. */ export declare function hasOwnAttachmentFolder(app: App, path: string, context?: AttachmentPathContext): Promise<boolean>; export {};