upload 1
All checks were successful
Deploy to Server / deploy (push) Successful in 28s

This commit is contained in:
jeremygan2021
2026-03-22 22:21:02 +08:00
parent 94333b61b6
commit 41d6991d5c
7 changed files with 125 additions and 66 deletions

View File

@@ -94,14 +94,40 @@ export const uploadProjectFile = (filePath: string, projectId: number, fileName?
'Authorization': `Bearer ${Taro.getStorageSync('token')}`
}
}).then(res => {
console.log('Upload response:', res)
if (res.statusCode >= 200 && res.statusCode < 300) {
const data = JSON.parse(res.data)
console.log('Upload success, data:', data)
if (data.error) {
const error = new Error(data.error) as any
error.response = data
throw error
}
return data
}
console.error('Upload failed:', res)
throw new Error(`Upload failed: ${res.statusCode}`)
const error = new Error('Upload failed') as any
error.statusCode = res.statusCode
throw error
})
}
export const deleteProjectFile = (fileId: number) => {
const BASE_URL = (typeof process !== 'undefined' && process.env && process.env.TARO_APP_API_URL) || 'https://market.quant-speed.com/api'
return Taro.request({
url: `${BASE_URL}/competition/files/${fileId}/`,
method: 'DELETE',
header: {
'Authorization': `Bearer ${Taro.getStorageSync('token')}`
}
}).then(res => {
if (res.statusCode >= 200 && res.statusCode < 300) {
return true
}
const error = new Error('Delete failed') as any
error.statusCode = res.statusCode
try {
const data = JSON.parse(res.data)
error.response = data
} catch {}
throw error
})
}
@@ -120,9 +146,21 @@ export const uploadMedia = (filePath: string, type: 'image' | 'video') => {
}
}).then(res => {
if (res.statusCode >= 200 && res.statusCode < 300) {
return JSON.parse(res.data)
const data = JSON.parse(res.data)
if (data.error) {
const error = new Error(data.error) as any
error.response = data
throw error
}
return data
}
throw new Error('Upload failed')
const error = new Error('Upload failed') as any
error.statusCode = res.statusCode
try {
const data = JSON.parse(res.data)
error.response = data
} catch {}
throw error
})
}