-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Ktilis:main
Thanks to Ktilis for this amazing PR#2! Remapping config strings & unique links for skin files by md5
- Loading branch information
Showing
25 changed files
with
423 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import database from '../../database.config'; | ||
import connection from '../mysqlConnect'; | ||
|
||
/** | ||
* Creates a new user in the database with the given username and hash. | ||
* | ||
* @param {string} username - The username of the new user. | ||
* @param {string} hash - The password of the new user. | ||
* @return {Promise<boolean>} A promise that resolves to true if the user was created successfully, or false otherwise. | ||
*/ | ||
export default async function addNewSkin(username: string, hash: string, last_updated: string): Promise<boolean> { | ||
try { | ||
const result = await connection.execute( | ||
`INSERT INTO ${database.database.tables.skins.name} | ||
(${database.database.tables.skins.columns.username}, | ||
${database.database.tables.skins.columns.hash}, | ||
${database.database.tables.skins.columns.last_updated}) | ||
VALUES (?, ?, ?)`, | ||
[username, hash, last_updated], | ||
); | ||
return true; | ||
} catch (error) { | ||
console.error('Error creating user:', error); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import mysql from 'mysql2'; | ||
import database from '../../database.config'; | ||
import connection from '../mysqlConnect'; | ||
|
||
/** | ||
* Is user exists | ||
* | ||
* @param {string} username - The username of the user to find. | ||
* @return {Promise<mysql.RowDataPacket | null>} A promise that resolves true if the user was found, or null if not found. | ||
*/ | ||
export default async function isUserExists(username: string): Promise<boolean> { | ||
try { | ||
const result = await new Promise<mysql.RowDataPacket[]>((resolve, reject) => { | ||
connection.execute( | ||
`SELECT * | ||
FROM ${database.database.tables.skins.name} | ||
WHERE ${database.database.tables.skins.columns.username} = ?`, | ||
[username], | ||
(err, result: mysql.RowDataPacket[]) => { | ||
if (err) { | ||
console.log(err); | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
if (result.length > 0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import mysql from 'mysql2'; | ||
import database from '../../database.config'; | ||
import connection from '../mysqlConnect'; | ||
|
||
/** | ||
* Returning player's skin hash | ||
* | ||
* @param {string} hash - The skin hash of the user to find. | ||
* @return {Promise<string | null>} A promise that resolves with the hash if found, or null if not found. | ||
*/ | ||
export default async function getHashByUsername(username: string): Promise<string | null> { | ||
try { | ||
const result = await new Promise<mysql.RowDataPacket[]>((resolve, reject) => { | ||
connection.execute( | ||
`SELECT ${database.database.tables.skins.columns.hash} | ||
FROM ${database.database.tables.skins.name} | ||
WHERE ${database.database.tables.skins.columns.username} = ?`, | ||
[username], | ||
(err, result: mysql.RowDataPacket[]) => { | ||
if (err) { | ||
console.log(err); | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
if (result.length > 0) { | ||
return result[0][database.database.tables.skins.columns.hash]; | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import mysql from 'mysql2'; | ||
import database from '../../database.config'; | ||
import connection from '../mysqlConnect'; | ||
|
||
/** | ||
* Returning player's skin hash | ||
* | ||
* @param {string} hash - The skin hash of the user to find. | ||
* @return {Promise<string | null>} A promise that resolves with the hash if found, or null if not found. | ||
*/ | ||
export default async function getUserBySkinHash(hash: string): Promise<string | null> { | ||
try { | ||
const result = await new Promise<mysql.RowDataPacket[]>((resolve, reject) => { | ||
connection.execute( | ||
`SELECT ${database.database.tables.skins.columns.username} | ||
FROM ${database.database.tables.skins.name} | ||
WHERE ${database.database.tables.skins.columns.hash} = ?`, | ||
[hash], | ||
(err, result: mysql.RowDataPacket[]) => { | ||
if (err) { | ||
console.log(err); | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
if (result.length > 0) { | ||
return result[0][database.database.tables.skins.columns.username]; | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import database from '../../database.config'; | ||
import connection from '../mysqlConnect'; | ||
|
||
export default async function updateUserSkinHash(username: string, hash: string, last_updated: string): Promise<boolean> { | ||
try { | ||
const result = await connection.execute( | ||
`UPDATE ${database.database.tables.skins.name} | ||
SET ${database.database.tables.skins.columns.hash} = ?, ${database.database.tables.skins.columns.last_updated} = ? | ||
WHERE ${database.database.tables.skins.columns.username} = ?`, | ||
[hash, last_updated, username] | ||
); | ||
|
||
console.log(`Updated row(s)`); | ||
|
||
return true; | ||
} catch (error) { | ||
console.error('Error updating values:', error); | ||
return false; | ||
} | ||
}; |
Oops, something went wrong.