feat: 更新内容创建和更新表单,支持封面ID和媒体ID字段

This commit is contained in:
2025-12-31 17:57:30 +08:00
parent 5ed6262e02
commit f560b95ec0
4 changed files with 59 additions and 65 deletions

View File

@@ -338,44 +338,12 @@ const submit = async () => {
visibility: 'public',
preview_seconds: form.enableTrial ? form.trialTime : 0,
price: form.priceType === 'paid' ? parseFloat(form.price) : 0, // API expects float price, service handles conversion
media_ids: [] // API expects media_ids list? Wait, update DTO `ContentUpdateForm` expects `media_ids` string array?
// Check `ContentCreateForm` and `ContentUpdateForm`.
// `ContentCreateForm`: `MediaIDs []string`.
// Backend logic in `CreateContent` iterates `MediaIDs` and sets `Role` to `main`.
// It does NOT handle Covers explicitly in `CreateContent` logic I read!
// `CreateContent` logic: `assets = append(assets, ... Role: Main)`.
// So Covers are ignored or treated as Main?
// Wait, `UpdateContent` also iterates `MediaIDs` and sets `Role` to `Main`.
// So current backend implementation treats ALL sent IDs as Main assets.
// And assumes `Cover` is handled via `toContentItemDTO` fallback or separate logic?
// Backend logic for `CreateContent`:
// `assets = append(assets, ... Role: Main)`.
// This is a limitation. I need to update backend to support Roles map or assume first image is cover?
// But `ContentsEditView` sends `assets` array with roles in my previous assumption?
// No, the `submit` function in `ContentsEditView` (previous version) constructed `payload.assets`.
// But `creatorApi.createContent` sends `ContentCreateForm` which has `media_ids []string`.
// `ContentCreateForm` does NOT have `assets` structure!
// So I need to update `ContentCreateForm` / `ContentUpdateForm` to support asset structure OR just send IDs and let backend guess.
// Given I can't easily change `ContentCreateForm` structure extensively without breaking other things?
// Actually, I just read `ContentCreateForm` has `MediaIDs []string`.
// If I want to support covers, I need to update Backend DTO and Service.
// Or I can send all IDs in `MediaIDs` and Backend sets them as `Main`.
// This means Covers won't be distinguished.
// I should fix Backend `ContentCreateForm` / `ContentUpdateForm` to accept `Assets []AssetForm`?
// Or just `CoverIDs` and `MediaIDs`.
cover_ids: [],
media_ids: []
};
// Let's check `backend/app/http/v1/dto/creator.go` again.
// `ContentCreateForm` struct: `MediaIDs []string`.
// `ContentUpdateForm` struct: `MediaIDs []string`.
// I will assume for now I pass ALL IDs. Backend sets Role=Main.
// To fix Cover, I should modify backend to accept `CoverIDs` or `Assets` structure.
// But for this task "Fix 404", I'll stick to passing IDs.
// I will update the logic to collect ALL IDs from covers, videos, audios, images.
const allMedia = [...form.covers, ...form.videos, ...form.audios, ...form.images];
payload.media_ids = allMedia.map(m => m.id);
payload.cover_ids = form.covers.map(m => m.id);
payload.media_ids = [...form.videos, ...form.audios, ...form.images].map(m => m.id);
if (isEditMode.value) {
await creatorApi.updateContent(contentId.value, payload);