package com.example.PhotoGallery.Configs;

import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class StaticResourceConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:/srv/nas/PhotoGalleryImages/images/")
                .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));

        registry.addResourceHandler("/thumbnails/**")
                .addResourceLocations("file:/srv/nas/PhotoGalleryImages/thumbnails/")
                .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));

        registry.addResourceHandler("/photo/images/**")
                .addResourceLocations("file:/srv/nas/PhotoGalleryImages/images/")
                .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));

        registry.addResourceHandler("/photo/thumbnails/**")
                .addResourceLocations("file:/srv/nas/PhotoGalleryImages/thumbnails/")
                .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));
    }

}