-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
35,287 additions
and
0 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,9 @@ | ||
{ | ||
"presets": [ | ||
"@babel/react" , | ||
"@babel/env" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} |
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,25 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
./backend/.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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,7 @@ | ||
Copyright 2021 MAFY Hemsidan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,42 @@ | ||
# Välkommen till [MAFY](https://mohikan.notion.site/mohikan/MAFY-Hemsidan-d5ddd0e8481b43508ef2b7dfa60edc2a)! | ||
Denna repository:n använder Node.JS, en förutsättning är att du har Node.js installerat på din maskin. | ||
|
||
## Hur använder jag denna repo? | ||
För att klona denna repository får du trycka på den gröna "Code" knappen ovan och sedan välja vilken metod du vill använda. | ||
När du har repository:n klonad får du köra `npm install` för att ladda ner alla dependencies. | ||
|
||
I `package.json` finns det flera kommandon som du kan använda för att: | ||
1. Köra endast backend: `npm run start-server` | ||
2. Köra endast frontend: `npm run start-client` | ||
3. Köra både backend och frontend (produktion): `npm run start` | ||
|
||
För att backend:en ska köras som det ska finns det flera miljövariabler som krävs, se `./backend/example.env` | ||
|
||
Frontend:en kan köras utan behov till dessa miljövariabler | ||
(genom kommandon `npm run start-client`) | ||
|
||
## Vad kan jag bidra med? | ||
Det finns flera saker man kan bidra till för utvecklingen av denna tjänst | ||
Vissa av dessa kräver igen till nästan ingen erfarenhet av programmering till exempel: | ||
|
||
* Korrigering av språk | ||
|
||
* Korrigering av de LaTeX-formatterade frågorna i `(./backend/public/json/math.json och ./backend/public/json/physics.json)` | ||
För att konvertera frågorna till text och (LaTeX) användes tjänsten MathPix. | ||
Dock kan det förekomma vissa särstavningar eller att vissa LaTeX uttryck laddas upp fel | ||
|
||
* Infoga bilder för fysikdelen `(./backend/public/json/physics.json)` | ||
Många frågor i fysikdelen använder figurer (som oftast saknas). | ||
Figurerna måste därför skärmdumpas och laddas upp manuellt i `physics.json`-filen. | ||
Enklaste sättet är uppladdning m.h.a imgur.com. Länken till Imgur-bilden (måste avsluta med .png eller .jpg) kan sedan kopieras och infogas för respektive fråga. | ||
För att snabbt hitta vilka frågor som saknar bilder kör `CTRL + F` och sök "img". | ||
|
||
### Om du är erfaren av programmering kan du: | ||
* Förbättra koden | ||
Mycket är koden är "over-rushed", saknar kommentarer eller dokumentering, så det är hjälpsamt att förbättra koden genom omanvändbara funktioner etc. | ||
|
||
* Skapa Unit Tests | ||
Denna repo saknar i nuläget Unit Tester totalt. En redan-nedladdad Testing-Library är JEST, det rekommenderas att användas. | ||
|
||
* Bidra till utvecklingen av funktioner för tjänster | ||
Gå till [TODO-LISTAN](https://mohikan.notion.site/TODO-Listan-212afe7744754fd58ff30ec6ecec331a?pvs=4) |
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,17 @@ | ||
# En ".env" fil krävs för att backend:en ska fungera som det ska. | ||
# Detta är bara en mall för vilka miljövariabler som krävs, vill du använda denna | ||
# fil får du ändra namnet till ".env" istället för "example.env" | ||
|
||
# Domänen till servern + hemsidan | ||
domain="http://localhost:3000" | ||
# Vilken port servern kommer att köras på | ||
PORT=3000 | ||
# Discord Client ID + Client Secret, se https://discord.com/developers/applications | ||
clientId="" | ||
clientSecret="" | ||
# Databas URI:n, servern använder MongoDB som databas, se https://www.mongodb.com/docs/manual/reference/connection-string/ | ||
DB_URI="" | ||
# 'DISCORD_OAUTH2_SESSION_ID' session secret, kan egentligen vara vad som helst | ||
SECRET="" | ||
# Encyption secret för encyption av refresh_token + access_token för varje användare | ||
ENCRYPT_SECRET="" |
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,50 @@ | ||
require('dotenv').config(); | ||
const express = require("express"); | ||
const app = express(); | ||
const routes = require("./routes/index.js"); | ||
const fileUpload = require('express-fileupload'); | ||
const cors = require("cors"); | ||
const path = require("path"); | ||
const mongoose = require('mongoose'); | ||
const session = require("express-session"); | ||
const cookieParser = require("cookie-parser"); | ||
const {deserialize} = require('./src/Session.js'); | ||
|
||
mongoose.connect(process.env.DB_URI); | ||
|
||
|
||
// We need to later turn this to only respond to requests from our domain | ||
app.use(cors({orgin: "*"})); | ||
app.use(fileUpload()); | ||
|
||
app.set('views', path.join(__dirname, "..", "build")); | ||
app.set('view engine', 'html'); | ||
app.engine('html', require('ejs').renderFile); | ||
|
||
app.use(express.static(path.join(__dirname, "..", "build"))); | ||
app.use("/public", express.static("public")); | ||
|
||
app.use(cookieParser()); | ||
|
||
app.use(session({ | ||
secret: process.env.SECRET, | ||
name: 'DISCORD_OAUTH2_SESSION_ID', | ||
resave: false, | ||
saveUninitialized: false, | ||
cookie: { | ||
maxAge: 3600000 * 24 * 7, | ||
} | ||
})); | ||
|
||
app.use(deserialize); | ||
|
||
app.use("/api/", routes); | ||
|
||
app.get("/*", (req, res) => { | ||
res.render("./index.html"); | ||
}); | ||
|
||
|
||
app.listen(process.env.PORT || 3000); | ||
|
||
module.exports = app; |
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,14 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Session = new mongoose.Schema( | ||
{ | ||
sessionID: {type: String}, | ||
expiresAt: {type: Date}, | ||
data: {type: String} | ||
}, | ||
{collection: 'sessions'} | ||
); | ||
|
||
const model = mongoose.model('Session', Session); | ||
|
||
module.exports = model; |
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 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Solution = new mongoose.Schema( | ||
{ | ||
questionNum: {type: String}, | ||
solutions: {type: Array} | ||
/** | ||
* [ | ||
* { | ||
* ID: ..., | ||
* uploadedAt: ..., | ||
* solution: ..., | ||
* type: image|text|video, | ||
* deletehash..., | ||
* width: ..., | ||
* height: ... | ||
* } | ||
* ] | ||
*/ | ||
}, | ||
{collection: 'solutions'} | ||
); | ||
|
||
const model = mongoose.model('Solution', Solution); | ||
|
||
module.exports = model; |
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,19 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const User = new mongoose.Schema( | ||
{ | ||
ID: {type: String, required: true, unique: true}, | ||
username: {type: String, required: true}, | ||
name: {type: String}, | ||
avatar: {type: String}, | ||
accessToken: {type: String, required: true}, | ||
refreshToken: {type: String, required: true}, | ||
correct: {type: Array}, | ||
wrong: {type: Array} | ||
}, | ||
{collection: 'mafy_users'} | ||
); | ||
|
||
const model = mongoose.model('UserData', User); | ||
|
||
module.exports = model; |
Oops, something went wrong.