item

The eagle.item API allows you to easily query the current content of the resource library or add new content to the resource library.

eagle.onPluginCreate(async (plugin) => {
    // Get the currently selected file in the Eagle app
    let items = await eagle.item.getSelected();
    let item = items[0];
    
    // Modify attributes
    item.name = 'New Name';
    item.tags = ['tag1', 'tag2'];
    
    // Save modifications
    await item.save();
});

Methods

get(options)

Universal search method that can get files with specified conditions.

  • options Object - Query conditions

    • id string (optional) - File id

    • ids string[] (optional) - Array of file ids

    • isSelected boolean (optional) - Currently selected files

    • isUntagged boolean (optional) - Files that have not been tagged

    • isUnfiled boolean (optional) - Files that have not been categorized

    • keywords string[] (optional) - Contains keywords

    • tags string[] (optional) - Contains tags

    • folders string[] (optional) - Contains folders

    • ext string (optional) - Format

    • annotation string (optional) - Annotation

    • rating Integer (optional) - Rating, range from 0 ~ 5

    • url string (optional) - Source URL

    • shape string (optional) - Shape, options are square, portrait, panoramic-portrait, landscape, panoramic-landscape

    • fields string[] (optional) - Specify fields to return, only returning needed data to improve performance

  • Returns Promise<items: Item[]> - items query result

Performance Tip: Using the fields parameter can significantly improve performance, especially when handling large numbers of files and only partial information is needed.


getAll()

Return all files.

  • Returns Promise<items: Item[]> - items all files


getById(itemId)

Return the file with the specified ID.

  • itemId string

  • Returns Promise<item: Item> - item the file with the corresponding ID

getByIds(itemIds)

Return the files with the specified IDs.

  • itemIds string[]

  • Returns Promise<items: Item[]> - items the files with the corresponding IDs


getSelected()

Return the currently selected files in the application.

  • Returns Promise<items: Item[]> - items selected files


getIdsWithModifiedAt()

Quickly get IDs and last modified times for all files.

  • Returns Promise<items: Object[]> - Array of objects containing id and modifiedAt

Performance Tip: This method is specifically optimized for retrieving file IDs and modification times, and is much faster than using the get() method to retrieve complete data.


count(options)

Returns the number of files that match the specified query conditions.

  • options Object - Query conditions (same as get() method)

    • id string (optional) - File id

    • ids string[] (optional) - Array of file ids

    • isSelected boolean (optional) - Currently selected files

    • isUntagged boolean (optional) - Files that have not been tagged

    • isUnfiled boolean (optional) - Files that have not been categorized

    • keywords string[] (optional) - Contains keywords

    • tags string[] (optional) - Contains tags

    • folders string[] (optional) - Contains folders

    • ext string (optional) - Format

    • annotation string (optional) - Annotation

    • rating Integer (optional) - Rating, range from 0 ~ 5

    • url string (optional) - Source URL

    • shape string (optional) - Shape, options are square, portrait, panoramic-portrait, landscape, panoramic-landscape

  • Returns Promise<count: number> - count number of files matching the query conditions

Performance Tip: The count() method is optimized for performance and is more efficient than calling get() and checking the array length when you only need the number of files.


countAll()

Returns the total number of files in the resource library.

  • Returns Promise<count: number> - count total number of files

Performance Tip: This method is highly optimized and provides a fast way to get the total file count without loading all file data into memory.


countSelected()

Returns the number of currently selected files in the application.

  • Returns Promise<count: number> - count number of selected files

Performance Tip: This is a convenience method that provides a faster way to count selected files compared to using getSelected().length.


select(itemIds)

Select specified files

  • itemIds string[] - Array of file IDs to select

  • Returns Promise<result: boolean> - result whether the selection was successful

Note: Calling this method will replace the current selection state, rather than appending to existing selected items.

Note: The select() method requires Eagle 4.0 build12 or higher.


addFromURL(url, options)

Add an image link to Eagle.

  • urlstring - The image link to add, supports http, https, base64

  • options Object

    • name string (optional) - File name

    • website string (optional) - Source URL

    • tags string[] (optional) - Tags

    • folders string[] (optional) - Belonging folder IDs

    • annotation string (optional) - Annotation

  • Returns Promise<itemId: string> - itemId is the successfully created item ID


addFromBase64(base64, options)

Add a base64 image to Eagle.

  • base64string - Base64 format image

  • options Object

    • name string (optional) - File name

    • website string (optional) - Source URL

    • tags string[] (optional) - Tags

    • folders string[] (optional) - Belonging folder IDs

    • annotation string (optional) - Annotation

  • Returns Promise<itemId: string> - itemId is the successfully created item ID


addFromPath(path, options)

Add files to Eagle from a local file path.

  • pathstring - The file path to add

  • options Object

    • name string (optional) - File name

    • website string (optional) - Source URL

    • tags string[] (optional) - Tags

    • folders string[] (optional) - Belonging folder IDs

    • annotation string (optional) - Annotation

  • Returns Promise<itemId: string> - itemId is the successfully created item ID


addBookmark(url, options)

Add a bookmark link to Eagle.

  • urlstring - The bookmark link to add

  • options Object

    • name string (optional) - Bookmark name

    • base64 string (optional) - Custom thumbnail in base64 format

    • tags string[] (optional) - Tags

    • folders string[] (optional) - Belonging folder IDs

    • annotation string (optional) - Annotation

  • Returns Promise<itemId: string> - itemId is the successfully created item ID


open(itemId, options)

Display the file corresponding to itemId in the full list

  • itemId string - ID of the file to display

  • options Object (optional) - Open options

    • window boolean (optional) - Whether to open the file in a new window, defaults to false

  • Returns Promise<result: boolean>

Note: The window parameter requires Eagle 4.0 build12 or higher.

Hint: You can also directly call the open() method of the item instance to open the file.


Class: Item

Object type returned by Eagle API get, provides modification and save features.


Instance methods

save()

Save all modifications

  • Returns Promise<result: boolean> - result indicates whether the modification was successful


moveToTrash()

Move the file to the trash.

  • Returns Promise<result: boolean> - result Indicates whether the deletion was successful.


replaceFile(filePath)

Replace the original file with the specified file, automatically refreshing the thumbnail without needing to call refreshThumbnail() again.

  • filePath string - Path of the file to replace

  • Returns Promise<result: boolean> - result indicates whether the replacement was successful


refreshThumbnail()

Refreshes the file thumbnail, and updates the properties like file size, color analysis, dimensions, etc.

  • Returns Promise<result: boolean> - result indicates whether the operation was successful


setCustomThumbnail(thumbnailPath)

Set a custom thumbnail for the file.

  • thumbnailPath string - Path of the thumbnail to set

  • Returns Promise<result: boolean> - result indicates whether the replacement was successful


open(options)

Display this file in the full list

  • options Object (optional) - Open options

    • window boolean (optional) - Whether to open the file in a new window, defaults to false

  • Returns Promise<void>

Hint: You can also directly call the eagle.item.open(itemId, options) method to open the file.

Note: The window parameter requires Eagle 4.0 build12 or higher.


select()

Select this file

  • Returns Promise<result: boolean> - result whether the selection was successful

Note: Calling the instance method select() will clear the current selection and select only this file. To batch select multiple files, use the static method eagle.item.select(itemIds).

Note: The select() method requires Eagle 4.0 build12 or higher.


Instance properties

id string

Read-only, file ID.

name string

File name.

ext string

Read-only, file extension.

width Interger

Image width.

height Interger

Image height.

url string

Source link.

isDeleted boolean

Read-only, is the file in the trash.

annotation string

File annotation.

tags string[]

File tags.

folders string[]

Belonging folder ids.

palettes Object[]

Read-only, color palette information.

size Interger

Read-only, file size.

star Interger

Rating information, 0 ~ 5.

importedAt Interger

Read-only, time the file was added.

modifiedAt Interger

Read-only, last modified time.

noThumbnail boolean

Read-only, the file doesn't have a thumbnail. Files without a thumbnail will be previewed using the original file.

noPreview boolean

Read-only, the file is not supported for double-click preview.

filePath string

Read-only, returns the file path.

fileURL string

Read-only, returns the file URL (file:///).

thumbnailPath string

Read-only, returns the thumbnail path.

thumbnailURL string

Read-only, returns the thumbnail URL (file:///). Use this property if you want to display the file in HTML.

metadataFilePathstring

Read-only, location of the metadata.json file for this file.

Last updated