修改礼物不支持
This commit is contained in:
parent
c0c81cd97b
commit
0c65edfa6f
@ -45,7 +45,7 @@ import {
|
|||||||
translateResourceCodes,
|
translateResourceCodes,
|
||||||
} from "@/features/resources/batchUpload.js";
|
} from "@/features/resources/batchUpload.js";
|
||||||
import { useResourceListPage } from "@/features/resources/hooks/useResourcePages.js";
|
import { useResourceListPage } from "@/features/resources/hooks/useResourcePages.js";
|
||||||
import { uploadImagesBatch } from "@/shared/api/upload";
|
import { uploadFilesBatch } from "@/shared/api/upload";
|
||||||
import { useToast } from "@/shared/ui/ToastProvider.jsx";
|
import { useToast } from "@/shared/ui/ToastProvider.jsx";
|
||||||
import styles from "@/features/resources/resources.module.css";
|
import styles from "@/features/resources/resources.module.css";
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ export function ResourceListPage() {
|
|||||||
label: `上传素材 ${index + 1}-${index + chunk.length}/${uploadEntries.length}`,
|
label: `上传素材 ${index + 1}-${index + chunk.length}/${uploadEntries.length}`,
|
||||||
running: true,
|
running: true,
|
||||||
});
|
});
|
||||||
const results = await uploadImagesBatch(chunk.map((entry) => entry.file));
|
const results = await uploadFilesBatch(chunk.map((entry) => entry.file));
|
||||||
results.forEach((result, resultIndex) => {
|
results.forEach((result, resultIndex) => {
|
||||||
const entry = chunk[resultIndex];
|
const entry = chunk[resultIndex];
|
||||||
resources[entry.resourceIndex][entry.role === "cover" ? "coverUrl" : "animationUrl"] = result.url;
|
resources[entry.resourceIndex][entry.role === "cover" ? "coverUrl" : "animationUrl"] = result.url;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { afterEach, expect, test, vi } from "vitest";
|
import { afterEach, expect, test, vi } from "vitest";
|
||||||
import { setAccessToken } from "@/shared/api/request";
|
import { setAccessToken } from "@/shared/api/request";
|
||||||
import { uploadFile, uploadImage, uploadImagesBatch } from "@/shared/api/upload";
|
import { uploadFile, uploadFilesBatch, uploadImage, uploadImagesBatch } from "@/shared/api/upload";
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
setAccessToken("");
|
setAccessToken("");
|
||||||
@ -46,7 +46,30 @@ test("uploadFile sends multipart data to generated file endpoint", async () => {
|
|||||||
expect(init?.headers).not.toHaveProperty("Content-Type");
|
expect(init?.headers).not.toHaveProperty("Content-Type");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("uploadImagesBatch sends multipart data to admin batch endpoint", async () => {
|
test("uploadFilesBatch sends multipart data to admin generic batch endpoint", async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
"fetch",
|
||||||
|
vi.fn(
|
||||||
|
async () =>
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
code: 0,
|
||||||
|
data: [{ url: "https://media.haiyihy.com/admin/files/gift.mp4" }],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await uploadFilesBatch([new File(["video"], "gift.mp4", { type: "video/mp4" })]);
|
||||||
|
const [url, init] = vi.mocked(fetch).mock.calls[0];
|
||||||
|
|
||||||
|
expect(String(url)).toContain("/api/v1/admin/files/batch-upload");
|
||||||
|
expect(init?.method).toBe("POST");
|
||||||
|
expect(init?.body).toBeInstanceOf(FormData);
|
||||||
|
expect(init?.headers).not.toHaveProperty("Content-Type");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uploadImagesBatch sends multipart data to admin image batch endpoint", async () => {
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
"fetch",
|
"fetch",
|
||||||
vi.fn(
|
vi.fn(
|
||||||
|
|||||||
@ -24,6 +24,18 @@ export function uploadImage(file: File): Promise<UploadResultDto> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function uploadFilesBatch(files: File[]): Promise<UploadResultDto[]> {
|
||||||
|
const formData = new FormData();
|
||||||
|
files.forEach((file) => {
|
||||||
|
formData.append("files", file);
|
||||||
|
});
|
||||||
|
|
||||||
|
return apiRequest<UploadResultDto[], FormData>("/v1/admin/files/batch-upload", {
|
||||||
|
body: formData,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function uploadImagesBatch(files: File[]): Promise<UploadResultDto[]> {
|
export function uploadImagesBatch(files: File[]): Promise<UploadResultDto[]> {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user