Skip to content

Beautiful Open-Source Form Builder

Refactor Unsplash download handling to use download location URL

JhumanJ9bf522866faa
diff --git a/api/app/Http/Controllers/Content/UnsplashController.php b/api/app/Http/Controllers/Content/UnsplashController.php
index 02c438675..e4170ed7f 100644
--- a/api/app/Http/Controllers/Content/UnsplashController.php
+++ b/api/app/Http/Controllers/Content/UnsplashController.php
@@ -51,7 +51,7 @@ class UnsplashController extends Controller
public function download(Request $request)
{
$request->validate([
- 'photo_id' => 'required|string|min:1|max:255',
+ 'download_location' => 'required|url|regex:#^https://api\.unsplash\.com/photos/#',
]);
$accessKey = config('services.unsplash.access_key');
@@ -60,12 +60,9 @@ class UnsplashController extends Controller
return response()->json(['error' => 'Invalid request'], 400);
}
- $photoId = $request->input('photo_id');
+ $downloadLocation = $request->input('download_location');
- // Construct the URL on the backend - only one place to maintain it
- $downloadLocation = "https://api.unsplash.com/photos/{$photoId}/download";
-
- // Trigger download tracking with proper headers
+ // Trigger download tracking with proper headers and authorization
$response = Http::withHeaders([
'Accept-Version' => 'v1',
'User-Agent' => 'OpnForm (https://opnform.com)',
@@ -74,7 +71,7 @@ class UnsplashController extends Controller
]);
if (!$response->successful()) {
- return response()->json(['error' => 'Failed to track download'], 500);
+ return response()->json(['error' => 'Failed to track download', 'response' => $response->json()], 400);
}
return response()->json(['success' => true]);
diff --git a/client/api/content.js b/client/api/content.js
index afca43efe..640bd0e12 100644
--- a/client/api/content.js
+++ b/client/api/content.js
@@ -14,6 +14,6 @@ export const contentApi = {
// Unsplash
unsplash: {
list: (options) => apiService.get('/unsplash', options),
- download: (photoId) => apiService.post('/unsplash/download', { photo_id: photoId })
+ download: (downloadLocation) => apiService.post('/unsplash/download', { download_location: downloadLocation })
}
}
\ No newline at end of file
diff --git a/client/components/forms/heavy/components/UnsplashImages.vue b/client/components/forms/heavy/components/UnsplashImages.vue
index 624f4d91f..01af2b6cd 100644
--- a/client/components/forms/heavy/components/UnsplashImages.vue
+++ b/client/components/forms/heavy/components/UnsplashImages.vue
@@ -95,10 +95,10 @@ const { data: images = [], isLoading: loading } = unsplash.list(debouncedTerm, {
const selectImage = async (image) => {
// Trigger download tracking as per Unsplash API guidelines
- if (image.id) {
+ if (image.download_location) {
try {
- // Fire-and-forget - pass only the photo ID, backend constructs the URL
- contentApi.unsplash.download(image.id)
+ // Fire-and-forget - pass the full download_location URL with ixid parameter
+ contentApi.unsplash.download(image.download_location)
} catch (error) {
// Silently fail - don't block image selection if download tracking fails
console.warn('Failed to track Unsplash download:', error)