Skip to content

Commit d7d8558

Browse files
committed
uploaded to github
0 parents  commit d7d8558

37 files changed

+8775
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"prettier"
11+
],
12+
"parserOptions": {
13+
"sourceType": "module",
14+
"ecmaVersion": 2020
15+
},
16+
"parser": "@typescript-eslint/parser",
17+
"plugins": ["@typescript-eslint"],
18+
"rules": {
19+
"@typescript-eslint/no-inferrable-types": [0],
20+
"valid-jsdoc": "off",
21+
"semi": [2, "always"],
22+
"keyword-spacing": ["error", { "after": true }],
23+
"comma-spacing": ["error", { "before": false, "after": true }],
24+
"space-infix-ops": ["error", { "int32Hint": false }],
25+
"eqeqeq": [2, "smart"],
26+
"space-before-blocks": "error",
27+
"space-before-function-paren": [
28+
"error",
29+
{
30+
"anonymous": "always",
31+
"named": "never",
32+
"asyncArrow": "always"
33+
}
34+
],
35+
"no-extra-boolean-cast": "off"
36+
}
37+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"tabWidth": 2,
4+
"trailingComma": "none",
5+
"singleQuote": true,
6+
"printWidth": 80,
7+
"bracketSpacing": true,
8+
"arrowParens": "avoid"
9+
}

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
### Scripts to setup and test the project
2+
3+
- **You can use Setup to quickly setup and start the project:** `npm run setup`
4+
- **Install:** `npm install`
5+
- **Build:** `npm run build`
6+
- **Lint:** `npm run lint`
7+
- **Prettify:** `npm run prettify`
8+
- **Run jasmine tests:** `npm run test`
9+
- **Start server:** `npm run start`
10+
11+
### Usage
12+
13+
The server runs on localhost:3000
14+
15+
#### Access the Web App
16+
17+
Open: [http://localhost:3000/](http://localhost:3000/)
18+
19+
#### Resize Images Endpoint
20+
21+
Endpoint URL: [http://localhost:3000/api/images](http://localhost:3000/api/images)
22+
23+
**Query Parameters:**
24+
25+
- **filename**: Name of the image file
26+
- **width**: Desired width in pixels (must be a positive number)
27+
- **height**: Desired height in pixels (must be a positive number)
28+
29+
**Examples:**
30+
31+
1. **List available image names:**
32+
33+
```
34+
http://localhost:3000/api/images
35+
```
36+
37+
Displays a list of available image names.
38+
39+
2. **Display original image:**
40+
41+
```
42+
http://localhost:3000/api/images?filename=fjord
43+
```
44+
45+
Displays the original `fjord` image.
46+
47+
3. **Resize image:**
48+
49+
```
50+
http://localhost:3000/api/images?filename=fjord&width=200&height=200
51+
```
52+
53+
Resizes the `fjord` image to 200x200 pixels and stores the resulting image. Subsequent calls will serve the resized image from cache.
54+
55+
4. **Invalid width parameter:**
56+
57+
```
58+
http://localhost:3000/api/images?filename=fjord&width=-200&height=200
59+
```
60+
61+
Displays a hint indicating the invalid width parameter.
62+
63+
5. **Missing height parameter:**
64+
```
65+
http://localhost:3000/api/images?filename=fjord&width=200
66+
```
67+
Displays a tip indicating the missing height parameter.
68+
69+
---
70+
71+
## Project Structure
72+
73+
This project follows a structured organization to make it easier to read and understand and develop future code into it:
74+
75+
```
76+
image-processing-api-deci/
77+
├── assets/
78+
│ └── images/
79+
│ ├── full/
80+
│ └── thumb/
81+
├── dist/
82+
├── frontend/
83+
│ ├── app.js
84+
│ ├── index.html
85+
│ └── styles.css
86+
├── node_modules/
87+
├── source/
88+
│ ├── controllers/
89+
│ │ ├── api/
90+
│ │ │ ├── processing.ts
91+
│ │ │ └── upload.ts
92+
│ │ └── router.ts
93+
│ ├── tests/
94+
│ │ ├── helpers/
95+
│ │ │ └── reporter.ts
96+
│ │ ├── fileSpec.ts
97+
│ │ └── indexSpec.ts
98+
│ ├── image-functions.ts
99+
│ ├── index.ts
100+
│ └── resize.ts
101+
├── spec/
102+
├── .eslintignore
103+
├── .eslintrc.json
104+
├── .gitignore
105+
├── .prettierrc.json
106+
├── package-lock.json
107+
├── package.json
108+
├── README.md
109+
└── tsconfig.json
110+
```
111+
112+
- `assets/`: Contains image assets used in the application, organized into `full` and `thumb` directories for full-sized and thumbnail images respectively.
113+
- `dist/`: Directory for distribution files.
114+
- `frontend/`: Holds the static front-end files including JavaScript, HTML, and CSS.
115+
- `source/`: Contains the core application logic:
116+
- `controllers/`: Manages API routes and processing.
117+
- `tests/`: Includes unit tests and helper files for testing.
118+
- `image-functions.ts`: Functions related to image processing.
119+
- `index.ts` and `resize.ts`: Main application logic and image resizing functionality.
120+
- `spec/`: configuration files for Jasmine and UNIT Testing.
121+
- `.eslintignore`, `.eslintrc.json`, `.prettierrc.json`: Configuration files for code linting and formatting.
122+
- `package.json`, `package-lock.json`: Dependencies and project configuration.
123+
- `tsconfig.json`: TypeScript configuration file.
124+
125+
This structure helps keep the project modular and organized, making it easier to navigate and maintain.
126+
127+
---
128+
129+
### Notes
130+
131+
- Images are served from `assets/images/full`. Additional images can be placed in this directory, trying to add any file other than .jpg will result into an error and wont get uploaded.
132+
- Resized images are stored in `assets/images/thumb`. Deleting images from this directory will cause them to be re-created on subsequent requests to the same endpoint.
133+
- In the web app, The Filename box in the resize section is Case-sensitive, adding a space or a capital letter will result in an error.

assets/images/full/Picture2.jpg

88 KB
Loading
2.11 MB
Loading

assets/images/full/fjord.jpg

2.31 MB
Loading
1.69 MB
Loading

assets/images/full/palmtunnel.jpg

2.17 MB
Loading

0 commit comments

Comments
 (0)