Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Feb 7, 2024
1 parent 35d10f2 commit dbbb091
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,10 @@ exports.list = (filterFields) => {
});
};

exports.updateFileDescription = async (originalFilename, description) => {
if (!originalFilename) {
throw new Error("originalFilename cannot be undefined");
}
let condition = {};
condition.original_filename = originalFilename;
return await file_info
.findAll({
where: condition,
order: [["updated_at", "DESC"]],
})
.then(async (data) => {
if (data.length > 0) {
let updated_file = {
id: data.id,
description: description,
};
return await file_info
.update(updated_file, {
where: condition,
})
.then((num) => {
return num;
});
}
console.warn(
`Warning: Cannot update description as file [ ${original_filename} ] does not exist!`
);
return data;
})
.catch((err) => {
console.log(err);
throw new Error(
err.message ||
"Error while updating description of uploaded files in MYSQL DB."
);
});
};

/**
* Create or update file info record in table
* @param {*} file_info
* e.g: {"size":0,"filepath":"/tmp/88734e92ec45dd40452a9a500.py","newFilename":"bsmscript.py","mimetype":"text/x-python","mtime":null,"originalFilename":"bsmscript.py"}
* e.g: {"size":0,"filepath":"/tmp/88734e92ec45dd40452a9a500.py","newFilename":"<filename>","mimetype":"text/x-python","mtime":null,"originalFilename":"<filename>"}
* Return update success or not. True success, otherwise false.
*/
exports.upsertFileInfo = async (fileInfo) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
const formidable = require("formidable");
const { uploadToS3 } = require("./s3_uploader");
const {
updateFileDescription,
} = require("../controllers/file_info.controller");
const uploadDest = process.env.UPLOAD_DESTINATION;
const uploadDestPath = process.env.UPLOAD_DESTINATION_PATH;
const uploadMaxFileSize = parseInt(process.env.UPLOAD_MAX_FILE_SIZE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require("dotenv").config();
const fileProcessingSubject = process.env.FILE_PROCESSING_SUBJECT;

exports.pubFileProcessingReq = async (nc, payload) => {
if (nc) {
nc.publish(fileProcessingSubject, String(payload));
exports.pubFileProcessingReq = async (natsConn, payload) => {
if (natsConn) {
natsConn.publish(fileProcessingSubject, String(payload));
console.log(
`Send file processing request: ${payload} to subject: ${fileProcessingSubject}`
);
Expand Down
1 change: 1 addition & 0 deletions telematic_system/telematic_apps/web_app/server/server.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ UPLOAD_MAX_FILE_SIZE=21474836480 #20 GB

# NATS config
NATS_SERVERS = localhost:4222
### This topic is used by processing service. Make sure this is consistent with processing service topic setup
FILE_PROCESSING_SUBJECT=ui.file.procressing
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ UPLOAD_MAX_FILE_SIZE=21474836480 #20 GB

# NATS config
NATS_SERVERS = localhost:4222
### This topic is used by processing service. Make sure this is consistent with processing service topic setup
FILE_PROCESSING_SUBJECT=ui.file.procressing
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ describe("Test NATS publisher", () => {
expect(err).not.toBeNull();
}
});

it("Test NATS publish to topic ui.file.procressing", async () => {
try {
const natsConn = undefined;
let processingReq = {
filepath: "/opt/telematic/test.txt",
upload_destination: "HOST",
};
await pubFileProcessingReq(natsConn, JSON.stringify(processingReq));
} catch (err) {
expect(err).not.toBeNull();
}
});
});

0 comments on commit dbbb091

Please sign in to comment.