mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:49:19 +08:00
feat: 添加浏览器扩展下载功能
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.extension.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.extension.service.ExtensionPackageService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 管理端:浏览器扩展安装包下载(JWT,暂挂密钥查看权限)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/sys/open-extension")
|
||||
@RequiredArgsConstructor
|
||||
public class ExtensionPackageController {
|
||||
|
||||
private final ExtensionPackageService extensionPackageService;
|
||||
|
||||
@GetMapping("/download")
|
||||
@RequirePermission(value = "open:api-key:read", description = "下载浏览器扩展", allowSuper = true)
|
||||
public ResponseEntity<Resource> download() throws IOException {
|
||||
Resource resource = extensionPackageService.getPackageResource();
|
||||
ResponseEntity.BodyBuilder builder = ResponseEntity.ok()
|
||||
.header(
|
||||
HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" + ExtensionPackageService.PACKAGE_FILE_NAME + "\"")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
long length = resource.contentLength();
|
||||
if (length >= 0) {
|
||||
builder.contentLength(length);
|
||||
}
|
||||
return builder.body(resource);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.extension.service;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* 浏览器扩展安装包(zip)读取。
|
||||
*/
|
||||
public interface ExtensionPackageService {
|
||||
|
||||
String PACKAGE_FILE_NAME = "ecbi-data-sync-extension.zip";
|
||||
|
||||
/** 解析可下载的扩展 zip;不存在时抛业务异常。 */
|
||||
Resource getPackageResource();
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.extension.service.impl;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.extension.service.ExtensionPackageService;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 读取扩展 zip;优先 ./static/extension/(部署挂载),否则 classpath。
|
||||
*/
|
||||
@Service
|
||||
public class ExtensionPackageServiceImpl implements ExtensionPackageService {
|
||||
|
||||
private static final String PACKAGE_REL = "extension/" + PACKAGE_FILE_NAME;
|
||||
|
||||
@Override
|
||||
public Resource getPackageResource() {
|
||||
Resource resource = resolvePackageResource();
|
||||
if (!resource.exists()) {
|
||||
throw new BusinessException(
|
||||
"浏览器扩展安装包不存在,请先在 browser-extension 执行 pnpm build");
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
private Resource resolvePackageResource() {
|
||||
FileSystemResource mounted = new FileSystemResource(Paths.get("static", PACKAGE_REL));
|
||||
if (mounted.exists()) {
|
||||
return mounted;
|
||||
}
|
||||
return new ClassPathResource("static/" + PACKAGE_REL);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"updatedAt": "2026-08-27T06:21:25.418Z",
|
||||
"updatedAt": "2026-08-30T15:28:14.671Z",
|
||||
"features": [
|
||||
{
|
||||
"id": "pdd-ad-fee",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
# 扩展安装包由 browser-extension `pnpm build` 生成,勿手改
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user