item(項目)

透過 eagle.item API 可以方便的查詢當前資源庫內容或新增新的內容到資源庫中。

eagle.onPluginCreate(async (plugin) => {
    // 取得 Eagle 應用當前被選中的檔案
    let items = await eagle.item.getSelected();
    let item = items[0];
    
    // 修改屬性
    item.name = 'New Name';
    item.tags = ['tag1', 'tag2'];
    
    // 儲存修改
    await item.save();
});

方法

get(options)

萬用搜尋方法,可獲取指定條件的檔案。

  • options Object - 查詢條件

    • id string (可選) - 檔案 id

    • ids string[] (可選) - 檔案 id 數組

    • isSelected boolean (可選) - 正在被選中的檔案

    • isUntagged boolean (可選) - 尚未標籤

    • isUnfiled boolean (可選) - 尚未分類

    • keywords string[] (可選) - 包含關鍵字

    • tags string[] (可選) - 包含標籤

    • folders string[] (可選) - 包含資料夾

    • ext string (可選) - 格式

    • annotation string (可選) - 註解

    • rating Interger (可選) - 評分,0 ~ 5

    • url string (可選) - 來源連結

    • shape string (可選) - 形狀,squareportraitpanoramic-portraitlandscapepanoramic-landscape

    • fields string[] (可選) - 指定返回的欄位,僅返回需要的資料以提升效能

  • 返回 Promise<items: Item[]> - items 查詢結果

提示:使用 fields 參數可以顯著提升效能,特別是在處理大量檔案時只需要部分資訊的場景。


getAll()

返回所有檔案

  • 返回 Promise<items: Item[]> - items 所有檔案


getById(itemId)

返回指定 ID 之檔案

  • itemId string

  • 返回 Promise<item: Item> - item 對應 ID 的檔案

getByIds(itemIds)

返回指定 IDs 之檔案

  • itemIds string[]

  • 返回 Promise<items: Item[]> - items 對應 IDs 的檔案


getIdsWithModifiedAt()

快速獲取所有檔案的 ID 和最後修改時間

  • 返回 Promise<items: Object[]> - items 包含 idmodifiedAt 的物件陣列

提示:此方法針對效能最佳化,當只需要檔案 ID 和修改時間資訊時,比使用 get() 效能更好。


getSelected()

返回應用當前選中的檔案

  • 返回 Promise<items: Item[]> - items 選中之檔案


count(options)

計算符合條件的檔案數量,支援與 get() 方法相同的查詢條件。

  • options Object - 查詢條件(與 get() 方法相同)

    • id string (可選) - 檔案 id

    • ids string[] (可選) - 檔案 id 陣列

    • isSelected boolean (可選) - 正在被選中的檔案

    • isUntagged boolean (可選) - 尚未標籤

    • isUnfiled boolean (可選) - 尚未分類

    • keywords string[] (可選) - 包含關鍵字

    • tags string[] (可選) - 包含標籤

    • folders string[] (可選) - 包含資料夾

    • ext string (可選) - 格式

    • annotation string (可選) - 註解

    • rating Interger (可選) - 評分,0 ~ 5

    • url string (可選) - 來源連結

    • shape string (可選) - 形狀,squareportraitpanoramic-portraitlandscapepanoramic-landscape

  • 返回 Promise<count: number> - count 符合條件的檔案數量

提示:當只需要獲取檔案數量時,使用 count()get() 效能更好。


countAll()

快速返回資源庫中所有檔案的總數

  • 返回 Promise<count: number> - count 所有檔案數量

提示:countAll() 針對效能進行了最佳化,比 getAll() 後計算陣列長度要快得多。


countSelected()

返回應用當前選中的檔案數量

  • 返回 Promise<count: number> - count 選中的檔案數量


select(itemIds)

選中指定的檔案

  • itemIds string[] - 要選中的檔案 ID 陣列

  • 返回 Promise<result: boolean> - result 是否選中成功

提示:呼叫此方法會取代當前的選中狀態,而不是追加到現有選中項。

提示:select() 方法需要 Eagle 4.0 build12 以上版本支援。


addFromURL(url, options)

將圖片連結新增至 Eagle

  • urlstring - 欲新增圖片連結,支援 httphttpsbase64

  • options Object

    • name string (可選) - 檔案名

    • website string (可選) - 來源網址

    • tags string[] (可選) - 標籤

    • folders string[] (可選) - 所屬資料夾 IDs

    • annotation string (可選) - 註解

  • 返回 Promise<itemId: string> - itemId成功新增的項目 ID


addFromBase64(base64, options)

新增 base64 圖片至 Eagle

  • base64string - base64 格式圖片

  • options Object

    • name string (可選) - 檔案名

    • website string (可選) - 來源網址

    • tags string[] (可選) - 標籤

    • folders string[] (可選) - 所屬資料夾 IDs

    • annotation string (可選) - 註解

  • 返回 Promise<itemId: string> - itemId成功新增的項目 ID


addFromPath(path, options)

從本機檔案路徑新增檔案至 Eagle

  • pathstring - 欲新增檔案路徑

  • options Object

    • name string (可選) - 檔案名

    • website string (可選) - 來源網址

    • tags string[] (可選) - 標籤

    • folders string[] (可選) - 所屬資料夾 IDs

    • annotation string (可選) - 註解

  • 返回 Promise<itemId: string> - itemId成功新增的項目 ID


addBookmark(url, options)

新增書籤連結至 Eagle

  • urlstring - 欲新增書籤連結

  • options Object

    • name string (可選) - 書籤名

    • base64 string (可選) - 自訂縮圖 base64 格式

    • tags string[] (可選) - 標籤

    • folders string[] (可選) - 所屬資料夾 IDs

    • annotation string (可選) - 註解

  • 返回 Promise<itemId: string> - itemId成功新增的項目 ID


open(itemId, options)

在全部列表顯示 itemId 對應的檔案

  • itemIdstring - 欲顯示檔案 ID

  • options Object (可選) - 開啟選項

    • window boolean (可選) - 是否在新視窗中開啟檔案,預設為 false

  • 返回 Promise<result: boolean>

提示:window 參數需要 Eagle 4.0 build12 以上版本支援。

提示:你也可以直接呼叫 item 實例的 open() 方法開啓檔案。


類:Item

由 Eagle API get返回的 Object 類型,提供修改、儲存功能。


實例方法

save()

儲存所有修改

  • 返回 Promise<result: boolean> - result是否修改成功


moveToTrash()

將檔案丟到垃圾桶

  • 返回 Promise<result: boolean> - result是否成功刪除


replaceFile(filePath)

使用指定檔案替換原檔案,將自動重新整理縮圖,無須再次呼叫 refreshThumbnail()

  • filePathstring - 欲替換檔案之路徑

  • 返回 Promise<result: boolean> - result是否替換成功


refreshThumbnail()

重新重新整理檔案縮圖,同時也會重新獲取檔案大小、顏色分析、尺寸等屬性。

  • 返回 Promise<result: boolean> - result是否成功


setCustomThumbnail(thumbnailPath)

為檔案設定自定縮圖。

  • thumbnailPathstring - 欲設定縮圖的路徑

  • 返回 Promise<result: boolean> - result是否替換成功


open(options)

在全部列表顯示此檔案

  • options Object (可選) - 開啟選項

    • window boolean (可選) - 是否在新視窗中開啟檔案,預設為 false

  • 返回 Promise<void>

提示:你也可以直接呼叫 eagle.item.open(itemId, options)方法開啓資料夾。

提示:window 參數需要 Eagle 4.0 build12 以上版本支援。


select()

選中此檔案

  • 返回 Promise<result: boolean> - result 是否選中成功

提示:呼叫實例方法 select() 會清空當前選中並僅選中此檔案。如需批量選中多個檔案,請使用靜態方法 eagle.item.select(itemIds)

提示:select() 方法需要 Eagle 4.0 build12 以上版本支援。


實例屬性

id string

唯讀,檔案 ID。

name string

檔案名。

ext string

唯讀,檔案副檔名。

width Interger

圖片寬度。

height Interger

圖片高度。

url string

來源連結。

isDeleted boolean

唯讀,檔案是否在垃圾桶。

annotation string

檔案註解。

tags string[]

檔案標籤。

folders string[]

所屬資料夾 ids。

palettes Object[]

唯讀,色票資訊。

size Interger

唯讀,檔案大小。

star Interger

評分資訊,0 ~ 5

importedAt Interger

唯讀,新增時間。

modifiedAt Interger

唯讀,最後修改時間。

noThumbnail boolean

唯讀,檔案是否有縮圖,無縮圖檔案將以原始檔案進行預覽。

noPreview boolean

唯讀,檔案是否支援雙擊預覽。

filePath string

唯讀,返回檔案所在路徑。

fileURL string

唯讀,返回檔案所在路徑之連結(file:///)。

thumbnailPath string

唯讀,返回縮圖路徑。

thumbnailURL string

唯讀,返回縮圖連結(file:///),如需在 HTML 顯示該檔案,可以使用這個屬性。

metadataFilePathstring

唯讀,該檔案 metadata.json 所在位置。

Last updated