Skip to content

Commit

Permalink
fix(server): Revert a previous change causing a bug
Browse files Browse the repository at this point in the history
In a previous change, the API_ID was replaced by the ID_BOOK in the API. That caused a bug in which the individual books cannot use the correct provider
  • Loading branch information
Nytuo committed Oct 19, 2023
1 parent ee828b1 commit 851b0c9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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")
}
})
})
Expand All @@ -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")
Expand All @@ -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")
}
})
})
Expand All @@ -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")
}
})
})
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 851b0c9

Please sign in to comment.