|
| 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. |
0 commit comments