Members
# async authenticate
This function checks if the password is correct
Example
auth('public/OSI-password.png', 'password', 'database/passwords.json');
# async buildSecureObject
This function builds an object with the path, the hash and the salt
Example
buildSecureObject('public/OSI-password.png', 'password');
# async changePassword
This function changes the password on a secure file
Example
changePassword('public/OSI-password.png', 'password', 'database/passwords.json');
# constant db
This constant is the path to the database
- Default Value:
- __dirname + '/../database/passwords.json'
Example
const db = __dirname + '/../database/passwords.json';
# async deleteSecureFile
This function deletes a secure file from the database
Example
deleteSecureFile('public/OSI-password.png', 'database/passwords.json');
# async newSecureFile
This function adds a new secure file to the database
Example
newSecureFile('public/OSI-password.png', 'password', false, 'database/passwords.json');
# async readJSON
Read JSON files
Example
const data = await readJSON<SecureObjects>("example.json");
# serveFile
This function serves a file from the database
Example
serveFile(fastify, 'public/OSI-password.png', true);
# async writeJSON
Write JSON files (Blanks them)
Example
await writeJSON("example.json", { hello: "world" });
Methods
# async authenticate(file, password, dbpopt)
This function checks if the password is correct
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file |
The path to the file | |||
password |
The password to check | |||
dbp |
<optional> |
db | The path to the database |
True if the password is correct, false otherwise
Example
auth('public/OSI-password.png', 'password', 'database/passwords.json');
# blacklisted(path)
This function checks if a file is blacklisted
Parameters:
| Name | Type | Description |
|---|---|---|
path |
The path to the file |
If the file is blacklisted
# async buildSecureObject(file, password)
This function builds an object with the path, the hash and the salt
Parameters:
| Name | Type | Description |
|---|---|---|
file |
The path to the file | |
password |
The password to hash |
The object with the path, the hash and the salt
Example
buildSecureObject('public/OSI-password.png', 'password');
# async changePassword(file, password, dbpopt) → {Promise.<void>}
This function changes the password on a secure file
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file |
The path to the file | |||
password |
The new password | |||
dbp |
<optional> |
db | The path to the database |
If the file doesn't exist
Error
Promise.<void>
Example
changePassword('public/OSI-password.png', 'password', 'database/passwords.json');
# async deleteSecureFile(file, dbpopt) → {Promise.<void>}
This function deletes a secure file from the database
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file |
The path to the file | |||
dbp |
<optional> |
db | The path to the database |
If the file doesn't exist
Error
Promise.<void>
Example
deleteSecureFile('public/OSI-password.png', 'database/passwords.json');
# async newSecureFile(file, password, dbpopt) → {Promise.<void>}
This function adds a new secure file to the database
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file |
The path to the file | |||
password |
The password to hash | |||
dbp |
<optional> |
db | The path to the database |
If the file already exists
Error
Promise.<void>
Example
newSecureFile('public/OSI-password.png', 'password', false, 'database/passwords.json');
# async readJSON(path) → {Promise.<T>}
Read JSON files
Parameters:
| Name | Type | Description |
|---|---|---|
path |
The path to the JSON file |
Promise.<T>
Example
const data = await readJSON<SecureObjects>("example.json");
# serveFile(fastifyInstance, path, securedopt) → {Promise.<void>}
This function serves a file from the database
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fastifyInstance |
The Fastify Instance | |||
path |
The path to the file | |||
secured |
<optional> |
false | If the file is secured |
Promise.<void>
Example
serveFile(fastify, 'public/OSI-password.png', true);
# async writeJSON(path, data) → {Promise.<void>}
Write JSON files (Blanks them)
Parameters:
| Name | Type | Description |
|---|---|---|
path |
The path to the JSON file | |
data |
The JSON object |
Promise.<void>
Example
await writeJSON("example.json", { hello: "world" });