fix(AddTorrentDialog): Prevent undefined values from being sent through API (#1330)

This commit is contained in:
Rémi Marseault 2023-11-20 20:44:16 +01:00 committed by GitHub
parent 3614081f19
commit 6575ade19e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View file

@ -137,19 +137,17 @@ const inactiveSeedingTimeLimit = computed({
function submit() {
if (!isFormValid.value) return
const promise = torrentStore.addTorrents(form.value, files.value)
.then(() => {
addTorrentStore.resetForm()
close()
})
toast.promise(promise, {
toast.promise(torrentStore.addTorrents(files.value, urls.value, form.value), {
pending: t('dialogs.add.pending'),
error: t('dialogs.add.error', addTorrentStore.pendingTorrentsCount),
success: t('dialogs.add.success', addTorrentStore.pendingTorrentsCount)
}, {
autoClose: 1500
})
.then(() => {
addTorrentStore.resetForm()
close()
})
}
function close() {

View file

@ -226,14 +226,14 @@ export class QBitApi {
// Post
async addTorrents(params: AddTorrentPayload, torrents: File[]): Promise<void> {
async addTorrents(torrents: File[], urls: string, params: AddTorrentPayload): Promise<void> {
let data
if (torrents) {
// torrent files
const formData = new FormData()
if (params) {
for (const [key, value] of Object.entries(params)) {
formData.append(key, value)
!!value && formData.set(key, value)
}
}
@ -246,7 +246,7 @@ export class QBitApi {
// magnet links
data = new URLSearchParams(params as Parameters)
}
!!urls && data.set('urls', urls)
return this.axios.post('/torrents/add', data)
}

View file

@ -99,8 +99,8 @@ export const useTorrentStore = defineStore('torrents', () => {
await qbit.setTorrentLocation(hashes, newPath)
}
async function addTorrents(payload: AddTorrentPayload, torrents: File[]) {
return await qbit.addTorrents(payload, torrents)
async function addTorrents(torrents: File[], urls: string, payload: AddTorrentPayload) {
return await qbit.addTorrents(torrents, urls, payload)
}
async function getTorrentProperties(hash: string) {

View file

@ -49,8 +49,6 @@ export default interface AddTorrentPayload {
tags?: string
/** Set torrent upload speed limit. Unit in bytes/second */
upLimit?: number
/** URLs separated with newlines */
urls?: string
/** Whether to enable use of `downloadPath` */
useDownloadPath?: boolean
}