Finalize 1.7.0. All uploads working.

This commit is contained in:
Patrick Fic
2025-06-02 14:18:13 -07:00
parent d23f0e4c6f
commit 491f0e1a3b
5 changed files with 116 additions and 15 deletions

View File

@@ -18,13 +18,13 @@ export const handleUpload = async (ev, context) => {
const { mediaId, onError, onSuccess, onProgress } = ev;
const { bodyshop, jobId } = context;
try {
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
const imageUri = imageData.localUri || imageData.uri
const newFile = await (
await fetch(imageData.localUri || imageData.uri)
await fetch(imageUri)
).blob();
let extension = imageData.localUri.split(".").pop();
let extension = imageData.filename.split(".").pop();
//Default to Cloudinary in case of split treatment errors.
let destination =
@@ -33,10 +33,10 @@ export const handleUpload = async (ev, context) => {
let key =
destination === "imgproxy"
? `${bodyshop.id}/${jobId}/${replaceAccents(
imageData.filename || imageData.uri.split("/").pop()
imageData.filename || imageUri.split("/").pop()
).replace(/[^A-Z0-9]+/gi, "_")}-${new Date().getTime()}.${extension}`
: `${bodyshop.id}/${jobId}/${(
imageData.filename || imageData.uri.split("/").pop()
imageData.filename || imageUri.split("/").pop()
).replace(/\.[^/.]+$/, "")}-${new Date().getTime()}`;
const res =
@@ -82,14 +82,14 @@ export const handleUpload = async (ev, context) => {
export const handleUploadImgproxy = async (ev, context) => {
const { mediaId, onError, onSuccess, onProgress } = ev;
const { bodyshop, jobId } = context;
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
const imageUri = imageData.localUri || imageData.uri
const newFile = await (
await fetch(imageData.localUri || imageData.uri)
await fetch(imageUri)
).blob();
let extension = imageData.localUri.split(".").pop();
let extension = imageUri.split(".").pop();
let key = `${bodyshop.id}/${jobId}/${(
imageData.filename || imageData.uri.split("/").pop()
imageData.filename || imageUri.split("/").pop()
).replace(/\.[^/.]+$/, "")}-${new Date().getTime()}`;
const res = await uploadToImgproxy(
@@ -158,6 +158,7 @@ export const uploadToImgproxy = async (
xhr.setRequestHeader("Content-Type", fileType);
xhr.upload.onprogress = (event) => {
console.log("*** ~ awaitnewPromise ~ event:", event);
if (onProgress && event.lengthComputable) {
onProgress({ percent: event.loaded / event.total, loaded: event.loaded });
}
@@ -171,7 +172,7 @@ export const uploadToImgproxy = async (
}
};
xhr.onerror = () => {
xhr.onerror = (req, event) => {
reject(new Error("Network error"));
};