package com.example.sjkbf.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.resource.EncodedResourceResolver;

import java.util.concurrent.TimeUnit;

@Configuration
public class VideoConfig implements WebMvcConfigurer {

    /**
     * 配置视频文件缓存策略
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 1. 转码视频资源映射（/tmp/video-transcoded/）
        registry.addResourceHandler("/transcoded/**")
                .addResourceLocations("file:/tmp/video-transcoded/")
                .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS))
                .resourceChain(true)
                .addResolver(new EncodedResourceResolver());

        // 2. 原始视频资源映射（/root/rindro/Script/Project/）
        registry.addResourceHandler("/original/**")
                .addResourceLocations("file:/root/rindro/Script/Project/")
                .setCacheControl(CacheControl.noCache())
                .resourceChain(false);
    }
}