Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learnathon #733

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 73 additions & 47 deletions packages/nulp_elite/src/pages/learnathon/lernCreatorForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const LernCreatorForm = () => {

const response = await fetch(url);
const data = await response.json();
console.log("userInfo---", data.result.response);
setUserInfo(data.result.response);
} catch (error) {
console.error("Error while getting user data:", error);
Expand Down Expand Up @@ -299,7 +300,6 @@ const LernCreatorForm = () => {
}

const result = await response.json();
console.log("suceesss----", result);

const uploadUrlBody = {
request: {
Expand All @@ -326,31 +326,20 @@ const LernCreatorForm = () => {
}

const uploadResult = await response.json();
console.log("upload suceesss------", uploadResult);
const formData = new FormData();
formData.append("file", e.target.files[0]);

const uploadBody = {
request: {
content: {
file: formData,
mimeType: "image/png",
},
},
};
const uploadBody = new FormData();
uploadBody.append("file", e.target.files[0]);
uploadBody.append("mimeType", "image/png");

try {
const response = await fetch(
`${urlConfig.URLS.ICON.UPLOAD}/${result.result.identifier}?enctype=multipart/form-data&processData=false&contentType=false&cache=false`,
`${urlConfig.URLS.ICON.UPLOAD}${result.result.identifier}?enctype=multipart/form-data&processData=false&contentType=false&cache=false`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(uploadBody),
body: uploadBody,
}
);

if (!response.ok) {
alert("Something went wrong while uploading Image");
throw new Error("Something went wrong");
}

Expand Down Expand Up @@ -392,7 +381,6 @@ const LernCreatorForm = () => {
}
};
const handleFileChange = async (e) => {
console.log("e.target.files[0]----", e.target.files[0]);
const mimeType = e.target.files[0].type;
const _uuid = uuidv4();
const assetBody = {
Expand Down Expand Up @@ -451,7 +439,45 @@ const LernCreatorForm = () => {
}

const uploadResult = await response.json();
// const result = {
// id: "api.content.create",
// ver: "3.0",
// ts: "2024-10-28T05:38:58ZZ",
// params: {
// resmsgid: "6bc1f805-0d14-4093-8947-0c1481da6945",
// msgid: null,
// err: null,
// status: "successful",
// errmsg: null,
// },
// responseCode: "OK",
// result: {
// identifier: "do_1141729295413821441662",
// node_id: "do_1141729295413821441662",
// versionKey: "1730093938169",
// },
// };
// const uploadResult = {
// id: "api.content.upload.url",
// ver: "3.0",
// ts: "2024-10-28T05:22:19ZZ",
// params: {
// resmsgid: "b68ea763-dbde-4901-b8c9-3f8cb581a591",
// msgid: null,
// err: null,
// status: "successful",
// errmsg: null,
// },
// responseCode: "OK",
// result: {
// identifier: "do_1141729213564026881661",
// url_expiry: "54000",
// pre_signed_url:
// "https://devnewnulp.blob.core.windows.net/contents/content/assets/do_1141729213564026881661/sample-video-file-for-testing.mp4?sv=2017-04-17&se=2024-10-28T20%3A22%3A19Z&sr=b&sp=w&sig=bNLAQABxL%2BFA33XZ9ShmCszkxwfozUxCJfoxFLWarMo%3D",
// },
// };
console.log("upload suceesss------", uploadResult);
const imgId = result.result.identifier;

const url = uploadResult.result.pre_signed_url;
const file = e.target.files[0];
Expand All @@ -471,10 +497,18 @@ const LernCreatorForm = () => {
.on("completed", async (completed) => {
console.log("1111", completed);

console.log("url", url);
console.log("mimeType", mimeType);

const fileURL = url.split("?")[0];
console.log("fileUrl", fileURL);
const data = new FormData();
data.append("fileUrl", fileURL);
data.append("mimeType", mimeType);

data.forEach((value, key) => {
console.log(`${key}:`, value);
});
// const config1 = {
// enctype: "multipart/form-data",
// processData: false,
Expand All @@ -490,9 +524,6 @@ const LernCreatorForm = () => {
`${urlConfig.URLS.ASSET.UPLOAD}/${imgId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: data,
}
);
Expand All @@ -516,37 +547,32 @@ const LernCreatorForm = () => {
}
});

try {
const subscription = uploadToBlob(url, file, csp).subscribe({
next: (completed) => {
console.log("Upload completed successfully!");
},
error: (error) => {
console.log(`Upload failed: ${error.message}`);
},
complete: () => {
console.log("Upload process completed.");
},
});

// Clean up subscription on unmount
return () => subscription.unsubscribe();
} catch (err) {
console.log(err);
}
// try {
// const subscription = uploadToBlob(url, file, csp).subscribe({
// next: (completed) => {
// console.log("Upload completed successfully!");
// },
// error: (error) => {
// console.log(`Upload failed: ${error.message}`);
// },
// complete: () => {
// console.log("Upload process completed.");
// },
// });

// // Clean up subscription on unmount
// return () => subscription.unsubscribe();
// } catch (err) {
// console.log(err);
// }
setFormData({
...formData,
content_id: uploadResult.result.identifier,
});
setErrors({ ...errors, content_id: "" });

// setData(result.result.data);
// setTotalPages(Math.ceil(result.result.totalCount / 10));
} catch (error) {
console.log("error---", error);
// setError(error.message);
} finally {
// setIsLoading(false);
}
} catch (error) {
console.log("error---", error);
Expand Down Expand Up @@ -1226,7 +1252,7 @@ const LernCreatorForm = () => {
<Grid container>
<Grid item xs={2} className="center-align">
<InputLabel htmlFor="User Name">
User Name{" "}
Participant Name{" "}
<span className="mandatory-symbol"> *</span>
</InputLabel>
</Grid>
Expand Down