Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/asset

Package Overview
Dependencies
Maintainers
1
Versions
310
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/asset

Modular library for storing and retrieving binary assets with additional support for image modification at runtime

  • 0.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

travetto: Asset

This module provides the framework for storing/retrieving assets. It also provides additional image functionality for on-the-fly resizing.

The asset module requires an AssetSource to provide functionality for reading and writing files. The AssetSource will need to be configured to be picked up by the AssetService

class AppConfig {
  @InjectableFactory()
  static getSource(): AssetSource {
    return new CustomAssetSource();
  }
}

After that, both AssetService and ImageService will rely upon the AssetSource to do their work. Below you can see an example of storing and retrieving a user's profile image.

Images

Storing of all assets uses the AssetService, but retrieval can either be from AssetService or ImageService depending on whether or not you want to perform image optimizations on retrieval. The ImageService users GraphicsMagick for image transformation. If the binary is not installed the framework will spin up a docker container to provide needed functionality.

@Injectable()
class UserProfileService {

  constructor(
    private asset: AssetService, 
    private image: ImageService,
    private model: ModelService
  ) {}

  async saveProfileImage(userId: string, image: Asset) {
    const path = await this.asset.store(image);
    const user = await this.model.getById(User, userId);
    user.profileImage = path;
    await this.model.update(User, user);
  }

  async getProfileImage(userId:string) {
    const user = await this.model.getById(userId);
    return await this.image.getImage(user.profileImage, { w: 100, h: 100 });
  }
}

Additionally, the ImageService currently supports the ability to resize an image on the fly, while auto orienting.

Keywords

FAQs

Package last updated on 01 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc