Skip to content
Permalink
Browse files
Initial Upload
  • Loading branch information
sultanh5 committed Apr 23, 2020
0 parents commit 1446a063469c43d5ac764477027412f00d658ea5
Show file tree
Hide file tree
Showing 67 changed files with 25,993 additions and 0 deletions.
120 README.md
@@ -0,0 +1,120 @@
**_# fileSharing_**

_software engineering project: File sharing_

When uploading a file to share between users, the sender can choose between drag and drop or search the file. Once sent, the receiver gets and email with a link to download the file. To download, the receiver must be logged in to get access to the list of files available to download. Each file is only available for 3 days or until it is downloaded. The receiver can also preview the files and get information such as format, size, date and time of upload and remaining time until deletion.

Team Members


**Dependencies**
- Koa
- nodeJS


***: Basic features**
**Logged-in users upload files to the server.**
**Email a link to download the file.**
**The files are not stored in the public directory.**
**The download link with a # string, not the file name.**
****: intermediate features**
**Files are deleted after downloaded or after 3 days.**
**All files should download.**

*****: advanced features**
**Choose the username of who can access it.**
**This username must already exist.**
**Logged in user have a list of the files they can download.**
**All files in the list should have: type of file, size, date and time of upload and time until deletion.**

**Team members**


| [Guilherme](https://github.coventry.ac.uk/deoliveg) | [Josh](https://github.coventry.ac.uk/handley7) | [Preeth](https://github.coventry.ac.uk/selvamop) | [Sofia](https://github.coventry.ac.uk/valente3) |
| :---: | :---: | :---: |:---: |
| | | | | | | |
|<img src="authors/gui.jpg" width="100"> | <img src="authors/josh.jpg" width="100"> | <img src="authors/preeth.jpg" width="100"> | <img src="authors/sofia.jpg" width="100">

______________________________________________________________________________________________________________________________

*Installation*

The install the packages:
- `npm install`

______________________________________________________________________________________________________________________________

*Git*

Tutorial on how to work with git branches:
- https://rogerdudler.github.io/git-guide/

______________________________________________________________________________________________________________________________

*Running*

______________________________________________________________________________________________________________________________

*Debugging*

Debugging can be made with VS Code by pressing `f5` or with `nmp run watch`
______________________________________________________________________________________________________________________________

*Folder Structure*

<pre>
Valente3/
├── index.js
├── README.md
├── modules/
│ └── user.js
├──public/
│ ├── avatars/
│ │ └──avatar.png
│ ├──images/
│ │ ├──bell.svg
│ │ ├──logo.pn
│ │ ├──facebook.svg
│ │ ├──instagram.svg
│ │ ├──linkedin.svg
│ │ ├──search.svg
│ │ ├──subject.svg
│ │ └──twitter.svg
│ ├──css/
│ │ └──tylesheet.css
│ └──style.css
├──unit tests/
│ └──user.spec.js
├──views/
│ ├──error.handlebars
│ ├──index.handlebars
│ ├──login.handlebars
│ ├──register.handlebars
│ ├──nav.hatml
│ ├──about.html
│ ├──download.html
│ ├──footer.html
│ └──homepage.html
├──authors/
│ ├──sofia.png
│ ├──josh.png
└──layout/
├──abput page.png
├──contacts page.png
├──homepage.png
├──log-in pop-up.png
├──my downloads.png
├──username.png
└──website layout.xd
</pre>




@@ -0,0 +1,24 @@
'use strict'


module.exports = class Table {

static createUserTable() {
return `CREATE TABLE IF NOT EXISTS users
(id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT, email TEXT, pass TEXT);`
}

static createFileTable() {
return `CREATE TABLE IF NOT EXISTS files(
downloadId INTEGER PRIMARY KEY AUTOINCREMENT,
filePath TEXT,
fileName TEXT,
uploadDate TEXT,
senderEmail TEXT,
receiverEmail TEXT,
encryptedFileName TEXT,
FOREIGN KEY(senderEmail) REFERENCES users(username)
);`
}
}
@@ -0,0 +1,48 @@
#!/usr/bin/env node
'use strict'

/* MODULE IMPORTS */
const Koa = require('koa')
const views = require('koa-views')
const staticDir = require('koa-static')
const bodyParser = require('koa-bodyparser')
const session = require('koa-session')
const fileRoutes = require('./routs/filesRouts')
const userRoutes = require('./routs/userRouts')
//const jimp = require('jimp')

const koaBody = require('koa-body')

const app = new Koa()

/* CONFIGURING THE MIDDLEWARE */
app.keys = ['darkSecret']
app.use(staticDir('public'))
app.use(staticDir('./private'))
app.use(koaBody())
app.use(bodyParser())
app.use(session(app))
app.use(views(`${__dirname}/views`, {
extension: 'handlebars',
options: {
partials: {
navbar: `${__dirname}/views/partials/nav.handlebars`,
footer: `${__dirname}/views/partials/footer.handlebars`
}
},
map: {
handlebars: 'handlebars'
}
}))


const defaultPort = 8080
const port = process.env.PORT || defaultPort

app.use(fileRoutes.routes())
app.use(userRoutes.routes())
app.use(fileRoutes.allowedMethods())
app.use(userRoutes.allowedMethods())

module.exports = app.listen(port, async() => console.log(`listening on port ${port}`))

@@ -0,0 +1,22 @@

{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"source": {
"include": [ "." ],
"exclude": [ "node_modules" ],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": ["jsdoc-route-plugin"],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
},
"opts": {
"destination": "docs/jsdoc",
"recurse": true
}
}
@@ -0,0 +1,147 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: filesDownload.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

<h1 class="page-title">Source: filesDownload.js</h1>






<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* This is the filesDownload module
* @requires "sqllite"
* @requires "table"
*/

'use strict'

const sqlite = require('sqlite-async')
const table = require('../TablesDatabase.js')

module.exports = class Download {

/**
* Creates an instance of Download.
* @constructor
* @param {*} dbName - the name of the database
*/
constructor(dbName = ':memory:') {
return (async() => {
try{
this.db = await sqlite.open(dbName)
await this.db.run(table.createFileTable())
return this
} catch(err) {
throw err
}
})()
}

/**
* addDummy function
* @async
*/

async addDummy() {
try{
//dummy database records
const sqlNew = `INSERT INTO files(uploadDate, receiverEmail, senderEmail, filePath, fileName)
VALUES("date('now')","toze@gmail.com", 1, "../images/alarm.png", "Alarm Image")`
await this.db.run(sqlNew)
} catch(err) {
throw err
}
}

/**
* download function - fetches the download file path from the database from a given downloadID
* @async
* @param {*} downloadId
*/
async download(downloadId) {
try {
const sql = `SELECT count(downloadId) AS count FROM files WHERE downloadId = "${downloadId}";`
const records = await this.db.get(sql)
if(records === 0) throw new Error('Inexistent file.')
const sql2 = `SELECT filePath FROM files WHERE downloadId = ${downloadId}`
const filePath = await this.db.get(sql2)
return filePath
} catch(err) {
throw err
}
}

/**
* getName function fetches the name of a file, given it's downloadID
* @async
* @param {*} downloadId
*/
async getName(downloadId) {
try {
const sql = `SELECT count(downloadId) AS count FROM files WHERE downloadId = "${downloadId}";`
const records = await this.db.get(sql)
if(records === 0) throw new Error('Inexistent file.')
const sql2 = `SELECT fileName FROM files WHERE downloadId = ${downloadId}`
const fileName = await this.db.get(sql2)
return fileName
} catch(err) {
throw err
}
}

/**
* function deleteFile, deletes the file from it's path, given the downloadID
* @async
* @param {*} downloadId
*/
async deleteFile(downloadId) {
try {
const sql2 = `DELETE FROM files WHERE downloadId = ${downloadId}`
await this.db.run(sql2)
} catch(err) {
throw err
}
}
}
</code></pre>
</article>
</section>




</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports_module.exports.html">exports</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Nov 30 2019 17:57:59 GMT+0000 (Greenwich Mean Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>

0 comments on commit 1446a06

Please sign in to comment.