feat: add image upload functionality for articles
- Implemented image upload API in the article service, allowing users to upload images associated with articles. - Added validation for image size and type, ensuring only supported formats (PNG, JPG, GIF, WebP) are accepted. - Created a new Aliyun object storage client to handle image storage and retrieval. - Updated the article handler to include an endpoint for image uploads. - Enhanced error handling for image upload failures and added relevant error messages. - Introduced public URL generation for stored images, allowing access via signed tokens. - Updated localization files to include new messages related to image upload functionality. - Added tests for image upload and retrieval processes.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { createApiClient } from "@geo/http-client";
|
||||
import type {
|
||||
ApiEnvelope,
|
||||
ArticleDetail,
|
||||
ArticleImageUploadResponse,
|
||||
ArticleListParams,
|
||||
ArticleListResponse,
|
||||
ArticleVersion,
|
||||
@@ -214,6 +216,17 @@ export const articlesApi = {
|
||||
update(id: number, payload: UpdateArticleRequest) {
|
||||
return apiClient.put<ArticleDetail, UpdateArticleRequest>(`/api/tenant/articles/${id}`, payload);
|
||||
},
|
||||
async uploadImage(id: number, file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
const response = await apiClient.raw.post<ApiEnvelope<ArticleImageUploadResponse>>(
|
||||
`/api/tenant/articles/${id}/images`,
|
||||
formData,
|
||||
);
|
||||
|
||||
return response.data.data;
|
||||
},
|
||||
versions(id: number) {
|
||||
return apiClient.get<ArticleVersion[]>(`/api/tenant/articles/${id}/versions`);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user