package com.ruoyi.platform.service.impl;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.service.DvcService;
import com.ruoyi.platform.utils.DVCUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DvcServiceImpl implements DvcService {
    @Value("${minio.accessKey}")
    String accessKeyId;
    @Value("${minio.secretKey}")
    String secretAccessKey;
    @Value("${minio.endpoint}")
    String endpoint;
    @Resource
    private DVCUtils dvcUtils;
    @Override
    public void initaddpushDvc(String localPath) throws Exception {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // dvc init 初始化
        dvcUtils.dvcInit(localPath);
        // 配置远程S3地址
        dvcUtils.dvcRemoteAdd(localPath,"");
//        dvcUtils.dvcConfigS3Credentials(localPath,endpoint, accessKeyId, secretAccessKey);
        // dvc 跟踪
        dvcUtils.dvcAdd(localPath , "data");
        // git commit
        dvcUtils.gitCommit(localPath, "commit from ci4s with "+loginUser.getUsername());
        // dvc push 到远程S3
        dvcUtils.dvcPush(localPath);
    }

}
