package cn.reghao.oss.store.rpc;

import cn.reghao.oss.api.dto.ObjectChannel;
import cn.reghao.oss.store.config.OssProperties;
import cn.reghao.oss.store.util.JwtUtil;
import cn.reghao.oss.api.constant.ChannelAction;
import cn.reghao.oss.api.dto.OssPayload;
import cn.reghao.oss.api.iface.OssServerService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

/**
 * @author reghao
 * @date 2023-08-01 14:54:23
 */
@DubboService
@Service
public class OssServerServiceImpl implements OssServerService {
    private final OssProperties ossProperties;

    public OssServerServiceImpl(OssProperties ossProperties) {
        this.ossProperties = ossProperties;
    }

    @Override
    public String getUploadToken(int channelId) {
        long userId = 1;
        String action = ChannelAction.upload.getName();
        long expireAt = System.currentTimeMillis() + 3600*1000;
        OssPayload ossPayload = new OssPayload(action, channelId, userId);
        return JwtUtil.createToken(ossPayload, expireAt, ossProperties.getSecretKey());
    }

    @Override
    public void createChannel(long userId, ObjectChannel channel) {
    }
}
