diff --git a/app.js b/app.js index a47652a..dd3d0f4 100644 --- a/app.js +++ b/app.js @@ -36,7 +36,7 @@ app .use(express.json()) .use(express.urlencoded({ extended: false })) .use(cookieParser()) - .use(express.static(path.join(__dirname, "public"))); +.use(express.static('public')); app.use("/", indexRouter); app.use("/users", usersRouter); @@ -84,7 +84,7 @@ const sheet = GoogleFunctions.SpreadSheets(auth); // GoogleFunctions.getPriceSlotValues(sheet, "tha"); // v3 !!!! -GoogleFunctions.syncProfilePrice(sheet, "tha", false); +// GoogleFunctions.syncProfilePrice(sheet, "tha", false); // // Test Taobin SyncText diff --git a/plugins/heartbeat.js b/plugins/heartbeat.js index 5b1f3fe..f9e4c65 100644 --- a/plugins/heartbeat.js +++ b/plugins/heartbeat.js @@ -28,4 +28,7 @@ endpointMap = { res.render("heartbeat"); }, + 'info': function(req, res, next){ + res.json(heartbeatApiInfo); + } }; \ No newline at end of file diff --git a/plugins/syncProfilePriceSlotSheet.js b/plugins/syncProfilePriceSlotSheet.js index 9053941..9882e19 100644 --- a/plugins/syncProfilePriceSlotSheet.js +++ b/plugins/syncProfilePriceSlotSheet.js @@ -26,12 +26,19 @@ endpointMap = { res.render("apiInfo"); }, - "run/now": function (req, res, next) { - GoogleFunctions.syncProfilePrice(sheet, "tha", false); - res.send("Force run `Sync Thai Price Slots`"); + "info": function(req, res, next) { + res.json(syncThaiProfilePriceSlotApiInfo); }, - "run/test": function (req, res, next) { - GoogleFunctions.syncProfilePrice(sheet, "tha", true); - res.send("Force run `Sync Thai Price Slots` test mode"); + "run/now": async function (req, res, next) { + // res.json({ status: "running" }); + await GoogleFunctions.syncProfilePrice(sheet, "tha", false); + res.json({ status: "success", message: "Force run `Sync Thai Price Slots`" }); + // res.send("Force run `Sync Thai Price Slots`"); + }, + "run/test": async function (req, res, next) { + // res.json({ status: "running" }); + await GoogleFunctions.syncProfilePrice(sheet, "tha", true); + res.json({ status: "success", message: "Force run `Sync Thai Price Slots` test mode" }); + // res.send("Force run `Sync Thai Price Slots` test mode"); }, }; diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..3b85fa1 --- /dev/null +++ b/public/index.html @@ -0,0 +1,58 @@ + + + + + + + + +
+
+

Heartbeat

+ +

Sync Price Slot (THA)

+ + + + + +
+
+ +

Output

+ +
+
+ + diff --git a/public/scripts/test.js b/public/scripts/test.js new file mode 100644 index 0000000..8552bf8 --- /dev/null +++ b/public/scripts/test.js @@ -0,0 +1,24 @@ +console.log("Hello, World!"); + +function sendToOutput(message){ + document.getElementById("output").value += message + "\n"; +} + +function getHeartBeatInfo(){ + fetch("http://localhost:36530/heartbeat/info").then(response => response.json()).then(data => sendToOutput(JSON.stringify(data))); +} + +// Sync Price Slot Command Shortcuts +// +// +function getSyncPriceInfo(){ + fetch("http://localhost:36530/syncProfilePriceSlotSheet/info").then(response => response.json()).then(data => sendToOutput(JSON.stringify(data))); +} + +function setSyncPriceRunTest(){ + fetch("http://localhost:36530/syncProfilePriceSlotSheet/run/test").then(response => response.json()).then(data => sendToOutput(JSON.stringify(data))); +} + +function setSyncPriceRunNow(){ + fetch("http://localhost:36530/syncProfilePriceSlotSheet/run/now").then(response => response.json()).then(data => sendToOutput(JSON.stringify(data))); +} \ No newline at end of file