start some documentation work

This commit is contained in:
waveringana 2023-08-25 20:03:30 -04:00
parent a42eeeda90
commit 1e23bd879b
8 changed files with 8857 additions and 11052 deletions

103
documentation/database.md Normal file
View file

@ -0,0 +1,103 @@
# Database Documentation for Embedder
Embedder utilizes **SQLite3** to manage its user system and store metadata for uploaded files.
---
## Databases:
### `media.db`
- **Description**: Manages the user system and image metadata.
### `session.db`
- **Description**: Handles login session data to keep users logged in over time.
---
## Tables:
### Media Table
#### TypeScript Interface: `MediaRow`
- **Description**: Represents a row in the media table.
- **Fields**:
- `id`: Optional number or string
- `path`: String
- `expire`: Date object
- `username`: Optional string
#### SQL Structure
- `id`: INTEGER
- `path`: TEXT
- `expire`: INTEGER
- `username`: TEXT
---
### User Table
#### TypeScript Interface: `UserRow`
- **Description**: Represents a row in the user table.
- **Fields**:
- `id`: Optional number
- `username`: String
- `hashed_password`: Any
- `salt`: Any
#### SQL Structure
- `id`: INTEGER
- `username`: TEXT
- `hashed_password`: BLOB
- `expire`: INTEGER
- `salt`: BLOB
---
## Database Interactions (`lib/db.ts`)
### `createDatabase(version: number)`
- **Description**: Initializes the database schema.
- **Parameters**:
- `version`: Number indicating the version of the database schema.
### `createUser(username: string, password: string)`
- **Description**: Inserts a new user record into the user table.
- **Parameters**:
- `username`: String representing the user's name.
- `password`: String representing the user's password.
### `insertToDB(filename: string, expireDate: Date, username: string)`
- **Description**: Adds a new media record into the media table.
- **Parameters**:
- `filename`: String representing the filename of the uploaded media.
- `expireDate`: Date object indicating when the media should expire.
- `username`: String representing the user's name.
### `getPath(id: number | string)`
- **Description**: Retrieves the path for a specific file using its ID.
- **Parameters**:
- `id`: Number or string representing the file's ID.
### `deleteId(database: string, id: number | string)`
- **Description**: Removes a record from the database.
- **Parameters**:
- `database`: String representing the name of the database.
- `id`: Number or string representing the ID of the record to be removed.
### `expire(database: string, column: string, expiration: number)`
- **Description**: Sets an expiration date for a particular database row.
- **Parameters**:
- `database`: String representing the name of the database.
- `column`: String representing the name of the column in which the date should be set.
- `expiration`: Number representing the Unix timestamp when the record should expire.

View file

@ -0,0 +1,60 @@
# Express Middleware Documentation for Embedder
Embedder employs a series of middleware functions to facilitate operations such as user authentication, media conversions, and handling uploaded files.
## Middleware Functions
---
### `checkAuth()`
- **Description**: Ensures the user is authenticated.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function
---
### `checkSharexAuth()`
- **Description**: Validates the ShareX authentication key provided in the headers.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function
---
### `createEmbedData()`
- **Description**: Generates oEmbed metadata for embeds and saves them as JSON files.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function
---
### `convert()`
- **Description**: Converts media files between video and GIF formats using ffmpeg.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function
---
### `convertTo720p()`
- **Description**: Converts the uploaded video to a 720p resolution to reduce file size.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function
---
### `handleUpload()`
- **Description**: Manages the uploaded files and records their metadata into the database.
- **Parameters**:
- `req`: Express request object
- `res`: Express response object
- `next`: Callback to the next middleware function

BIN
documentation/readmegif.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

30
documentation/routing.md Normal file
View file

@ -0,0 +1,30 @@
# Routing
Embedder utilizes **Express** for routing and serving the app. Templating is currently with **EJS**, but there's a potential future migration to **React**. **Passport** is employed for authentication.
## Routes:
- **/** ([index.ts](../app/routes/index.ts))
- `GET`:
- Unauthenticated: Serve `home.ejs`
- Authenticated: Serve `index.ejs`
- `POST`: Redirect to `/`
- **/login** ([auth.ts](../app/routes/auth.ts))
- `GET`: Serve `login.ejs`
- `POST` to `/login/password`:
- Success: Redirect to `/`
- Failure: Redirect to `/login`
- **/logout** ([auth.ts](../app/routes/auth.ts))
- `POST`: Redirect to `/`
- **/gifv** ([index.ts](../app/routes/index.ts))
- `GET`: Serve `gifv.ejs`
- `POST` to `/adduser`: Redirect to `/`
- **/adduser** ([adduser.ts](../app/routes/adduser.ts))
- `GET`: Serve `adduser.ejs`
- **/sharex** ([index.ts](../app/routes/index.ts))
- `POST`: Response is text containing path to uploaded file