halo/ui/packages/api-client
guqing ef37aa794b
feat: implement new mechanisms for generating and managing attachment thumbnails (#6454)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
实现了图片类型的附件缩略图生成和管理的新机制

实现依据 RFC:https://github.com/halo-dev/rfcs/pull/24

使用缩略图前需要配置 externalUrl 才能生成

**How to test it?**
1. 测试本地缩略图的文件是否正确,每个图片对应到相应 size 的目录如 thumbnails/w400 应该是一对一
2. 每个图片生成缩略图的只会在 `http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails` 中存在一份记录
3. 测试删除附件会删除对应的缩略图文件和 [thumbnails](http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails) 
记录
4. 修改 externalUrl 以上功能均不会受到影响

#### Which issue(s) this PR fixes:
Fixes #2387 

#### Does this PR introduce a user-facing change?
```release-note
附件图片支持生成多尺寸图片,文章支持响应式图片。
```
2024-08-26 10:27:14 +00:00
..
entry refactor: remove page cache feature (#6108) 2024-06-28 10:08:59 +00:00
src feat: implement new mechanisms for generating and managing attachment thumbnails (#6454) 2024-08-26 10:27:14 +00:00
.eslintignore Move folder console to ui 2024-02-02 22:22:51 +08:00
.eslintrc.js Move folder console to ui 2024-02-02 22:22:51 +08:00
.gitignore Move folder console to ui 2024-02-02 22:22:51 +08:00
.openapi_config.yaml Generate API docs and regenerate API client (#5742) 2024-04-19 02:34:07 +00:00
.prettierrc.js chore: bump vite to 5.x (#5920) 2024-05-16 06:18:36 +00:00
README.md docs: update readme for api client package (#6167) 2024-06-27 07:16:54 +00:00
build.config.ts Move folder console to ui 2024-02-02 22:22:51 +08:00
openapitools.json Generate API docs and regenerate API client (#5742) 2024-04-19 02:34:07 +00:00
package.json chore: bump vite-related dependencies (#6482) 2024-08-20 03:28:47 +00:00
tsconfig.json feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00
vite.config.ts feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00

README.md

@halo-dev/api-client

Halo 2.0 的 JavaScript API 客户端请求库。使用 OpenAPI Generator 生成。

使用

import {
  coreApiClient,
  consoleApiClient,
  ucApiClient,
  publicApiClient,
  createCoreApiClient,
  createConsoleApiClient,
  createUcApiClient,
  createPublicApiClient,
  axiosInstance
} from "@halo-dev/api-client"
  • coreApiClient: 为 Halo 所有自定义模型的 CRUD 接口封装的 api client。
  • consoleApiClient: 为 Halo 针对 Console 提供的接口封装的 api client。
  • ucApiClient: 为 Halo 针对 UC 提供的接口封装的 api client。
  • publicApiClient: 为 Halo 所有公开访问的接口封装的 api client。
  • createCoreApiClient: 用于创建自定义模型的 CRUD 接口封装的 api client需要传入 axios 实例。
  • createConsoleApiClient: 用于创建 Console 接口封装的 api client需要传入 axios 实例。
  • createUcApiClient: 用于创建 UC 接口封装的 api client需要传入 axios 实例。
  • createPublicApiClient: 用于创建公开访问接口封装的 api client需要传入 axios 实例。
  • axiosInstance: 内部默认创建的 axios 实例。

在插件中使用

pnpm install @halo-dev/api-client axios

由于已经在 Console 和 UC 项目中引入并设置好了 Axios 拦截器,所以直接使用即可:

import { coreApiClient } from "@halo-dev/api-client"

coreApiClient.content.post.listPost().then(response => {
  // handle response
})

此外,在最新的 @halo-dev/ui-plugin-bundler-kit@2.17.0 中,已经排除了 @halo-dev/api-clientaxios 依赖,所以最终产物中的相关依赖会自动使用 Halo 本身提供的依赖,无需关心最终产物大小。

详细文档可查阅:插件开发 / API 请求

在外部项目中使用

pnpm install @halo-dev/api-client axios
import axios from "axios"

const axiosInstance = axios.create({
  baseURL: "http://localhost:8090"
})

const coreApiClient = createCoreApiClient(axiosInstance)

coreApiClient.content.post.listPost().then(response => {
  // handle response
})