mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 12:00:41 +03:00
Added other files
This commit is contained in:
parent
9c4cd23464
commit
4009344da9
5 changed files with 111 additions and 0 deletions
5
classes/index.js
Normal file
5
classes/index.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const Message = require("./message")
|
||||
const Thread = require("./thread")
|
||||
const User = require("./user")
|
||||
|
||||
module.exports = { Message, Thread, User }
|
15
classes/message.js
Normal file
15
classes/message.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
const User = require("./user")
|
||||
|
||||
module.exports = class Message {
|
||||
|
||||
|
||||
constructor(content, author = new User(), time = new Date().getTime()) {
|
||||
|
||||
|
||||
this.content = content;
|
||||
this.author = author;
|
||||
this.time = time;
|
||||
|
||||
}
|
||||
}
|
49
classes/thread.js
Normal file
49
classes/thread.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
const db = require("quick.db")
|
||||
const User = require("./user")
|
||||
|
||||
module.exports = class Thread {
|
||||
|
||||
constructor(title, content, author = new User(), messages = [], time = new Date().getTime()) {
|
||||
|
||||
this.content = content;
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.messages = messages;
|
||||
this.time = time;
|
||||
|
||||
}
|
||||
|
||||
getId(id = this.id) {
|
||||
const thread = db.get("threads."+id);
|
||||
if (!thread) return null;
|
||||
this.id = id;
|
||||
const { content, title, author, messages = [], time = new Date().getTime() } = thread;
|
||||
this.content = content
|
||||
this.title = title
|
||||
this.author = author
|
||||
this.messages = messages;
|
||||
this.time = time;
|
||||
|
||||
return this
|
||||
}
|
||||
takeId(){
|
||||
|
||||
|
||||
this.id = db.get("threads").length;
|
||||
return this
|
||||
}
|
||||
|
||||
push(message){
|
||||
this.messages.push(message)
|
||||
return this;
|
||||
}
|
||||
write(id = this.id) {
|
||||
|
||||
db.set("threads."+id, this)
|
||||
}
|
||||
getLink(id = this.id) {
|
||||
return "/threads/" + id;
|
||||
|
||||
|
||||
}
|
||||
}
|
40
classes/user.js
Normal file
40
classes/user.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const db = require("quick.db")
|
||||
|
||||
module.exports = class User {
|
||||
|
||||
|
||||
constructor(name = "guest", avatar = "/images/guest.png", time = new Date().getTime()) {
|
||||
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
this.time = time;
|
||||
|
||||
}
|
||||
|
||||
getId(id = this.id) {
|
||||
const user = db.get("users." + id);
|
||||
if (!user) return null;
|
||||
this.id = id;
|
||||
const { name = "guest", avatar = "/images/guest.png", time = new Date().getTime() } = user;
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
this.time = time;
|
||||
return this
|
||||
}
|
||||
takeId() {
|
||||
let id = db.get("users");
|
||||
this.id = id ? id.length : 0;
|
||||
return this
|
||||
}
|
||||
|
||||
write(id = this.id) {
|
||||
|
||||
db.set("users." + id, this)
|
||||
}
|
||||
getLink(id = this.id) {
|
||||
return "/users/" + id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
2
errors/error.js
Normal file
2
errors/error.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
module.exports = (res, type, error) =>
|
||||
res.status(type).render("error", { type, error });
|
Loading…
Reference in a new issue