feat(voice): support cover image uploads

This commit is contained in:
7788dev
2026-08-02 11:53:51 +08:00
parent 15f515c1ba
commit 93b3e624d8
5 changed files with 213 additions and 65 deletions
+12 -6
View File
@@ -4371,27 +4371,33 @@ ONLINE 已发布
### 播客上传声音
说明: 可以上传声音到播客,例子在 `/public/voice_upload.html` 访问地址: <a href="/voice_upload.html" target="_blank">/voice_upload.html</a>
说明: 登录后调用此接口,使用`'Content-Type': 'multipart/form-data'`上传声音文件 formData(name 为`songFile`),可通过 formData(name 为`imgFile`)同时上传声音封面。例子在 `/public/voice_upload.html` 访问地址: <a href="/voice_upload.html" target="_blank">/voice_upload.html</a>
**接口地址:** `/voice/upload`
**必选参数:**
`voiceListId`: 播客 id
`coverImgId`: 播客封面
`songFile`: 声音文件
`voiceListId`: 播客 id
`categoryId`: 分类 id
`secondCategoryId`:次级分类 id
`secondCategoryId`: 次级分类 id
`description`: 声音介绍
**可选参数:**
`imgFile`: 声音封面图片文件,上传后会自动生成图片 id。与`coverImgId`同时传入时,优先使用`imgFile`
`coverImgId`: 已上传的声音封面图片 id,未传入`imgFile`时使用该值
`songName`: 声音名称
`privacy`: 设为隐私声音,播客如果是隐私博客,则必须设为 1
`privacy`: 设为隐私声音,播客如果是隐私播客,则必须设为 1
`publishTime`:默认立即发布,定时发布的话需传入时间戳
`publishTime`: 默认立即发布,定时发布的话需传入时间戳
`autoPublish`: 是否发布动态,是则传入 1
+18 -9
View File
@@ -217,8 +217,13 @@
</div>
<div class="form-group">
<label>选择文件</label>
<input type="file" name="songFile" accept="audio/*" />
<label for="songFile">选择声音文件</label>
<input id="songFile" type="file" name="songFile" accept="audio/*" />
</div>
<div class="form-group">
<label for="imgFile">选择声音封面(可选)</label>
<input id="imgFile" type="file" name="imgFile" accept="image/*" />
</div>
<button class="btn" @click="submit">上传</button>
@@ -251,12 +256,13 @@
methods: {
submit() {
console.info('submit')
const file = document.querySelector('input[type=file]').files[0]
if (!file) {
alert('请选择文件')
const songFile = document.querySelector('input[name=songFile]').files[0]
const imgFile = document.querySelector('input[name=imgFile]').files[0]
if (!songFile) {
alert('请选择声音文件')
return
}
this.upload(file)
this.upload(songFile, imgFile)
},
async getData() {
@@ -286,14 +292,17 @@
}
},
upload(file) {
upload(songFile, imgFile) {
if (!this.currentVoice) {
alert('请先选择播客列表')
return
}
var formData = new FormData()
formData.append('songFile', file)
formData.append('songFile', songFile)
if (imgFile) {
formData.append('imgFile', imgFile)
}
axios({
method: 'post',
@@ -312,7 +321,7 @@
data: formData,
})
.then((res) => {
alert(`${file.name} 上传成功`)
alert(`${songFile.name} 上传成功`)
})
.catch((err) => {
console.error('上传失败:', err)