Skip to content

feat: support backend image upload provider#198

Merged
Yukaii merged 3 commits intomasterfrom
feature/fs-image-upload-api
Dec 5, 2025
Merged

feat: support backend image upload provider#198
Yukaii merged 3 commits intomasterfrom
feature/fs-image-upload-api

Conversation

@Yukaii
Copy link
Contributor

@Yukaii Yukaii commented Dec 5, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 5, 2025 16:19
@netlify
Copy link

netlify bot commented Dec 5, 2025

Deploy Preview for disfactory-frontend ready!

Name Link
🔨 Latest commit 40de106
🔍 Latest deploy log https://app.netlify.com/projects/disfactory-frontend/deploys/69330e81ac85ca00081e726a
😎 Deploy Preview https://deploy-preview-198--disfactory-frontend.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for backend-based image uploads as an alternative to the existing Imgur upload provider. The change allows the application to be configured to upload images to a backend server instead of relying solely on Imgur.

Key Changes:

  • Added configurable image upload provider with support for 'imgur' (default) and 'backend' options
  • Implemented uploadToBackend function that uploads images to a configurable backend URL
  • Refactored image upload logic to use a unified uploadImage function that routes to the appropriate provider
  • Added environment variables for configuration: VUE_APP_IMAGE_UPLOAD_PROVIDER and VUE_APP_IMAGE_UPLOAD_URL

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/api/index.ts Adds image upload provider abstraction with backend upload support, including new types, configuration constants, upload functions, and integration with existing image upload workflows
.env.example Documents new environment variables for configuring the image upload provider and backend upload URL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Image upload provider configuration
type ImageUploadProvider = 'imgur' | 'backend'
const IMAGE_UPLOAD_PROVIDER: ImageUploadProvider = (process.env.VUE_APP_IMAGE_UPLOAD_PROVIDER as ImageUploadProvider) || 'imgur'
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variable VUE_APP_IMAGE_UPLOAD_PROVIDER is cast to ImageUploadProvider type without validation. If an invalid value (e.g., 'typo' or 'cloudinary') is provided, it will be assigned to IMAGE_UPLOAD_PROVIDER and only fall back to 'imgur' if the value is falsy. This could lead to unexpected behavior in the uploadImage function.

Consider adding validation:

const rawProvider = process.env.VUE_APP_IMAGE_UPLOAD_PROVIDER
const IMAGE_UPLOAD_PROVIDER: ImageUploadProvider = 
  (rawProvider === 'imgur' || rawProvider === 'backend') ? rawProvider : 'imgur'

This ensures only valid provider values are used.

Suggested change
const IMAGE_UPLOAD_PROVIDER: ImageUploadProvider = (process.env.VUE_APP_IMAGE_UPLOAD_PROVIDER as ImageUploadProvider) || 'imgur'
const rawProvider = process.env.VUE_APP_IMAGE_UPLOAD_PROVIDER
const IMAGE_UPLOAD_PROVIDER: ImageUploadProvider = (rawProvider === 'imgur' || rawProvider === 'backend') ? rawProvider : 'imgur'

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +119
async function uploadToBackend (file: File): Promise<ImageUploadResult> {
const formData = new FormData()
formData.append('image', file)

// Use the configured backend upload URL, or construct from current base URL
const uploadUrl = IMAGE_UPLOAD_URL || `${currentBaseURL.value}/upload`

const { data } = await axios({
method: 'POST',
url: uploadUrl,
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
})

// Backend returns Imgur-compatible response format
if (!data.success) {
throw new Error(data.data?.error || 'Image upload failed')
}

return {
link: data.data.link as string,
deletehash: data.data.deletehash as string,
file
}
}

// Upload image using configured provider
async function uploadImage (file: File): Promise<ImageUploadResult> {
if (IMAGE_UPLOAD_PROVIDER === 'backend') {
return uploadToBackend(file)
}
return uploadToImgur(file)
}
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new upload functionality (uploadToBackend, uploadImage) lacks test coverage. Since the repository uses Jest for testing (as evidenced by src/components/__tests__/TutorialModal.spec.ts), consider adding tests to verify:

  1. The uploadImage function correctly routes to the appropriate provider based on IMAGE_UPLOAD_PROVIDER
  2. The uploadToBackend function handles successful and failed uploads properly
  3. The fallback behavior when IMAGE_UPLOAD_URL is not provided

This would ensure the new feature works as expected and prevent regressions.

Copilot uses AI. Check for mistakes.
@Yukaii Yukaii merged commit 6a441fc into master Dec 5, 2025
9 checks passed
@Yukaii Yukaii deleted the feature/fs-image-upload-api branch December 5, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants