文件更新

master
whb 8 months ago
parent 80d8f7d758
commit 94f70fa56e

@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.annotation.AnonymousAccess;
import com.sztzjy.resource_center.config.Constant; import com.sztzjy.resource_center.config.Constant;
import com.sztzjy.resource_center.util.ResultEntity; import com.sztzjy.resource_center.util.ResultEntity;
import com.sztzjy.resource_center.util.file.IFileUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -24,6 +25,7 @@ import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -33,6 +35,8 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -46,7 +50,8 @@ import java.util.Optional;
@RestController @RestController
public class JupyterhubController { public class JupyterhubController {
@Autowired
IFileUtil iFileUtil;
@ApiOperation("创建容器") @ApiOperation("创建容器")
@GetMapping("/jumpJupyerHub") @GetMapping("/jumpJupyerHub")
@ -236,6 +241,50 @@ public class JupyterhubController {
} }
@ApiOperation("ipynb文件重命名")
@GetMapping("/uploadIpynbByName")
@AnonymousAccess
public ResultEntity uploadIpynbByName(@ApiParam("参数为:案例名") String caseName,String newName) throws IOException {
// 对参数进行 URL 编码
String encodedCaseName = URLEncoder.encode(caseName, StandardCharsets.UTF_8.toString());
String encodedNewName = URLEncoder.encode(newName, StandardCharsets.UTF_8.toString());
String url = "https://jrdsj.sztzjy.com:598/api/jupyterhub/uploadFileByIpynbName?caseName=" + encodedCaseName+ "&newName="+encodedNewName ;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(url);
// 执行 GET 请求
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.toString(responseEntity);
// 解析 JSON 响应
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonResponse = objectMapper.readTree(responseString);
// 假设返回的 JSON 对象包含 "data" 字段
JsonNode dataNode = jsonResponse.get("data");
//html也需要重命名
String htmlOldIpynb = "/usr/local/tianzeProject/jupyter/md/html/" + caseName + ".html";
String htmlNewIpynb = "/usr/local/tianzeProject/jupyter/md/html/" + newName + ".html";
// 创建 File 对象
File oldFile = new File(htmlOldIpynb);
File newFile = new File(htmlNewIpynb);
// 重命名文件或目录
boolean success = oldFile.renameTo(newFile);
return new ResultEntity<>(HttpStatus.OK,dataNode != null && dataNode.asBoolean());
}
}
}

@ -381,17 +381,18 @@ public class StuJupyterController {
//文件查询 ,判断有无文件 //文件查询 ,判断有无文件
@ApiOperation("Html文件上传") @ApiOperation("html文件上传")
@PostMapping("/importHtml") @PostMapping("/importHtml")
@AnonymousAccess @AnonymousAccess
public ResultEntity importHtml(@ApiParam("案例名") String caseName,@RequestPart MultipartFile file) { public ResultEntity importHtml(@ApiParam("案例名") String caseName,@RequestPart MultipartFile file) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
int i = originalFilename.lastIndexOf("."); int i = originalFilename.lastIndexOf(".");
String substring = originalFilename.substring(i); String substring = originalFilename.substring(i+1);
if ("html".equals(substring)) { if ("html".equals(substring)) {
String htmlPath = "/usr/local/tianzeProject/jupyter/md/html"; String htmlPath = "/usr/local/tianzeProject/jupyter/md/html";
//String htmlPath = "D:\\home\\";
String upload = localFileUtil.uploadByRelativePath(file, htmlPath,caseName); String upload = localFileUtil.uploadByRelativePath(file, htmlPath,caseName);

Loading…
Cancel
Save