๐Ÿ“Œ ์ปจํ…์ธ  ๋“ฑ๋ก ๋ฐ ์ˆ˜์ • ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ

๐Ÿ“ ๊ฐœ์š”

์ปจํ…์ธ ๋ฅผ ๋“ฑ๋กํ•˜๊ณ  ์ˆ˜์ •ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋ฉด์„œ, JS ๋ฐ SH ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ์ƒ์„ฑ ๋ฐ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค.

๊ธฐ์กด์—๋Š” ์ปจํ…์ธ  ํ…Œ์ด๋ธ”์—์„œ server_host์™€ server_port ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•ด๋„ ํ•ด๋‹น ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ๋ฐ˜์˜๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์œผ๋‚˜, ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ SH ๋ฐ JS ํŒŒ์ผ์ด ํ•จ๊ป˜ ์ˆ˜์ •๋˜๋„๋ก ๊ตฌํ˜„ํ–ˆ๋‹ค.


๐Ÿš€ ๊ตฌํ˜„ ๋‚ด์šฉ

๐Ÿ”น 1. ์ปจํ…์ธ  ๋“ฑ๋ก (POST /content)

์ปจํ…์ธ ๋ฅผ ์‹ ๊ทœ ๋“ฑ๋กํ•  ๋•Œ, ์ค‘๋ณต ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ณ  SH ๋ฐ JS ํŒŒ์ผ์„ ํ•จ๊ป˜ ์ƒ์„ฑํ•˜๋„๋ก ํ–ˆ๋‹ค.

โœ… ์ฃผ์š” ์ฒ˜๋ฆฌ ๊ณผ์ •

  1. ์ค‘๋ณต ๊ฒ€์‚ฌ: ๊ฐ™์€ ์ด๋ฆ„์˜ ์ปจํ…์ธ ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
  2. JSON ๋ฐ์ดํ„ฐ ์ƒ์„ฑ: server_host, server_port ๋“ฑ ํ•„์ˆ˜ ์ •๋ณด๋ฅผ JSON ๊ฐ์ฒด๋กœ ์ €์žฅ
  3. ์ปจํ…์ธ  ์ €์žฅ: DB์— ์ €์žฅ ํ›„ UID๋ฅผ ๋ถ€์—ฌ
  4. ๋ฒ„์ „ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ: Android ๋ฐ iOS์šฉ ๋ฒ„์ „ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€
  5. SH ๋ฐ JS ํŒŒ์ผ ์ƒ์„ฑ:

โœ… ์ปจํ…์ธ  ๋“ฑ๋ก API ์ฝ”๋“œ

@PostMapping("content")
public ResponseEntity<GResponse> createContents(HttpServletResponse response, @RequestBody ContentParam param) {
    response.setHeader("Job-Log", "์ปจํ…์ธ  ์ •๋ณด ๋“ฑ๋ก");

    // ์ค‘๋ณต ๊ฒ€์‚ฌ
    ContentEntity content = contentRepo.findByName(param.getName());
    if (content != null) {
        return ResponseEntity.ok(new GResponse("400", "์ด๋ฏธ ์กด์žฌํ•˜๋Š” ์ปจํ…์ธ ๋ช…"));
    }

    // JSON ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
    JSONObject info = new JSONObject();
    info.put("server_host", param.getServerHost());
    info.put("server_port", param.getServerPort().isEmpty() ? ":443" : param.getServerPort());

    JSONObject define = new JSONObject();
    define.put("server_host", param.getServerHost());
    define.put("server_port", param.getServerPort().isEmpty() ? ":443" : param.getServerPort());

    // ์ปจํ…์ธ  ์ €์žฅ
    content = new ContentEntity();
    content.setCreator(userHelper.getCurrentUserID());
    content.setInfo(info.toString());
    content.setDefine(define.toString());
    content = contentRepo.save(content);

    // SH ๋ฐ JS ํŒŒ์ผ ์ƒ์„ฑ
    fileService.createOrUpdateJsFile(param.getName(), param.getProductName(), define);
    fileService.createShFile(param.getName(), param.getProductName(), param.getServerHost(), param.getServerPort(), content);

    return ResponseEntity.ok(new GResponse("0000", "๋“ฑ๋ก ์™„๋ฃŒ"));
}


๐Ÿ”น 2. ์ปจํ…์ธ  ์ˆ˜์ • (PATCH /content)

์ปจํ…์ธ ๋ฅผ ์ˆ˜์ •ํ•  ๋•Œ, ๊ธฐ์กด server_host์™€ server_port ์ •๋ณด๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ฉฐ, ํ•ด๋‹น ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด JS ๋ฐ SH ํŒŒ์ผ์—๋„ ๋ฐ˜์˜๋˜๋„๋ก ํ–ˆ๋‹ค.

โœ… ์ฃผ์š” ์ฒ˜๋ฆฌ ๊ณผ์ •