IO-3092 Implement delete, move and download on image proxy. Add imgproxy based components.
This commit is contained in:
@@ -38,13 +38,10 @@ export const uploadToS3 = async (
|
||||
context,
|
||||
notification
|
||||
) => {
|
||||
const { bodyshop, jobId, billId, uploaded_by, callback, tagsArray } = context;
|
||||
const { bodyshop, jobId, billId, uploaded_by, callback } = context;
|
||||
|
||||
//Set variables for getting the signed URL.
|
||||
let timestamp = Math.floor(Date.now() / 1000);
|
||||
//Get the signed url.
|
||||
|
||||
const signedURLResponse = await axios.post("/media/proxy/sign", {
|
||||
//Get the signed url allowing us to PUT to S3.
|
||||
const signedURLResponse = await axios.post("/media/imgproxy/sign", {
|
||||
filenames: [key],
|
||||
bodyshopid: bodyshop.id,
|
||||
jobid: jobId
|
||||
@@ -60,19 +57,16 @@ export const uploadToS3 = async (
|
||||
return;
|
||||
}
|
||||
|
||||
//Key should be same as we provided to maintain backwards compatibility.
|
||||
const { presignedUrl: preSignedUploadUrlToS3, key: s3Key } = signedURLResponse.data.signedUrls[0];
|
||||
|
||||
//Build request to end to cloudinary.
|
||||
var options = {
|
||||
// headers: { "X-Requested-With": "XMLHttpRequest" },
|
||||
onUploadProgress: (e) => {
|
||||
if (onProgress) onProgress({ percent: (e.loaded / e.total) * 100 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const cloudinaryUploadResponse = await cleanAxios.put(preSignedUploadUrlToS3, file, options);
|
||||
|
||||
const s3UploadResponse = await cleanAxios.put(preSignedUploadUrlToS3, file, options);
|
||||
//Insert the document with the matching key.
|
||||
let takenat;
|
||||
if (fileType.includes("image")) {
|
||||
@@ -94,18 +88,18 @@ export const uploadToS3 = async (
|
||||
uploaded_by: uploaded_by,
|
||||
key: s3Key,
|
||||
type: fileType,
|
||||
extension: cloudinaryUploadResponse.data.format || extension,
|
||||
extension: s3UploadResponse.data.format || extension,
|
||||
bodyshopid: bodyshop.id,
|
||||
size: cloudinaryUploadResponse.data.bytes || file.size,
|
||||
size: s3UploadResponse.data.bytes || file.size, //Leftover from Cloudinary. We don't do any optimization on upload, so it will always be file.size.
|
||||
takenat
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
if (!documentInsert.errors) {
|
||||
if (onSuccess)
|
||||
onSuccess({
|
||||
//TODO: Since this may go server side, we can just manage the state locally.
|
||||
uid: documentInsert.data.insert_documents.returning[0].id,
|
||||
name: documentInsert.data.insert_documents.returning[0].name,
|
||||
status: "done",
|
||||
@@ -130,17 +124,6 @@ export const uploadToS3 = async (
|
||||
}
|
||||
};
|
||||
|
||||
//Also needs to be updated in media JS and mobile app.
|
||||
export function DetermineFileType(filetype) {
|
||||
if (!filetype) return "auto";
|
||||
else if (filetype.startsWith("image")) return "image";
|
||||
else if (filetype.startsWith("video")) return "video";
|
||||
else if (filetype.startsWith("application/pdf")) return "image";
|
||||
else if (filetype.startsWith("application")) return "raw";
|
||||
|
||||
return "auto";
|
||||
}
|
||||
|
||||
function replaceAccents(str) {
|
||||
// Verifies if the String has accents and replace them
|
||||
if (str.search(/[\xC0-\xFF]/g) > -1) {
|
||||
@@ -167,6 +150,5 @@ function replaceAccents(str) {
|
||||
.replace(/[\xFE]/g, "p")
|
||||
.replace(/[\xFD\xFF]/g, "y");
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user