2025-01-27 11:40:17 +00:00
|
|
|
import { readFileSync, readdirSync } from "fs"
|
|
|
|
|
|
|
|
const base_api_url = "http://localhost:3000"
|
|
|
|
|
2025-02-11 21:21:16 +00:00
|
|
|
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6Imp3dCJ9.eyJ1c2VybmFtZSI6Inp1bWEiLCJhZG1pbiI6dHJ1ZSwiaWQiOiJjMmZlNDhhNi1iNmVmLTRhMDktOTZmNi0wM2YyNTNkZjExZGQiLCJtYXhBZ2UiOjYwNDgwMH0=.0eee4c6c4c2a13b4add8ca7b34e1f1cdec5e16b56d6cae77ede9974fccd8f2d6"
|
2025-01-27 11:40:17 +00:00
|
|
|
|
2025-02-11 21:21:16 +00:00
|
|
|
let bsets_sanitized_names = readdirSync(import.meta.dirname + "/data/decks_bsets/")
|
2025-01-27 11:40:17 +00:00
|
|
|
|
|
|
|
function get_line_data(line) {
|
|
|
|
let data = line.split(" ")
|
|
|
|
let amount = parseInt(data[0])
|
|
|
|
let name = data.slice(1).join(" ").split("/")[0].replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase()
|
|
|
|
return {"sanitized_name":name, "amount":amount}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(const sanitized_name of bsets_sanitized_names) {
|
2025-02-11 21:21:16 +00:00
|
|
|
let path = import.meta.dirname + "/data/decks_bsets/" + sanitized_name + "/"
|
2025-01-27 11:40:17 +00:00
|
|
|
let deck_files = readdirSync(path)
|
|
|
|
for( const deck_file of deck_files) {
|
|
|
|
let api_object = {
|
|
|
|
"selected_bset": sanitized_name,
|
|
|
|
"name": deck_file.split(".txt")[0],
|
|
|
|
"commander_name": "",
|
|
|
|
"cards": []
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = readFileSync(path + deck_file, 'utf8')
|
|
|
|
let lines = data.split(/\n/)
|
|
|
|
lines = lines.filter((line) => line.match(/[0-9]+\s[\w]+/) != undefined)
|
|
|
|
let commander_line = lines[lines.length - 1]
|
|
|
|
api_object["commander_name"] = get_line_data(commander_line).sanitized_name
|
|
|
|
for(const card of lines.slice(0, lines.length - 1)){
|
|
|
|
api_object.cards.push(get_line_data(card))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fetch(base_api_url + '/api/account/decks/create', {
|
|
|
|
method: "POST",
|
|
|
|
headers: {Authorization: 'Bearer ' + token},
|
|
|
|
body: JSON.stringify(api_object)
|
|
|
|
}).then((res) => {
|
|
|
|
if(res.status == 200) {
|
|
|
|
console.log("Deck created")
|
|
|
|
} else {
|
|
|
|
console.log("Problem with : " + deck_file)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|