1.0.1 • Published 1 year ago

@browser.style/asset-server v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Asset Server

A server for managing digital assets with automatic image processing, WebP conversion, and tag management.

Features

  • Organized Storage Structure: Assets are stored in a hierarchical directory structure based on SKU/ID
  • Image Processing: On-the-fly image resizing and WebP conversion
  • WebP Conversion: Automatic conversion to WebP format for better performance
  • Compression: Brotli compression for supported clients
  • Caching: Efficient caching system for resized images
  • Tagging System: Attach metadata tags to assets
  • API-Driven: RESTful API for all operations
  • Validation: Input validation for all endpoints

Technologies

  • Node.js: JavaScript runtime
  • Express: Web framework
  • Multer: File upload handling
  • Sharp: Image processing and WebP conversion
  • PM2: Process management and auto-restart
  • express-validator: Input validation

Installation

Prerequisites

  • Node.js 16+ (LTS recommended)
  • npm or yarn

Setup

  1. Clone the repository:

    git clone https://github.com/madsstoumann/asset-server.git
    cd asset-server
  2. Install dependencies:

    npm install
  3. Create environment file:

    cp .env.example .env
  4. Edit .env file with your configuration settings

Configuration

Configure your server through the .env file:

VariableDescriptionDefault
PORTServer port3000
NODE_ENVEnvironment (development or production)development
ALLOWED_ORIGINSCORS allowed origins (comma-separated)http://localhost:5500
ALLOWED_WIDTHSPermitted image resize widths75,200,400,800,1200,1600
ALLOWED_TAGSValid tags for assetsfront,back,inside,spine
ALLOWED_TYPESPermitted file typesimage/jpeg,image/png,image/gif,application/pdf
MAX_FILE_SIZEMaximum upload file size (MB)10
ENABLE_COMPRESSIONEnable Brotli compressiontrue
COMPRESSION_LEVELCompression level (0-11)11

API Endpoints

Asset Management

MethodEndpointDescription
GET/api/asset/:idGet asset by ID
POST/api/asset/:idUpload new asset(s)
GET/api/asset-list/:idList assets by folder ID
PUT/api/asset/:id/tagsUpdate asset tags
DELETE/api/asset/:idDelete asset

Configuration

MethodEndpointDescription
GET/api/config/clientGet client configuration

Query Parameters

Asset Retrieval

  • w or width: Resize image to specified width
  • h or height: Resize image to specified height
  • dpi: Set image DPI

Asset Deletion

  • filename: Specify file to delete

Usage Examples

Upload an Asset

curl -X POST http://localhost:3000/api/asset/12345 -F "assets=@/path/to/your/file.jpg"

Get an Asset

curl http://localhost:3000/api/asset/12345?w=200

List Assets in a Folder

curl http://localhost:3000/api/asset-list/12345

Update Asset Tags

curl -X PUT http://localhost:3000/api/asset/12345/tags -d '{"tags":["front","back"]}' -H "Content-Type: application/json"

Delete an Asset

curl -X DELETE http://localhost:3000/api/asset/12345?filename=file.jpg

Additional Features

Image Processing

  • Resize: Resize images on-the-fly to specified dimensions.
  • WebP Conversion: Convert images to WebP format for better performance.
  • DPI Setting: Set DPI for images.

Compression

  • Brotli Compression: Enable Brotli compression for supported clients to reduce file size.

Caching

  • Efficient Caching: Cache resized images to improve performance on subsequent requests.

Tagging System

  • Metadata Tags: Attach metadata tags to assets for better organization and retrieval.

Validation

  • Input Validation: Validate input for all endpoints to ensure data integrity.

License

This project is licensed under the ISC License.