Skip to content
Permalink
71b429b8cf
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
1695 lines (504 sloc) 19.9 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Module: upload</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">Module: upload</h1>
<section>
<header>
</header>
<article>
<div class="container-overview">
<div class="description">Upload Module.</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line9">line 9</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Classes</h3>
<dl>
<dt><a href="module-upload.upload.html">upload</a></dt>
<dd></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addToDB"><span class="type-signature">(async, static) </span>module.exports#addToDB<span class="signature">(hashID, fileName, ext, sourceUser, targetUser)</span><span class="type-signature"> &rarr; {integer}</span></h4>
<div class="description">
Adds the details of the file and its upload to the database
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>hashID</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Hashed name of the file.</td>
</tr>
<tr>
<td class="name"><code>fileName</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Name of the file straight from the upload form.</td>
</tr>
<tr>
<td class="name"><code>ext</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Separated extension of the file as a string.</td>
</tr>
<tr>
<td class="name"><code>sourceUser</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Username of the user who uploaded the file.</td>
</tr>
<tr>
<td class="name"><code>targetUser</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Username of the user who the file is being shared with.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line196">line 196</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- Returns a status code based on the outcome: 0 for success, -2 file is already uploaded, -3 any other error
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">integer</span>
</dd>
</dl>
<h4 class="name" id="checkUploadRes"><span class="type-signature">(async, static) </span>module.exports#checkUploadRes<span class="signature">(statusCode, name)</span><span class="type-signature"> &rarr; {array}</span></h4>
<div class="description">
Takes a status code and the hash ID of the chosen file and returns an appropriate message
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>statusCode</code></td>
<td class="type">
<span class="param-type">integer</span>
</td>
<td class="description last">Status of the upload operations</td>
</tr>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Name of the file taken straight from the upload form.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line115">line 115</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
][{integer} result, {string} message] - result: code to mark success or fail of upload, message: returns relevant message based on the statusCode
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="checkValidUser"><span class="type-signature">(async, static) </span>module.exports#checkValidUser<span class="signature">(username)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<div class="description">
Checks if a username belongs to a valid user.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>username</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Username of account being checked.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line76">line 76</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- Returns true if user is valid, false in any other case
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="generateFileDetails"><span class="type-signature">(async, static) </span>module.exports#generateFileDetails<span class="signature">(name)</span><span class="type-signature"> &rarr; {array}</span></h4>
<div class="description">
Creates a new file name, a hashed ID and a extension for the file being uploaded
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Name of the file taken straight from the upload form.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line95">line 95</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
][{string} saveName, {string} hashID, {string} ext] - saveName: name file is saved under, hashID: unique id for file, ext: file extension (type)
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="getExtension"><span class="type-signature">(async, static) </span>module.exports#getExtension<span class="signature">(name)</span><span class="type-signature"> &rarr; {string}</span></h4>
<div class="description">
Separates the extension from the filename.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Name of the file straight from the upload form.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line172">line 172</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<ul>
<li>
<dl>
<dt>
<div class="param-desc">
No file name passed (getExtension).
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">EmptyFileName</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</li>
<li>
<dl>
<dt>
<div class="param-desc">
File name is invalid: No extension found (getExtension).
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">NoExtension</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</li>
</ul>
<h5>Returns:</h5>
<div class="param-desc">
ext - Returns the extension of the file as a string
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="getUploadTime"><span class="type-signature">(async, static) </span>module.exports#getUploadTime<span class="signature">()</span><span class="type-signature"> &rarr; {integer}</span></h4>
<div class="description">
Adds the details of the file and its upload to the database
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line227">line 227</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
uploadTime - Retuns unix time in minutes (not ms as is the default)
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">integer</span>
</dd>
</dl>
<h4 class="name" id="hashFileName"><span class="type-signature">(async, static) </span>module.exports#hashFileName<span class="signature">(name)</span><span class="type-signature"> &rarr; {string}</span></h4>
<div class="description">
Hashes the name of the file using sha1 standards.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Name of the file straight from the upload form.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line147">line 147</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<ul>
<li>
<dl>
<dt>
<div class="param-desc">
No file name passed (fileName).
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">EmptyFileName</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</li>
<li>
<dl>
<dt>
<div class="param-desc">
File name is invalid: No extension found (fileName).
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">NoExtension</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</li>
</ul>
<h5>Returns:</h5>
<div class="param-desc">
hashName - Returns a hashed version of the file name (minus the extension), name is hashed using sha1 standard
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="uploadFile"><span class="type-signature">(async, static) </span>module.exports#uploadFile<span class="signature">(path, originalName, sourceUser, targetUser)</span><span class="type-signature"> &rarr; {array}</span></h4>
<div class="description">
Uploads a file to the server and the database.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Path to the file being uploaded.</td>
</tr>
<tr>
<td class="name"><code>originalName</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Original name of the file.</td>
</tr>
<tr>
<td class="name"><code>sourceUser</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Username of the user uploading the file.</td>
</tr>
<tr>
<td class="name"><code>targetUser</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Username of the user the file is being shared with.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="modules_upload.js.html">modules/upload.js</a>, <a href="modules_upload.js.html#line45">line 45</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
[{int} statusCode, {string} message] - Returns an array with a status code and message to reflect the outcome of the upload
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-download.html">download</a></li><li><a href="module-remove.html">remove</a></li><li><a href="module-upload.html">upload</a></li><li><a href="module-user.html">user</a></li></ul><h3>Classes</h3><ul><li><a href="module-download.download.html">download</a></li><li><a href="module-remove.remove.html">remove</a></li><li><a href="module-upload.upload.html">upload</a></li><li><a href="module-user.user.html">user</a></li></ul><h3>Global</h3><ul><li><a href="global.html#FileDownloadPage">File Download Page</a></li><li><a href="global.html#FileListPage">File List Page</a></li><li><a href="global.html#FileSharingPage">File Sharing Page</a></li><li><a href="global.html#HomePage">Home Page</a></li><li><a href="global.html#LogOutPage">Log Out Page</a></li><li><a href="global.html#LoginPage">Login Page</a></li><li><a href="global.html#LoginScript">Login Script</a></li><li><a href="global.html#RegisterPage">Register Page</a></li><li><a href="global.html#RegisterScript">Register Script</a></li><li><a href="global.html#UploadPage">Upload Page</a></li><li><a href="global.html#UploadScript">Upload Script</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Mon Nov 25 2019 17:25:00 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>