Skip to content

Commit

Permalink
Edit page .authme rollback file support #152
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Nov 13, 2021
1 parent b182a9e commit cc88b15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const rollback_con = document.querySelector(".rollback")
const rollback_text = document.querySelector("#rollbackText")
let cache = true

fs.readFile(path.join(cache_path, "latest.authmecache"), "utf-8", (err, data) => {
fs.readFile(path.join(cache_path, "rollback.authme"), "utf-8", (err, data) => {
if (err) {
logger.warn("Cache file don't exist")
} else {
Expand Down Expand Up @@ -98,7 +98,7 @@ const rollback = () => {
})
.then((result) => {
if (result.response === 0) {
fs.readFile(path.join(cache_path, "latest.authmecache"), "utf-8", (err, data) => {
fs.readFile(path.join(cache_path, "rollback.authme"), "utf-8", (err, data) => {
if (err) {
logger.error("Error reading hash file", err)
} else {
Expand Down Expand Up @@ -173,7 +173,7 @@ const go = () => {
document.querySelector(".codes_container").innerHTML = ""

if (cache === true) {
createCache()
createRollback()
cache = false
}

Expand Down Expand Up @@ -362,7 +362,13 @@ const newSaveCodes = () => {

const encrypted = aes.encrypt(save_text, key)

/**
* Save codes
* @type{LibAuthmeFile}
* */
const codes = {
role: "codes",
encrypted: true,
codes: encrypted.toString("base64"),
date: time.timestamp(),
version: "2",
Expand Down Expand Up @@ -443,8 +449,10 @@ const addMore = () => {
})
}

// ? create cache
const createCache = () => {
/**
* Create rollback.authme file
*/
const createRollback = () => {
if (file.security.new_encryption === true) {
fs.readFile(path.join(file_path, "codes", "codes.authme"), "utf-8", (err, data) => {
if (err) {
Expand All @@ -454,11 +462,14 @@ const createCache = () => {
fs.mkdirSync(cache_path)
}

fs.writeFile(path.join(cache_path, "latest.authmecache"), data, (err) => {
const loaded = JSON.parse(data)
loaded.role = "rollback"

fs.writeFile(path.join(cache_path, "rollback.authme"), convert.fromJSON(loaded), (err) => {
if (err) {
logger.error("Failed to create cache folder", err)
} else {
logger.log("Cache file created")
logger.log("Rollback file created")
}
})
}
Expand All @@ -472,7 +483,7 @@ const createCache = () => {
fs.mkdirSync(cache_path)
}

fs.writeFile(path.join(cache_path, "latest.authmecache"), data, (err) => {
fs.writeFile(path.join(cache_path, "rollback.authme"), data, (err) => {
if (err) {
logger.error("Failed to create cache folder", err)
} else {
Expand Down
9 changes: 9 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ module.exports = {
types,
}
},

/**
* Convert JSON to text
* @param {Object} object
* @return {String} stringify
*/
fromJSON: (object) => {
return JSON.stringify(object, null, "\t")
},
}

0 comments on commit cc88b15

Please sign in to comment.