better first time xp
This commit is contained in:
64
app.js
64
app.js
@@ -1,23 +1,73 @@
|
||||
const fs = require('fs');
|
||||
if (process.argv[0] == "--first-time") {
|
||||
initialise()
|
||||
}
|
||||
|
||||
const express = require('express');
|
||||
const showdown = require('showdown')
|
||||
const crypto = require('crypto'); // For encrypting passwords
|
||||
const { fromUnixTime, format, getUnixTime } = require("date-fns")
|
||||
const fs = require('fs');
|
||||
|
||||
const users = require('./users.js');
|
||||
const posts = require('./posts.js');
|
||||
const comments = require('./comments.js');
|
||||
const config = require('./config.js');
|
||||
let converter = new showdown.Converter({simpleLineBreaks: true, tables: true, strikethrough: true, tasklists: true, encodeEmails: true})
|
||||
let users
|
||||
let posts
|
||||
let comments
|
||||
let config
|
||||
|
||||
try {
|
||||
users = require('./users.js');
|
||||
posts = require('./posts.js');
|
||||
comments = require('./comments.js');
|
||||
config = require('./config.js');
|
||||
}
|
||||
catch (error) {
|
||||
console.log("A file is missing!")
|
||||
console.log("Run with --first-time to initialise the program")
|
||||
console.log("Error output:\n", error)
|
||||
process.exit(1)
|
||||
}
|
||||
let converter = new showdown.Converter({
|
||||
simpleLineBreaks: true,
|
||||
tables: true,
|
||||
strikethrough: true,
|
||||
tasklists: true,
|
||||
encodeEmails: true
|
||||
})
|
||||
const app = express();
|
||||
|
||||
let footer_div = config.site_wide_footer
|
||||
footer_div = replace_format_indicators(footer_div)
|
||||
|
||||
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json());
|
||||
app.use(express.static(config.root_path));
|
||||
|
||||
function initialise() {
|
||||
try {
|
||||
const users = require("./users.js");
|
||||
}
|
||||
catch (error) {
|
||||
fs.writeFileSync(`${__dirname}/users.js`, `export const users = []`)
|
||||
}
|
||||
try {
|
||||
const posts = require("./posts.js");
|
||||
}
|
||||
catch (error) {
|
||||
fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = []`)
|
||||
}
|
||||
try {
|
||||
const users = require("./comments.js");
|
||||
}
|
||||
catch (error) {
|
||||
fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = []\nexport const counter = 0`)
|
||||
}
|
||||
try {
|
||||
const users = require("./config.js");
|
||||
}
|
||||
catch (error) {
|
||||
fs.copyFile('example-config.js', 'config.js')
|
||||
}
|
||||
}
|
||||
|
||||
function get_userID(username) {
|
||||
for (let i = 0; i < users.users.length; i++) {
|
||||
if (users.users[i]['username'] == username) {
|
||||
|
Reference in New Issue
Block a user