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.
🦄 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.
options
Object - Query conditionsid
string (optional) - File idids
string[] (optional) - Array of file idsisSelected
boolean (optional) - Currently selected filesisUntagged
boolean (optional) - Files that have not been taggedisUnfiled
boolean (optional) - Files that have not been categorizedkeywords
string[] (optional) - Contains keywordstags
string[] (optional) - Contains tagsfolders
string[] (optional) - Contains foldersext
string (optional) - Formatannotation
string (optional) - Annotationrating
Integer (optional) - Rating, range from0 ~ 5
url
string (optional) - Source URLshape
string (optional) - Shape, options aresquare
,portrait
,panoramic-portrait
,landscape
,panoramic-landscape
Returns
Promise<items: Item[]>
-items
query result
getAll()
Return all files.
Returns
Promise<items: Item[]>
-items
all 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.
itemId
stringReturns
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
addFromURL(url, options)
Add an image link to Eagle.
url
string - The image link to add, supportshttp
,https
,base64
options
Objectname
string (optional) - File namewebsite
string (optional) - Source URLtags
string[] (optional) - Tagsfolders
string[] (optional) - Belonging folder IDsannotation
string (optional) - Annotation
Returns
Promise<itemId: string>
-itemId
is the successfully created item ID
addFromBase64(base64, options)
Add a base64 image to Eagle.
base64
string - Base64 format imageoptions
Objectname
string (optional) - File namewebsite
string (optional) - Source URLtags
string[] (optional) - Tagsfolders
string[] (optional) - Belonging folder IDsannotation
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.
path
string - The file path to addoptions
Objectname
string (optional) - File namewebsite
string (optional) - Source URLtags
string[] (optional) - Tagsfolders
string[] (optional) - Belonging folder IDsannotation
string (optional) - Annotation
Returns
Promise<itemId: string>
-itemId
is the successfully created item ID
addBookmark(url, options)
Add a bookmark link to Eagle.
url
string - The bookmark link to addoptions
Objectname
string (optional) - Bookmark namebase64
string (optional) - Custom thumbnail in base64 formattags
string[] (optional) - Tagsfolders
string[] (optional) - Belonging folder IDsannotation
string (optional) - Annotation
Returns
Promise<itemId: string>
-itemId
is the successfully created item ID
open(itemId)
Display the file corresponding to itemId
in the full list
itemId
string - ID of the file to displayReturns
Promise<result: boolean>
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.
🦄 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>
-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.
🦄 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.
filePath
string - Path of the file to replaceReturns
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 setReturns
Promise<result: boolean>
-result
indicates whether the replacement was successful
open()
Display this file in the full list
Returns
Promise<void>
Hint: You can also directly call the eagle.item.open(itemId)
method to open the file.
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.
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.
metadataFilePath
string
metadataFilePath
stringRead-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