Skip to content

Commit ead8486

Browse files
committed
readme
1 parent 4572acd commit ead8486

File tree

2 files changed

+195
-3
lines changed

2 files changed

+195
-3
lines changed

README.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# TypeX
2+
3+
A TypeScript based Image/File uploading server. Fast and Elegant.
4+
5+
## Table of Contents
6+
7+
1. Prerequisites
8+
1. Node
9+
2. Common Databases
10+
2. Installation
11+
1. Get the Source
12+
2. Setting up configurations
13+
1. Upload Size
14+
2. Site Settings
15+
3. Administrator user
16+
4. Database configuration
17+
5. Session Secret
18+
6. Web server port
19+
3. Example Config
20+
4. Compiling Source
21+
5. Running Compiled Source
22+
23+
## Prerequisites
24+
25+
Dependencies needed for running TypeX
26+
27+
### Node & Typescript
28+
29+
Node.JS is what runs the show, and you will need it before anything else. Install it [here](https://nodejs.org)
30+
31+
Once Node is installed install Typescript by doing
32+
33+
```sh
34+
npm i typescript -g
35+
```
36+
37+
Verify your installation by running these commands
38+
39+
```sh
40+
tsc -v
41+
npm -v
42+
node -v
43+
```
44+
45+
They should all output something along the lines of
46+
47+
```sh
48+
-> tsc -v
49+
Version 3.8.3
50+
-> npm -v
51+
node 6.14.4
52+
-> node -v
53+
v13.13.0
54+
```
55+
56+
### Common Databases
57+
58+
* MariaDB
59+
* MySQL
60+
* PostgreSQL
61+
* CockroachDB
62+
* Microsoft SQL Server
63+
* MongoDB (Coming soon!)
64+
65+
(check out [this](https://github.com/typeorm/typeorm/blob/master/docs/connection-options.md) for all types, you will need to use a different ORM config later on, view [this](https://github.com/typeorm/typeorm/blob/master/docs/connection-options.md#common-connection-options) for every option, more on this on Database configuration setup step)
66+
67+
## Installation
68+
69+
Now that you have considered what prerequisites you would like, lets actually install this! This installation is based on Linux systems, yet will work on both MacOSX and Windows with their respective commands
70+
71+
### Get the Source & Install Dependencies
72+
73+
You can get the source from the releases
74+
75+
```sh
76+
wget <RELEASE TAR BALL>
77+
tar -xvf <REALASE>
78+
cd <REALASE>
79+
npm i
80+
```
81+
82+
### Configuration Options
83+
84+
Every single configuration option will be listed here
85+
86+
#### Upload
87+
88+
**Config Property:** `upload`
89+
90+
| Config Property | Type | Description / Expected Values |
91+
|---------------------|---------|--------------------------------------------------------------|
92+
| `upload.fileLength` | integer | how long the random id for a file should be |
93+
| `upload.tempDir` | string | temporary directory, files are stored here and then deleted. |
94+
| `upload.uploadDir` | string | upload directory (where all uploads are stored) |
95+
96+
#### Site Settings
97+
98+
**Config Property:** `site`
99+
100+
| Config Property | Type | Description / Expected Values |
101+
|-----------------|---------|--------------------------------------------------------|
102+
| `site.protocol` | integer | protocol (http or https) |
103+
| `site.domain` | string | domain of server (ex. `localhost:8080`, `example.com`) |
104+
105+
#### Administrator User
106+
107+
**Config Property:** `administrator`
108+
109+
| Config Property | Type | Description / Expected Values |
110+
|-------------------------------|--------|----------------------------------------------------------------------------------------------------------|
111+
| `administrator.password` | string | password of administrator user (NOT RECOMENDED to use administrator user, set this to a SECURE password) |
112+
| `administrator.authorization` | string | authorization token that could be used for uploading (NOT RECOMENDED, set this to a SECURE master token) |
113+
114+
#### Database Configuration
115+
116+
**Config Property:** `orm`
117+
118+
| Config Property | Type | Description / Expected Values |
119+
|-------------------|----------|------------------------------------------------------|
120+
| `orm.type` | string | `mariadb`, `mysql`, `postgres`, `cockroach`, `mssql` |
121+
| `orm.host` | string | `localhost` or different IP |
122+
| `orm.port` | integer | `5432` or different pot |
123+
| `orm.username` | string | username |
124+
| `orm.password` | string | password |
125+
| `orm.database` | string | database to use |
126+
| `orm.synchronize` | boolean | synchronize database to database, or not |
127+
| `orm.logging` | boolean | log all queries |
128+
| `orm.entities` | string[] | entity paths (should not be edited, and should be `["out/src/entities/**/*.js"]`) |
129+
130+
#### Session Secret
131+
132+
**Config Property:** `sessionSecret`
133+
134+
A Random string of characters (anything)
135+
136+
#### Port
137+
138+
**Config Property:** `port`
139+
140+
Port to run the webserver on
141+
142+
### Example Config
143+
144+
```json
145+
{
146+
"upload": {
147+
"fileLength": 6,
148+
"tempDir": "./temp",
149+
"uploadDir": "./uploads"
150+
},
151+
"site": {
152+
"protocol": "http",
153+
"domain": "localhost:8000"
154+
},
155+
"administrator": {
156+
"password": "1234",
157+
"authorization": "Administrator master"
158+
},
159+
"orm": {
160+
"type": "postgres",
161+
"host": "localhost",
162+
"port": 5432,
163+
"username": "postgres",
164+
"password": "password",
165+
"database": "typex",
166+
"synchronize": true,
167+
"logging": false,
168+
"entities": [
169+
"out/src/entities/**/*.js"
170+
]
171+
},
172+
"sessionSecret": "aoshfyujfnbyurkjh53748uyfhn",
173+
"port": 8000
174+
}
175+
```
176+
177+
### Compiling Typescript for running
178+
179+
Compile the Typescript code before running the code, or you can run it with `ts-node` which is not recommended. ***MAKE SURE YOU ARE IN THE PROJECT DIR!***
180+
181+
```sh
182+
tsc -p .
183+
```
184+
185+
### Running Compiled Source
186+
187+
Run the webserver by running
188+
189+
```sh
190+
node out/src
191+
```

src/controllers/APIController.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { createReadStream, createWriteStream, unlinkSync, existsSync, mkdirSync
88
import multer from 'multer'
99
import { getExtension } from 'mime';
1010
import { User } from '../entities/User';
11-
const upload = multer({ dest: 'temp/' });
11+
import { sep } from 'path';
12+
const upload = multer({ dest: config.upload.tempDir });
1213

1314
@Controller('api')
1415
export class APIController {
@@ -23,8 +24,8 @@ export class APIController {
2324
const id = randomId(5);
2425
const extension = getExtension(file.mimetype);
2526
const source = createReadStream(file.path);
26-
if (!existsSync('./uploads')) mkdirSync('./uploads');
27-
const destination = createWriteStream(`./uploads/${id}.${extension}`);
27+
if (!existsSync(config.upload.uploadDir)) mkdirSync(config.upload.uploadDir);
28+
const destination = createWriteStream(`${config.upload.uploadDir}${sep}${id}.${extension}`);
2829
source.pipe(destination, { end: false });
2930
source.on("end", function () {
3031
unlinkSync(file.path);

0 commit comments

Comments
 (0)