Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #1 from 5001CEM-1920SEPJAN/one-last-hope3
One last hope3
- Loading branch information
Showing
53 changed files
with
4,357 additions
and
1,580 deletions.
There are no files selected for viewing
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,2 @@ | ||
/node_modules | ||
/docs |
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,39 @@ | ||
#!/bin/bash | ||
#found in https://www.reddit.com/r/bash/comments/8inq6i/validate_git_commit_message/, contributed by user frakman1 | ||
#rules based on https://chris.beams.io/posts/git-commit/#seven-rules | ||
|
||
echo -e "\e[32m--- Checking Commit Message ---\e[0m"; | ||
|
||
cnt=0 | ||
while IFS='' read -r line || [[ -n "$line" ]]; do | ||
cnt=$((cnt+1)) | ||
length=${#line} | ||
if [ $cnt -eq 1 ]; then | ||
# Checking if subject exceeds 50 characters | ||
if [ $length -gt 50 ]; then | ||
echo -e "\e[31m*** Subject line exceeds 50 characters ***\e[0m"; | ||
exit 1 | ||
fi | ||
i=$(($length-1)) | ||
last_char=${line:$i:1} | ||
# Last character must not have a punctuation | ||
if [[ ! $last_char =~ [0-9a-zA-Z] ]]; then | ||
echo -e "\e[31m*** Last character of subject line must not contain punctuation ***\e[0m"; | ||
exit 1 | ||
fi | ||
elif [ $cnt -eq 2 ]; then | ||
# Subject must be followed by a blank line | ||
if [ $length -ne 0 ]; then | ||
echo -e "\e[31m*** Current subject line follows a non-empty line. Subject lines should always be followed by a blank line ***\e[0m"; | ||
exit 1 | ||
fi | ||
else | ||
# Any line in body must not exceed 72 characters | ||
if [ $length -gt 72 ]; then | ||
echo -e "\e[31m*** Line \"$line\" exceeds 72 characters ***\e[0m"; | ||
exit 1 | ||
fi | ||
fi | ||
done < "$1" | ||
|
||
|
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 |
---|---|---|
@@ -25,3 +25,5 @@ trace/ | ||
|
||
*.codio | ||
*.c9 | ||
|
||
.vscode/ |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
'use strict' | ||
|
||
const Database = require('sqlite-async') | ||
|
||
class Article { | ||
|
||
constructor(dbName = ':memory:') { | ||
return (async() => { | ||
this.db = await Database.open(dbName) | ||
const sql = `CREATE TABLE IF NOT EXISTS Articles ( | ||
"article_id" INTEGER PRIMARY KEY AUTOINCREMENT, | ||
"title" TEXT NOT NULL, | ||
"summary" TEXT, | ||
"content" NVARCHAR NOT NULL, | ||
"written_date" DATE NOT NULL, | ||
"author" TEXT, | ||
"image_url" TEXT, | ||
"tag" TEXT, | ||
"released" INTEGER, | ||
"rating" INTEGER);` | ||
await this.db.run(sql) | ||
return this | ||
})() | ||
} | ||
|
||
async upload(title, summary, content, tag, username) { | ||
try{ | ||
if(title === null) throw new Error('Please enter a title for your article') | ||
else if(summary === null) throw new Error('Please enter a summary for your article') | ||
else if(content === null) throw new Error('Where is the content? Please Enter some text in the content box') | ||
const date = await new Date() | ||
const fullDate = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}` | ||
let sql = `INSERT INTO Articles(title, summary, content, written_date, tag, released, author) | ||
VALUES("${title}", "${summary}", "${content}", "${fullDate}", "${tag}", 0, "${username}")` | ||
await this.db.run(sql) | ||
sql = 'SELECT last_insert_rowid() as id' | ||
const result = await this.db.get(sql) | ||
sql = `UPDATE Articles SET image_url = "articleImages/${result.id}.png" WHERE article_id = ${result.id};` | ||
await this.db.run(sql) | ||
return result.id | ||
} catch(err) { | ||
throw err | ||
} | ||
} | ||
|
||
async reupload(id, title, summary, content, tag) { | ||
try{ | ||
if(title === null) throw new Error('Please enter a title for your article') | ||
else if(summary === null) throw new Error('Please enter a summary for your article') | ||
else if(content === null) throw new Error('Where is the content? Please Enter some text in the content box') | ||
const date = await new Date() | ||
const fullDate = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}` | ||
let sql = `UPDATE Articles SET title = "${title}", summary = "${summary}", content = "${content}", | ||
written_date = "${fullDate}", tag = "${tag}", released = 0 | ||
WHERE article_id = ${id};` | ||
await this.db.run(sql) | ||
sql = `UPDATE Articles SET image_url = "articleImages/${id}.png" WHERE article_id = ${id};` | ||
await this.db.run(sql) | ||
return true | ||
} catch(err) { | ||
throw err | ||
} | ||
} | ||
|
||
async release(id) { | ||
const query = `UPDATE Articles SET released = 1 WHERE article_id = ${id};` | ||
await this.db.run(query) | ||
} | ||
|
||
async get(id) { | ||
try{ | ||
const data = await this.db.get(`SELECT * FROM Articles WHERE article_id = '${id}';`) | ||
if(data === undefined) throw new Error('This article does not exist') | ||
return data | ||
} catch(err) { | ||
throw err | ||
} | ||
} | ||
|
||
async getByTag(tag) { | ||
const data = await this.db.all(`SELECT * FROM Articles WHERE tag = '${tag}';`) | ||
Array.prototype.reverse.call(data) | ||
return data | ||
} | ||
|
||
async getUnreleased() { | ||
const data = await this.db.all('SELECT * FROM Articles WHERE released = 0;') | ||
Array.prototype.reverse.call(data) | ||
return data | ||
} | ||
|
||
async search(searchQuery) { | ||
let sql = 'SELECT * FROM Articles WHERE released = 1;' | ||
if(searchQuery !== undefined && searchQuery.q !== undefined) { | ||
sql = `SELECT * FROM Articles | ||
WHERE upper(title) LIKE upper("%${searchQuery.q}%") AND released = 1 | ||
OR upper(summary) LIKE upper("%${searchQuery.q}%") AND released = 1 | ||
OR upper(content) LIKE upper("%${searchQuery.q}%") AND released = 1 | ||
OR upper(author) LIKE upper("%${searchQuery.q}%") AND released = 1;` | ||
} | ||
const data = await this.db.all(sql) | ||
Array.prototype.reverse.call(data) | ||
return data | ||
} | ||
} | ||
module.exports = Article |
Oops, something went wrong.