mirror of
https://github.com/Nezumi-2711/uptime-monitoring.git
synced 2026-09-22 13:48:31 +00:00
feat: setup oxlint and prettier for the project
This commit is contained in:
+17
-17
@@ -1,35 +1,35 @@
|
||||
import { hashPassword } from "../src/worker/lib/password";
|
||||
import { hashPassword } from '../src/worker/lib/password';
|
||||
|
||||
async function readPassword() {
|
||||
if (!process.stdin.isTTY) {
|
||||
return (await new Response(Bun.stdin.stream()).text()).trimEnd();
|
||||
}
|
||||
|
||||
process.stdout.write("Password: ");
|
||||
process.stdout.write('Password: ');
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.setEncoding('utf8');
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
let password = "";
|
||||
let password = '';
|
||||
const cleanup = () => {
|
||||
process.stdin.setRawMode(false);
|
||||
process.stdin.pause();
|
||||
process.stdout.write("\n");
|
||||
process.stdout.write('\n');
|
||||
};
|
||||
|
||||
process.stdin.on("data", (key: string) => {
|
||||
if (key === "\u0003") {
|
||||
process.stdin.on('data', (key: string) => {
|
||||
if (key === '\u0003') {
|
||||
cleanup();
|
||||
reject(new Error("Cancelled"));
|
||||
reject(new Error('Cancelled'));
|
||||
return;
|
||||
}
|
||||
if (key === "\r" || key === "\n") {
|
||||
if (key === '\r' || key === '\n') {
|
||||
cleanup();
|
||||
resolve(password);
|
||||
return;
|
||||
}
|
||||
if (key === "\u007f" || key === "\b") {
|
||||
if (key === '\u007f' || key === '\b') {
|
||||
password = password.slice(0, -1);
|
||||
return;
|
||||
}
|
||||
@@ -43,23 +43,23 @@ function sqlValue(value: string) {
|
||||
}
|
||||
|
||||
function shellDoubleQuoted(value: string) {
|
||||
return value.replace(/[\\"$`]/g, "\\$&");
|
||||
return value.replace(/[\\"$`]/g, '\\$&');
|
||||
}
|
||||
|
||||
const password = await readPassword();
|
||||
if (password.length < 8) {
|
||||
console.error("Password must contain at least 8 characters.");
|
||||
console.error('Password must contain at least 8 characters.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const statement = [
|
||||
"INSERT OR REPLACE INTO admin_credentials",
|
||||
"(id, password_hash, created_at, updated_at)",
|
||||
'INSERT OR REPLACE INTO admin_credentials',
|
||||
'(id, password_hash, created_at, updated_at)',
|
||||
`VALUES (1, ${sqlValue(await hashPassword(password))}, ${now}, ${now});`,
|
||||
].join(" ");
|
||||
].join(' ');
|
||||
|
||||
console.log("\nLocal database:");
|
||||
console.log('\nLocal database:');
|
||||
console.log(`bunx wrangler d1 execute uptime --local --command "${shellDoubleQuoted(statement)}"`);
|
||||
console.log("\nRemote database:");
|
||||
console.log('\nRemote database:');
|
||||
console.log(`bunx wrangler d1 execute uptime --remote --command "${shellDoubleQuoted(statement)}"`);
|
||||
|
||||
Reference in New Issue
Block a user