update sendDeviceInfo follow model special and RAM, flash
This commit is contained in:
		
							parent
							
								
									ae8c0dea08
								
							
						
					
					
						commit
						2a33901778
					
				| 
						 | 
					@ -14,10 +14,11 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
    const regexVersion = /sh.*? ver.*/;
 | 
					    const regexVersion = /sh.*? ver.*/;
 | 
				
			||||||
    const regexMemory = /(\d+)K/g;
 | 
					    const regexMemory = /(\d+)K/g;
 | 
				
			||||||
    const date = moment(Date.now()).format("YYYYMMDD");
 | 
					    const date = moment(Date.now()).format("YYYYMMDD");
 | 
				
			||||||
    const memDefault = (await KeyValue.all())
 | 
					    const allKeyValue = await KeyValue.all();
 | 
				
			||||||
 | 
					    const memDefault = allKeyValue
 | 
				
			||||||
      .filter((i) => i.$attributes.key === "MEMORY_DEFAULT")
 | 
					      .filter((i) => i.$attributes.key === "MEMORY_DEFAULT")
 | 
				
			||||||
      .map((obj) => obj.$attributes.value);
 | 
					      .map((obj) => obj.$attributes.value);
 | 
				
			||||||
    const listInformation = [];
 | 
					    let listInformation = [];
 | 
				
			||||||
    let dataFile = await LogDetectFile.all();
 | 
					    let dataFile = await LogDetectFile.all();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let html = "";
 | 
					    let html = "";
 | 
				
			||||||
| 
						 | 
					@ -38,7 +39,8 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Read file in listFile
 | 
					    //Read file in listFile
 | 
				
			||||||
    await listFile.map(async (file) => {
 | 
					    const filePromises = listFile.map((file, index) => {
 | 
				
			||||||
 | 
					      return new Promise((resolve, reject) => {
 | 
				
			||||||
        fs.readFile(
 | 
					        fs.readFile(
 | 
				
			||||||
          Env.get("FOLDER_LOGS") + "/" + file,
 | 
					          Env.get("FOLDER_LOGS") + "/" + file,
 | 
				
			||||||
          "utf8",
 | 
					          "utf8",
 | 
				
			||||||
| 
						 | 
					@ -162,7 +164,6 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                      ?.replace(/,/g, "")
 | 
					                      ?.replace(/,/g, "")
 | 
				
			||||||
                      .trim();
 | 
					                      .trim();
 | 
				
			||||||
                    const SN = u?.split("SN:")[1]?.replace(/,/g, "").trim();
 | 
					                    const SN = u?.split("SN:")[1]?.replace(/,/g, "").trim();
 | 
				
			||||||
                  //   let memory =
 | 
					 | 
				
			||||||
                    if (index > 0) {
 | 
					                    if (index > 0) {
 | 
				
			||||||
                      if (PID !== "" && SN !== "") {
 | 
					                      if (PID !== "" && SN !== "") {
 | 
				
			||||||
                        listInformation.push({
 | 
					                        listInformation.push({
 | 
				
			||||||
| 
						 | 
					@ -173,13 +174,6 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                          flash: "",
 | 
					                          flash: "",
 | 
				
			||||||
                          extra_item: "yes",
 | 
					                          extra_item: "yes",
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      html += `<tr><td>${PID}</td>
 | 
					 | 
				
			||||||
                  <td>${VID}</td>
 | 
					 | 
				
			||||||
                  <td>${SN}</td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td>yes</td></tr>`;
 | 
					 | 
				
			||||||
                      }
 | 
					                      }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                      if (PID !== "" && SN !== "") {
 | 
					                      if (PID !== "" && SN !== "") {
 | 
				
			||||||
| 
						 | 
					@ -206,7 +200,9 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                                    .filter(
 | 
					                                    .filter(
 | 
				
			||||||
                                      (line) =>
 | 
					                                      (line) =>
 | 
				
			||||||
                                        line.includes("bytes of memory") ||
 | 
					                                        line.includes("bytes of memory") ||
 | 
				
			||||||
                                      line.includes("bytes of physical memory")
 | 
					                                        line.includes(
 | 
				
			||||||
 | 
					                                          "bytes of physical memory"
 | 
				
			||||||
 | 
					                                        )
 | 
				
			||||||
                                    )
 | 
					                                    )
 | 
				
			||||||
                                    .join("<br>")
 | 
					                                    .join("<br>")
 | 
				
			||||||
                                    .match(regexMemory)[0]
 | 
					                                    .match(regexMemory)[0]
 | 
				
			||||||
| 
						 | 
					@ -242,24 +238,6 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                              : "",
 | 
					                              : "",
 | 
				
			||||||
                          extra_item: "no",
 | 
					                          extra_item: "no",
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      html += `<tr style='background-color:${backgroundColor}'><td>${PID}</td>
 | 
					 | 
				
			||||||
                  <td>${VID}</td>
 | 
					 | 
				
			||||||
                  <td>${SN}</td>
 | 
					 | 
				
			||||||
                  <td>${RAM}</td>
 | 
					 | 
				
			||||||
                  <td>${
 | 
					 | 
				
			||||||
                    flash.match(regexMemory) !== null
 | 
					 | 
				
			||||||
                      ? (
 | 
					 | 
				
			||||||
                          parseInt(flash.match(regexMemory)[0]) /
 | 
					 | 
				
			||||||
                          1024 /
 | 
					 | 
				
			||||||
                          1024
 | 
					 | 
				
			||||||
                        ).toFixed(2) +
 | 
					 | 
				
			||||||
                        "G (D: " +
 | 
					 | 
				
			||||||
                        memDefaultForPID.split(":")[2] +
 | 
					 | 
				
			||||||
                        ")"
 | 
					 | 
				
			||||||
                      : ""
 | 
					 | 
				
			||||||
                  }</td>
 | 
					 | 
				
			||||||
                  <td>no</td></tr>`;
 | 
					 | 
				
			||||||
                      }
 | 
					                      }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                  });
 | 
					                  });
 | 
				
			||||||
| 
						 | 
					@ -288,13 +266,6 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                          flash: "",
 | 
					                          flash: "",
 | 
				
			||||||
                          extra_item: "yes",
 | 
					                          extra_item: "yes",
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      html += `<tr><td>${PID}</td>
 | 
					 | 
				
			||||||
                  <td>${VID}</td>
 | 
					 | 
				
			||||||
                  <td>${SN}</td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td>yes</td></tr>`;
 | 
					 | 
				
			||||||
                      }
 | 
					                      }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                      if (PID !== "" && SN !== "") {
 | 
					                      if (PID !== "" && SN !== "") {
 | 
				
			||||||
| 
						 | 
					@ -306,29 +277,42 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
                          flash: "",
 | 
					                          flash: "",
 | 
				
			||||||
                          extra_item: "no",
 | 
					                          extra_item: "no",
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      html += `<tr style='background-color:${backgroundColor}'><td>${PID}</td>
 | 
					 | 
				
			||||||
                  <td>${VID}</td>
 | 
					 | 
				
			||||||
                  <td>${SN}</td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td></td>
 | 
					 | 
				
			||||||
                  <td>no</td></tr>`;
 | 
					 | 
				
			||||||
                      }
 | 
					                      }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                  });
 | 
					                  });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            resolve(0);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setTimeout(async () => {
 | 
					    await Promise.all(filePromises);
 | 
				
			||||||
    if (listInformation.length > 0) {
 | 
					    if (listInformation.length > 0) {
 | 
				
			||||||
      console.log(listInformation);
 | 
					      console.log(listInformation);
 | 
				
			||||||
 | 
					      let specialModel = allKeyValue
 | 
				
			||||||
 | 
					        .filter((i) => i.key === "MODEL_SPECIAL")
 | 
				
			||||||
 | 
					        .map((obj) => obj.$attributes.value);
 | 
				
			||||||
 | 
					      listInformation = listInformation.filter(
 | 
				
			||||||
 | 
					        (i) =>
 | 
				
			||||||
 | 
					          i.RAM !== "" ||
 | 
				
			||||||
 | 
					          i.flash !== "" ||
 | 
				
			||||||
 | 
					          specialModel.filter((m) => i.PID.includes(m)).length > 0
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      listInformation.map((inf) => {
 | 
				
			||||||
 | 
					        html += `<tr><td>${inf.PID}</td>
 | 
				
			||||||
 | 
					                        <td>${inf.VID}</td>
 | 
				
			||||||
 | 
					                        <td>${inf.SN}</td>
 | 
				
			||||||
 | 
					                        <td>${inf.RAM}</td>
 | 
				
			||||||
 | 
					                        <td>${inf.flash}</td>
 | 
				
			||||||
 | 
					                        <td>${inf.extra_item}</td></tr>`;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
      const options = {
 | 
					      const options = {
 | 
				
			||||||
        from: "admin@apactech.io",
 | 
					        from: "admin@apactech.io",
 | 
				
			||||||
        to: "joseph@apactech.io, ips@ipsupply.com.au",
 | 
					        to: "joseph@apactech.io, ips@ipsupply.com.au",
 | 
				
			||||||
 | 
					        // to: "joseph@apactech.io",
 | 
				
			||||||
        subject: "(AUTO-REPORT) SERIAL NUMBER",
 | 
					        subject: "(AUTO-REPORT) SERIAL NUMBER",
 | 
				
			||||||
        html:
 | 
					        html:
 | 
				
			||||||
          "<table border='1'>\
 | 
					          "<table border='1'>\
 | 
				
			||||||
| 
						 | 
					@ -348,10 +332,8 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
        </table>",
 | 
					        </table>",
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      transporter.sendMail(options);
 | 
					      transporter.sendMail(options);
 | 
				
			||||||
 | 
					 | 
				
			||||||
      await InfoDevice.createMany(listInformation);
 | 
					      await InfoDevice.createMany(listInformation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }, 5000);
 | 
					 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    console.log(error);
 | 
					    console.log(error);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue