This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user