mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-08 17:32:27 +08:00
- Replace .eslintrc.json with eslint.config.mjs - Simplify configuration using @antfu/eslint-config - Add necessary ESLint plugin dependencies - Disable overly strict style rules - Set package.json type to module for ESM support - Fix ESLint disable comment format 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
866 B
TypeScript
39 lines
866 B
TypeScript
'use client'
|
|
|
|
import { upload } from '@/service/base'
|
|
|
|
interface ImageUploadParams {
|
|
file: File
|
|
onProgressCallback: (progress: number) => void
|
|
onSuccessCallback: (res: { id: string }) => void
|
|
onErrorCallback: () => void
|
|
}
|
|
type ImageUpload = (v: ImageUploadParams) => void
|
|
export const imageUpload: ImageUpload = ({
|
|
file,
|
|
onProgressCallback,
|
|
onSuccessCallback,
|
|
onErrorCallback,
|
|
}) => {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
const onProgress = (e: ProgressEvent) => {
|
|
if (e.lengthComputable) {
|
|
const percent = Math.floor(e.loaded / e.total * 100)
|
|
onProgressCallback(percent)
|
|
}
|
|
}
|
|
|
|
upload({
|
|
xhr: new XMLHttpRequest(),
|
|
data: formData,
|
|
onprogress: onProgress,
|
|
})
|
|
.then((res: { id: string }) => {
|
|
onSuccessCallback(res)
|
|
})
|
|
.catch(() => {
|
|
onErrorCallback()
|
|
})
|
|
}
|