|
|
|
@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.sztzjy.resource_center.annotation.AnonymousAccess;
|
|
|
|
|
import com.sztzjy.resource_center.config.Constant;
|
|
|
|
|
import com.sztzjy.resource_center.util.ResultEntity;
|
|
|
|
|
import com.sztzjy.resource_center.util.file.IFileUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
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.HttpClients;
|
|
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@ -33,6 +35,8 @@ import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
@ -46,7 +50,8 @@ import java.util.Optional;
|
|
|
|
|
@RestController
|
|
|
|
|
public class JupyterhubController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
IFileUtil iFileUtil;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("创建容器")
|
|
|
|
|
@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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|