Git Product home page Git Product logo

upload-attachment-service's Introduction

Upload Attachment Service - Coding challenge.

This repository serves as a challenge on how to create an effective upload attachment service.

Using this repository

Prerequisites:

node: 18.18.*
docker

Install and run:

npm install # Before running any other commands install the dependencies
npm run start-services # Starts the containers: s3 and sftp containers
npm run test # To run the test suite
npm run stop-services # Stops the running containers

Task

For a given tenant Implement an AttachmentService that uploads an attachment to storage given a tenants configuration file. The code should be typed.

Attachment Flow:

  1. Each file should be optimised.
  2. Each file must have a thumbnail generated and stored on storage.
  3. Each file must be uploaded to the tenant's chosen storage method.

Storage methods:

  • Tenant A: LocalDisk
    • storage/ directory is relative to the project root
  • Tenant B: S3
    • Running inside a mock server inside the docker container
  • Tenant C: SFTP
    • Running inside a mock server inside the docker container

Suggested Workflow:

Run the test suite npm run test to see if the solution is working. Tests are skipped in test/upload-to-storage.spec.ts except for the first one. Work from there and implement each case, testing and verifying on your way. Only the createAttachmentService() function should be changed in the test file.

Start with images upload first, then optimize and after thumbnail generation. Lastly videos uploads, they are more difficult and can be skipped.

There is a src/tenant-config.ts that controls where the file needs to be uploaded and the configuration for the given storage method (this file should not be changed but the types can be used in your files). The connection parameters for s3 and sftp are in this file for tenantB and tenantC.

You can create new files in src/ as needed. Inside src/AttachmentService.ts the upload() method's signature cannot be changed. You can add private methods, constructor, fields to the AttachmentService class as you need.

Work Flow:

  1. First for tenantA implement the local file upload.
    • Files should be saved in the storage/ direction
    • You probably need to create this directory in code if it doesn't exist
  2. Then for the second test: Optimise the image.
  3. For the third test: Generate the image thumbnail.
  4. Then implement the uploads for S3 and SFTP uploads.
  5. Implement different image types, if not done already.
  6. Implement video upload, optimisation and thumbnail generation.

You can use the packages included in the package.json:

  • @aws-sdk/client-s3: for connecting and uploading to s3
  • sharp: for optimizing images
  • ssh2-sftp-client: for connecting and uploading to sftp
  • fluent-ffmpeg: for videos
What this will hopefully teach you:
  • How to swap implementations based on configuration.
  • How to separate your code efficiently and easily modified it.
  • How to easily test code and without integration with real services.
Hints:
  • Dependency Injection
  • Inversion of control (Dependency Inversion)
  • Strategy Pattern
  • Factories

upload-attachment-service's People

Stargazers

 avatar

Watchers

Rick Lancee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.