@zodic/shared 0.0.345 → 0.0.346
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api/index.ts +38 -14
- package/package.json +1 -1
package/app/api/index.ts
CHANGED
|
@@ -803,17 +803,37 @@ export const Api = (env: BackendBindings) => ({
|
|
|
803
803
|
}
|
|
804
804
|
};
|
|
805
805
|
|
|
806
|
-
// Helper function to
|
|
807
|
-
const
|
|
808
|
-
//
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
806
|
+
// Helper function to resize an image by calling the Express server
|
|
807
|
+
const resizeImage = async (url: string, label: string): Promise<ArrayBuffer> => {
|
|
808
|
+
const resizeEndpoint = `https://zodiako-image-mounter.onrender.com/resize-image?url=${encodeURIComponent(url)}`; // Replace with your Express server URL
|
|
809
|
+
try {
|
|
810
|
+
const response = await fetch(resizeEndpoint);
|
|
811
|
+
if (!response.ok) {
|
|
812
|
+
throw new Error(`${label} resize failed: ${response.status} ${response.statusText}`);
|
|
813
|
+
}
|
|
814
|
+
const contentType = response.headers.get('Content-Type');
|
|
815
|
+
if (!contentType || !contentType.startsWith('image/')) {
|
|
816
|
+
throw new Error(`${label} resize response is not an image: Content-Type is ${contentType}`);
|
|
817
|
+
}
|
|
818
|
+
return await response.arrayBuffer();
|
|
819
|
+
} catch (err: any) {
|
|
820
|
+
console.error(`Error resizing ${label}:`, err.message);
|
|
821
|
+
throw new Error(`Failed to resize ${label}: ${err.message}`);
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
// Helper function to upload an image to storage and get a public URL
|
|
826
|
+
const uploadImageToStorage = async (imageData: ArrayBuffer, label: string): Promise<string> => {
|
|
827
|
+
const fileName = `${label.toLowerCase().replace(/\s+/g, '-')}-${Date.now()}.jpg`;
|
|
828
|
+
// Replace this with your actual storage service implementation (e.g., Cloudflare R2, AWS S3)
|
|
829
|
+
// Example for Cloudflare R2:
|
|
830
|
+
// const r2Response = await env.R2_BUCKET.put(fileName, imageData, {
|
|
831
|
+
// httpMetadata: { contentType: 'image/jpeg' },
|
|
832
|
+
// });
|
|
833
|
+
// return `https://your-r2-bucket-url/${fileName}`;
|
|
834
|
+
|
|
835
|
+
// For now, we'll throw an error if this isn't implemented
|
|
836
|
+
throw new Error(`Storage service not implemented for ${label}`);
|
|
817
837
|
};
|
|
818
838
|
|
|
819
839
|
try {
|
|
@@ -821,9 +841,13 @@ export const Api = (env: BackendBindings) => ({
|
|
|
821
841
|
await validateImageUrl(sourceImageUrl, 'Source image URL');
|
|
822
842
|
await validateImageUrl(targetImageUrl, 'Target image URL');
|
|
823
843
|
|
|
824
|
-
//
|
|
825
|
-
const
|
|
826
|
-
const
|
|
844
|
+
// Resize images by calling the Express server
|
|
845
|
+
const resizedSourceData = await resizeImage(sourceImageUrl, 'Source image');
|
|
846
|
+
const resizedTargetData = await resizeImage(targetImageUrl, 'Target image');
|
|
847
|
+
|
|
848
|
+
// Upload resized images to storage to get public URLs
|
|
849
|
+
const resizedSourceUrl = await uploadImageToStorage(resizedSourceData, 'Source image');
|
|
850
|
+
const resizedTargetUrl = await uploadImageToStorage(resizedTargetData, 'Target image');
|
|
827
851
|
|
|
828
852
|
const body = JSON.stringify({
|
|
829
853
|
model: 'Qubico/image-toolkit',
|