diff --git a/server.js b/server.js index 686bf12..13dcc66 100644 --- a/server.js +++ b/server.js @@ -1160,7 +1160,8 @@ app.post("/refreshMeta", async function (req, res) { result.push(row); }); let book = result[0]; - await GETMARVELAPI_Comics_ByID(book.API_ID).then(async (res2) => { + const BOOK_API_ID = book.ID_book.split("_")[0]; + await GETMARVELAPI_Comics_ByID(BOOK_API_ID).then(async (res2) => { res2 = res2.data.results[0]; let blacklisted = ["note", "read", "reading", "unread", "favorite", "last_page", "folder", "PATH", "lock", "ID_book"] let asso = {} @@ -1472,7 +1473,7 @@ app.get("/insert/marvel/book/", apiMarvelLimiter, async function (req, res) { } if (cdata["data"]["total"] > 0) { cdata = cdata["data"]["results"][0]; - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${cdata["id"]}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${cdata["thumbnail"].path + "/detail." + cdata["thumbnail"].extension}','${cdata["issueNumber"]}','${cdata["description"] !== null ? cdata["description"].replaceAll("'", "''") : ""}','${cdata["format"]}',${cdata["pageCount"]},'${JSON.stringify(cdata["urls"])}','${JSON.stringify(cdata["series"])}','${JSON.stringify(cdata["creators"])}','${JSON.stringify(cdata["characters"])}','${JSON.stringify(cdata["prices"])}','${JSON.stringify(cdata["dates"])}','${JSON.stringify(cdata["collectedIssues"])}','${JSON.stringify(cdata["collections"])}','${JSON.stringify(cdata["variants"])}',false)`, token, "Books") + await insertIntoDB("", `('${cdata["id"] + "_1"}','1','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${cdata["thumbnail"].path + "/detail." + cdata["thumbnail"].extension}','${cdata["issueNumber"]}','${cdata["description"] !== null ? cdata["description"].replaceAll("'", "''") : ""}','${cdata["format"]}',${cdata["pageCount"]},'${JSON.stringify(cdata["urls"])}','${JSON.stringify(cdata["series"])}','${JSON.stringify(cdata["creators"])}','${JSON.stringify(cdata["characters"])}','${JSON.stringify(cdata["prices"])}','${JSON.stringify(cdata["dates"])}','${JSON.stringify(cdata["collectedIssues"])}','${JSON.stringify(cdata["collections"])}','${JSON.stringify(cdata["variants"])}',false)`, token, "Books") GETMARVELAPI_Creators(cdata["id"], "comics").then(async (ccdata) => { ccdata = ccdata["data"]["results"]; for (let i = 0; i < ccdata.length; i++) { @@ -1486,7 +1487,7 @@ app.get("/insert/marvel/book/", apiMarvelLimiter, async function (req, res) { } }); } else { - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${null}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") + await insertIntoDB("", `('${Math.floor(Math.random() * 100000) + "_1"}','${1}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") } }) }) @@ -1511,7 +1512,7 @@ app.get("/insert/ol/book/", async function (req, res) { console.log(book); let bookD = book["details"]; console.log(bookD); - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${book["bib_key"]}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${book.hasOwnProperty("thumbnail_url") ? book["thumbnail_url"].replace("-S", "-L") : null}','${null}','${bookD["description"] !== undefined ? bookD["description"].replaceAll("'", "''") : null}','${bookD["physical_format"] !== undefined ? bookD["physical_format"] : null}',${bookD["number_of_pages"] !== undefined ? bookD["number_of_pages"] : null},'${bookD["info_url"] !== undefined ? JSON.stringify(bookD["info_url"]) : null}','${null}','${bookD["authors"] !== undefined ? JSON.stringify(bookD["authors"]) : null}','${null}','${null}','${bookD["publish_date"] !== undefined ? JSON.stringify(bookD["publish_date"]) : null}','${null}','${null}','${null}',false)`, token, "Books") + await insertIntoDB("", `('${book["bib_key"] + "_3"}','${3}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${book.hasOwnProperty("thumbnail_url") ? book["thumbnail_url"].replace("-S", "-L") : null}','${null}','${bookD["description"] !== undefined ? bookD["description"].replaceAll("'", "''") : null}','${bookD["physical_format"] !== undefined ? bookD["physical_format"] : null}',${bookD["number_of_pages"] !== undefined ? bookD["number_of_pages"] : null},'${bookD["info_url"] !== undefined ? JSON.stringify(bookD["info_url"]) : null}','${null}','${bookD["authors"] !== undefined ? JSON.stringify(bookD["authors"]) : null}','${null}','${null}','${bookD["publish_date"] !== undefined ? JSON.stringify(bookD["publish_date"]) : null}','${null}','${null}','${null}',false)`, token, "Books") let bookauthors = bookD["authors"]; for (let i = 0; i < bookauthors.length; i++) { await insertIntoDB("", `('${bookauthors[i]["key"] + "_3"}','${bookauthors[i]["name"].replaceAll("'", "''")}','${null}',${null},'${null}')`, token, "Creators") @@ -1520,7 +1521,7 @@ app.get("/insert/ol/book/", async function (req, res) { }) } else { res.send(cdata) - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${null}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") + await insertIntoDB("", `('${Math.floor(Math.random() * 100000) + "_3"}','${3}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") } }) }) @@ -1536,13 +1537,13 @@ app.get("/insert/googlebooks/book/", apiGoogleLimiter, async function (req, res) } if (cdata["totalItems"] > 0) { cdata = cdata["items"][0]; - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${cdata["id"]}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${cdata["volumeInfo"]["imageLinks"] !== undefined ? (cdata["volumeInfo"]["imageLinks"]["large"] !== undefined ? (cdata["volumeInfo"]["imageLinks"]["large"]) : (cdata["volumeInfo"]["imageLinks"]["thumbnail"])) : null}','${null}','${cdata["volumeInfo"]["description"] !== undefined ? cdata["volumeInfo"]["description"].replaceAll("'", "''") : null}','${cdata["volumeInfo"]["printType"]}',${cdata["volumeInfo"]["pageCount"]},'${JSON.stringify(cdata["volumeInfo"]["infoLink"])}','${null}','${JSON.stringify(cdata["volumeInfo"]["authors"])}','${null}','${cdata["saleInfo"]["retailPrice"] !== undefined ? (JSON.stringify(cdata["saleInfo"]["retailPrice"]["amount"])) : null}','${JSON.stringify(cdata["volumeInfo"]["publishedDate"])}','${null}','${null}','${null}',false)`, token, "Books") + await insertIntoDB("", `('${cdata["id"] + "_4"}','${4}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${cdata["volumeInfo"]["imageLinks"] !== undefined ? (cdata["volumeInfo"]["imageLinks"]["large"] !== undefined ? (cdata["volumeInfo"]["imageLinks"]["large"]) : (cdata["volumeInfo"]["imageLinks"]["thumbnail"])) : null}','${null}','${cdata["volumeInfo"]["description"] !== undefined ? cdata["volumeInfo"]["description"].replaceAll("'", "''") : null}','${cdata["volumeInfo"]["printType"]}',${cdata["volumeInfo"]["pageCount"]},'${JSON.stringify(cdata["volumeInfo"]["infoLink"])}','${null}','${JSON.stringify(cdata["volumeInfo"]["authors"])}','${null}','${cdata["saleInfo"]["retailPrice"] !== undefined ? (JSON.stringify(cdata["saleInfo"]["retailPrice"]["amount"])) : null}','${JSON.stringify(cdata["volumeInfo"]["publishedDate"])}','${null}','${null}','${null}',false)`, token, "Books") let authorsccdata = cdata["volumeInfo"]["authors"]; for (let i = 0; i < authorsccdata.length; i++) { - await insertIntoDB("", `('${Math.floor(Math.random() * 100000) + "_4"}','${authorsccdata[i].replaceAll("'", "''")}','${null}',${null},'${null}')`, token, "Creators") + await insertIntoDB("", `('${cdata["id"] + "_4"}','${authorsccdata[i].replaceAll("'", "''")}','${null}',${null},'${null}')`, token, "Creators") } } else { - await insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${null}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") + await insertIntoDB("", `('${Math.floor(Math.random() * 100000) + "_4"}','${4}','${realname}',null,${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") } }) }) @@ -1577,7 +1578,7 @@ app.post("/insert/anilist/book", apiAnilistLimiter, function (req, res) { break; } } - insertIntoDB("", `(${Math.floor(Math.random() * 100000)},'${null}','${realname}',${null},${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${"Anilist_" + realname.replaceAll(" ", "$") + "_" + SerieName.replaceAll(" ", "$")}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") + insertIntoDB("", `('${Math.floor(Math.random() * 100000) + "_2"}','${2}','${realname}',${null},${0},${0},${1},${0},${0},${0},'${path}','${null}','${null}','${null}','${null}',${null},'${null}','${"Anilist_" + realname.replaceAll(" ", "$") + "_" + SerieName.replaceAll(" ", "$")}','${null}','${null}','${null}','${null}','${null}','${null}','${null}',false)`, token, "Books") }); } catch (e) { console.log(e);