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();
});🦄 Best Practice: To ensure data security, use the item API provided save() method for data access and modification, and avoid directly modifying the metadata.json or any files under the Eagle resource library.
Methods
get(options)
Universal search method that can get files with specified conditions.
optionsObject - Query conditionsidstring (optional) - File ididsstring[] (optional) - Array of file idsisSelectedboolean (optional) - Currently selected filesisUntaggedboolean (optional) - Files that have not been taggedisUnfiledboolean (optional) - Files that have not been categorizedkeywordsstring[] (optional) - Contains keywordstagsstring[] (optional) - Contains tagsfoldersstring[] (optional) - Contains foldersextstring (optional) - Formatannotationstring (optional) - AnnotationratingInteger (optional) - Rating, range from0 ~ 5urlstring (optional) - Source URLshapestring (optional) - Shape, options aresquare,portrait,panoramic-portrait,landscape,panoramic-landscapefieldsstring[] (optional) - Specify fields to return, only returning needed data to improve performance
Returns
Promise<items: Item[]>-itemsquery result
getAll()
Return all files.
Returns
Promise<items: Item[]>-itemsall files
🦄 Best Practice: If the resource library has a large number of files (e.g., 20W+), avoid calling this method without restrictions to avoid reducing application performance.
getById(itemId)
Return the file with the specified ID.
itemIdstringReturns
Promise<item: Item>-itemthe file with the corresponding ID
getByIds(itemIds)
Return the files with the specified IDs.
itemIdsstring[]Returns
Promise<items: Item[]>-itemsthe files with the corresponding IDs
getSelected()
Return the currently selected files in the application.
Returns
Promise<items: Item[]>-itemsselected files
getIdsWithModifiedAt()
Quickly get IDs and last modified times for all files.
Returns
Promise<items: Object[]>- Array of objects containingidandmodifiedAt
count(options)
Returns the number of files that match the specified query conditions.
optionsObject - Query conditions (same asget()method)idstring (optional) - File ididsstring[] (optional) - Array of file idsisSelectedboolean (optional) - Currently selected filesisUntaggedboolean (optional) - Files that have not been taggedisUnfiledboolean (optional) - Files that have not been categorizedkeywordsstring[] (optional) - Contains keywordstagsstring[] (optional) - Contains tagsfoldersstring[] (optional) - Contains foldersextstring (optional) - Formatannotationstring (optional) - AnnotationratingInteger (optional) - Rating, range from0 ~ 5urlstring (optional) - Source URLshapestring (optional) - Shape, options aresquare,portrait,panoramic-portrait,landscape,panoramic-landscape
Returns
Promise<count: number>-countnumber of files matching the query conditions
countAll()
Returns the total number of files in the resource library.
Returns
Promise<count: number>-counttotal number of files
countSelected()
Returns the number of currently selected files in the application.
Returns
Promise<count: number>-countnumber of selected files
select(itemIds)
Select specified files
itemIdsstring[] - Array of file IDs to selectReturns
Promise<result: boolean>-resultwhether the selection was successful
addFromURL(url, options)
Add an image link to Eagle.
urlstring - The image link to add, supportshttp,https,base64optionsObjectnamestring (optional) - File namewebsitestring (optional) - Source URLtagsstring[] (optional) - Tagsfoldersstring[] (optional) - Belonging folder IDsannotationstring (optional) - Annotation
Returns
Promise<itemId: string>-itemIdis the successfully created item ID
addFromBase64(base64, options)
Add a base64 image to Eagle.
base64string - Base64 format imageoptionsObjectnamestring (optional) - File namewebsitestring (optional) - Source URLtagsstring[] (optional) - Tagsfoldersstring[] (optional) - Belonging folder IDsannotationstring (optional) - Annotation
Returns
Promise<itemId: string>-itemIdis the successfully created item ID
addFromPath(path, options)
Add files to Eagle from a local file path.
pathstring - The file path to addoptionsObjectnamestring (optional) - File namewebsitestring (optional) - Source URLtagsstring[] (optional) - Tagsfoldersstring[] (optional) - Belonging folder IDsannotationstring (optional) - Annotation
Returns
Promise<itemId: string>-itemIdis the successfully created item ID
addBookmark(url, options)
Add a bookmark link to Eagle.
urlstring - The bookmark link to addoptionsObjectnamestring (optional) - Bookmark namebase64string (optional) - Custom thumbnail in base64 formattagsstring[] (optional) - Tagsfoldersstring[] (optional) - Belonging folder IDsannotationstring (optional) - Annotation
Returns
Promise<itemId: string>-itemIdis the successfully created item ID
open(itemId, options)
Display the file corresponding to itemId in the full list
itemIdstring - ID of the file to displayoptionsObject (optional) - Open optionswindowboolean (optional) - Whether to open the file in a new window, defaults tofalse
Returns
Promise<result: boolean>
Class: Item
Object type returned by Eagle API get, provides modification and save features.
🦄 Best Practice: To ensure data security, use save() method provided by the Item instance for data access and modification. Avoid directly modifying metadata.json or any files in the Eagle repository.
Instance methods
save()
Save all modifications
Returns
Promise<result: boolean>-resultindicates whether the modification was successful
moveToTrash()
Move the file to the trash.
Returns
Promise<result: boolean>-resultIndicates 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.
🦄 Best Practice: Directly modifying the file you want to change can be risky. Errors or exceptions during the process may cause file corruption and be irreversible. Therefore, to ensure a more robust operation, first save the new version of the file in another location on your computer. After verifying it's correct, use the replaceFile() method to replace it.
filePathstring - Path of the file to replaceReturns
Promise<result: boolean>-resultindicates 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>-resultindicates whether the operation was successful
setCustomThumbnail(thumbnailPath)
Set a custom thumbnail for the file.
thumbnailPathstring - Path of the thumbnail to setReturns
Promise<result: boolean>-resultindicates whether the replacement was successful
open(options)
Display this file in the full list
optionsObject (optional) - Open optionswindowboolean (optional) - Whether to open the file in a new window, defaults tofalse
Returns
Promise<void>
select()
Select this file
Returns
Promise<result: boolean>-resultwhether the selection was successful
Instance properties
id string
id stringRead-only, file ID.
name string
name stringFile name.
ext string
ext stringRead-only, file extension.
width Interger
width IntergerImage width.
height Interger
height IntergerImage height.
url string
url stringSource link.
isDeleted boolean
isDeleted booleanRead-only, is the file in the trash.
annotation string
annotation stringFile annotation.
tags string[]
tags string[]File tags.
folders string[]
folders string[]Belonging folder ids.
palettes Object[]
palettes Object[]Read-only, color palette information.
size Interger
size IntergerRead-only, file size.
star Interger
star IntergerRating information, 0 ~ 5.
importedAt Interger
importedAt IntergerRead-only, time the file was added.
modifiedAt Interger
modifiedAt IntergerRead-only, last modified time.
noThumbnail boolean
noThumbnail booleanRead-only, the file doesn't have a thumbnail. Files without a thumbnail will be previewed using the original file.
noPreview boolean
noPreview booleanRead-only, the file is not supported for double-click preview.
filePath string
filePath stringRead-only, returns the file path.
fileURL string
fileURL stringRead-only, returns the file URL (file:///).
thumbnailPath string
thumbnailPath stringRead-only, returns the thumbnail path.
thumbnailURL string
thumbnailURL stringRead-only, returns the thumbnail URL (file:///). Use this property if you want to display the file in HTML.
metadataFilePathstring
metadataFilePathstringRead-only, location of the metadata.json file for this file.
🦄 Best Practice: To ensure data security, use the item API provided save() method for data access and modifications. Avoid directly modifying metadata.json.
Last updated