RemoteFileService.java 2.73 KB
package com.bs.fileservice.feign;

import com.bs.common.core.domain.AjaxResult;
import com.bs.common.core.domain.FileEntity;
import com.bs.common.core.domain.model.ScreenshotRequest;
import com.bs.common.core.domain.model.ScreenshotResponse;
import com.bs.fileservice.feign.factory.RemoteFileServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 文件服务远程调用接口
 * <p>
 * 对应 bs-fileservice 的 FileController 对外接口。
 * 调用方使用方式:
 * <pre>
 * &#64;Resource
 * private RemoteFileService remoteFileService;
 * </pre>
 * 启动类需确保扫描到本包:&#64;EnableFeignClients(basePackages = "com.bs.**")
 *
 * @author system
 */
@FeignClient(
        name = "bs-fileservice",
        contextId = "remoteFileService",
        path = "/fileservice",
        fallbackFactory = RemoteFileServiceFallbackFactory.class
)
public interface RemoteFileService {

    /**
     * 文件上传
     *
     * @param file 文件
     * @return 上传结果,data 为文件信息
     */
    @PostMapping(value = "upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    AjaxResult<FileEntity> upload(@RequestPart("file") MultipartFile file);

    /**
     * 视频抽帧(获取视频第一帧图片)
     *
     * @param url 视频地址
     * @return 抽帧结果,data 包含 name/url/height/width/memorySize/pixelSize
     */
    @GetMapping("getVideoFirstImg")
    AjaxResult<Map<String, Object>> getVideoFirstImg(@RequestParam("url") String url);

    /**
     * 获取腾讯云/阿里云 OSS 上传参数
     *
     * @return 配置信息(加密后返回)
     */
    @GetMapping("/get/config")
    AjaxResult<Map<String, Object>> getCosConfig();

    /**
     * 获取 STS 临时授权凭证
     *
     * @return STS 凭证信息(加密后返回)
     */
    @GetMapping("/get/stsConfig")
    AjaxResult<Map<String, Object>> getCosStsConfig();

    /**
     * 网页截图
     *
     * @param request 截图请求
     * @return 截图结果
     */
    @PostMapping("/screenshot")
    AjaxResult<ScreenshotResponse> screenshot(@RequestBody ScreenshotRequest request);

    /**
     * 网页转 PDF
     *
     * @param request 请求
     * @return 转换结果
     */
    @PostMapping("/pdf")
    AjaxResult<ScreenshotResponse> pdf(@RequestBody ScreenshotRequest request);
}