package com.lesingle.edu.common.config;

import com.lesingle.edu.common.util.OssUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * OSS Bucket CORS 初始化
 * <p>
 * 应用启动时自动配置 OSS 跨域规则，解决前端直传跨域问题。
 * 需在配置中开启：aliyun.oss.cors-enabled=true
 * </p>
 */
@Slf4j
@Component
@Order(100) // 较晚执行，确保其他组件已就绪
@RequiredArgsConstructor
public class OssCorsInitRunner implements ApplicationRunner {

    private final OssUtils ossUtils;

    @Override
    public void run(ApplicationArguments args) {
        ossUtils.configureBucketCors();
    }
}
