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.
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
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.
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.
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
addComment(commentData) (Eagle 4.0 build22+)
Add a comment to this item. Supports image rect comments and video timestamp comments.
commentDataObject - Comment dataannotationstring (optional) - Comment textxnumber (optional) - Rect X position (image comment)ynumber (optional) - Rect Y position (image comment)widthnumber (optional) - Rect width, must > 0 (image comment)heightnumber (optional) - Rect height, must > 0 (image comment)durationnumber (optional) - Video timestamp in seconds, must >= 0 (video comment)
Returns
Promise<comment: Object>- The newly created comment object
updateComment(commentId, updateData) (Eagle 4.0 build22+)
Update an existing comment. Only the provided fields are updated.
commentIdstring - The comment ID to updateupdateDataObject - Fields to updateannotationstring (optional) - New comment textxnumber (optional) - New X position (image comment only)ynumber (optional) - New Y position (image comment only)widthnumber (optional) - New width (image comment only)heightnumber (optional) - New height (image comment only)durationnumber (optional) - New timestamp (video comment only)
Returns
Promise<comment: Object>- The updated comment object
removeComment(commentId) (Eagle 4.0 build22+)
Remove a comment from this item.
commentIdstring - The comment ID to removeReturns
Promise<result: boolean>- Whether the removal 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
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.
comments Object[] (Eagle 4.0 build22+)
Read-only, item comments/annotations. Use addComment(), updateComment(), removeComment() methods to modify.
size Interger
Read-only, file size.
star Interger
Rating information, 0 ~ 5.
importedAt Interger
Import time (timestamp). Readable and writable, call save() after modification.
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