Skip to content

Commit

Permalink
sharp & semaphore changes
Browse files Browse the repository at this point in the history
  • Loading branch information
UmangSharma5 committed Dec 8, 2023
1 parent f73c244 commit 5a61b32
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions server/routes/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ router.get("/:url", async (req, res) => {
});
}
const objects = [];
// console.log(user);
const stream = minioClient.listObjects(
bucketName,
"hv/" + user + "/thumbnail",
Expand All @@ -78,7 +77,6 @@ router.get("/:url", async (req, res) => {
let tname = name.split("/")[3];
await file_stats(bucketName, tname.split(".")[0]).then(
(response) => {
// console.log(response);
if (response[0]?.isUploaded)
temp.push({
name: tname.split(".")[0],
Expand Down Expand Up @@ -109,9 +107,7 @@ const handleUpload = async (
fileName,
socketIndex
) => {
// console.log(sockets,socketIndex)
let sock = sockets[socketIndex].sock;
// console.log(bucketName+minioPath+filePath)
minioClient.fPutObject(
bucketName,
minioPath + filePath,
Expand All @@ -120,6 +116,7 @@ const handleUpload = async (
if (err) {
console.error("---->", err);
} else {
// console.log("file-path ->",filePath)
console.log(count++);
obj.curr_count++;
if (sock != 0 && obj.curr_count % 10 == 0) {
Expand Down Expand Up @@ -167,7 +164,7 @@ const handleUpload = async (
fs.unlinkSync(dziPath);
}
}
// sem.leave(1)
sem.leave(1)
}
);
};
Expand All @@ -180,7 +177,6 @@ const handleAllUpload = async (
format,
tempDirPath
) => {
// console.log("user--",user);
let obj = {
total_files: 0,
curr_count: 0,
Expand All @@ -200,21 +196,23 @@ const handleAllUpload = async (

walker = walk(`temp/${fileName}_files`);
let filePath;
let cnt = 0;

walker.on("file", async (root, fileStats, next) => {
filePath = root + "/" + fileStats.name;
// sem.take(1,() => handleUpload(bucketName,minioPath,filePath,obj,tempDirPath,fileName))
// console.log(minioPath,filePath)
handleUpload(
bucketName,
minioPath,
filePath,
obj,
tempDirPath,
fileName,
sock
);
cnt++;
const filePath = root + "/" + fileStats.name;
try {
await new Promise((resolve) => {
sem.take(1, () => resolve(handleUpload(bucketName, minioPath, filePath, obj, tempDirPath, fileName, sock)));
});
} catch (error) {
// Handle any errors that occurred during handleUpload
console.error("Error during handleUpload:", error);
}

next();
});


walker.on("end", () => {
console.log("End Upload");
Expand Down Expand Up @@ -285,6 +283,11 @@ router.post("/:url", async function (req, res) {
filePath,
`./temp/${tempName}`,
"--vips-progress",
// "--tile-size",
// "350"
// "--depth",
// "onetile",
// "--overlap=1",
]; // Add any arguments your command requires

const childProcess = spawn(command, args);
Expand Down

0 comments on commit 5a61b32

Please sign in to comment.