> For the complete documentation index, see [llms.txt](https://developer.eagle.cool/web-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.eagle.cool/web-api/zh-tw/api/library.md).

# Library

## 端點概覽

| 方法   | 端點                        | 說明        |
| ---- | ------------------------- | --------- |
| GET  | `/api/v2/library/info`    | 取得資源庫中繼資料 |
| GET  | `/api/v2/library/history` | 取得歷史資料庫列表 |
| POST | `/api/v2/library/switch`  | 切換至指定資料庫  |
| GET  | `/api/v2/library/icon`    | 取得資料庫圖示   |

***

## GET /api/v2/library/info <a href="#info" id="info"></a>

回傳目前開啟的 Eagle 資源庫中繼資料，包括名稱、路徑和設定。

### 回應

```json
{
    "status": "success",
    "data": {
        "name": "My Design Library",
        "path": "D:\\Eagle Libraries\\My Design Library.library",
        "modificationTime": 1700000000000,
        "applicationVersion": "4.0",
        "folders": [],
        "smartFolders": [],
        "quickAccess": [],
        "tagGroups": []
    }
}
```

### 範例

```javascript
await fetch("http://localhost:41595/api/v2/library/info").then(r => r.json());
```

***

## GET /api/v2/library/history <a href="#history" id="history"></a>

取得歷史資料庫列表。回傳分頁結果。

### 查詢參數

* `offset` integer（可選）— 分頁偏移量，預設 `0`
* `limit` integer（可選）— 分頁限制，預設 `50`，最大 `1000`

### 回應

```json
{
    "status": "success",
    "data": {
        "data": [
            {
                "name": "My Design Library",
                "path": "D:\\Eagle Libraries\\My Design Library.library"
            }
        ],
        "total": 3,
        "offset": 0,
        "limit": 50
    }
}
```

### 範例

```javascript
await fetch("http://localhost:41595/api/v2/library/history").then(r => r.json());

// 分頁取得
await fetch("http://localhost:41595/api/v2/library/history?offset=0&limit=10").then(r => r.json());
```

***

## POST /api/v2/library/switch <a href="#switch" id="switch"></a>

切換至指定資料庫。

### 請求主體

* `libraryPath` string（必填）— 要切換的資料庫路徑

### 回應

```json
{
    "status": "success",
    "data": true
}
```

### 範例

```javascript
await fetch("http://localhost:41595/api/v2/library/switch", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
        libraryPath: "D:\\Eagle Libraries\\My Design Library.library"
    })
}).then(r => r.json());
```

***

## GET /api/v2/library/icon <a href="#icon" id="icon"></a>

取得資料庫圖示。

### 查詢參數

* `libraryPath` string（必填）— 資料庫路徑

### 回應

回傳圖示的圖片資料。

### 範例

```javascript
await fetch("http://localhost:41595/api/v2/library/icon?libraryPath=D%3A%5CEagle%20Libraries%5CMy%20Design%20Library.library")
    .then(r => r.blob());
```

***

## Library 屬性 <a href="#properties" id="properties"></a>

資源庫物件包含以下屬性：

| 屬性                   | 類型        | 說明                 |
| -------------------- | --------- | ------------------ |
| `name`               | string    | 資源庫顯示名稱            |
| `path`               | string    | `.library` 目錄的完整路徑 |
| `modificationTime`   | integer   | 最後修改時間戳記           |
| `applicationVersion` | string    | 建立此資源庫的 Eagle 版本   |
| `folders`            | Object\[] | 頂層資料夾結構            |
| `smartFolders`       | Object\[] | 智慧型資料夾設定           |
| `quickAccess`        | Object\[] | 快速存取項目             |
| `tagGroups`          | Object\[] | 標籤群組定義             |
