PageSourceSearch

https://ksolarcoops.org/assets/controllers/base/async_download_controller-db94a268.js

js ksolarcoops.org collected 2026-10-06 14:04:22 UTC 1,507 bytes, 43 lines download raw bytes

1import { Controller } from '@hotwired/stimulus';
2
3// 이 컨트롤러는 다운로드 링크를 클릭할 때 서버에 HEAD 요청을 보내고,
4// 서버가 202 응답을 보내면 잠시 후에 다시 요청을 시도하라고 알립니다.
5// 서버가 200 응답을 보내면 다운로드를 시작합니다.
6/**
7 * @domain 도메인 워크플로우
8 * @concern 다운로드 준비 상태 확인 후 파일 다운로드 트리거
9 * @description 다운로드 링크 클릭 시 서버에 HEAD 요청을 보내 200이면 즉시 다운로드를 트리거하고, 202면 준비 중 안내를, 오류면 에러 메시지를 알림으로 표시하는 컨트롤러
10 */
11export default class extends Controller {
12  static values = {
13    url: String,
14  };
15
16  async download(event) {
17    event.preventDefault();
18
19    try {
20      const response = await fetch(this.urlValue, { method: 'HEAD' });
21
22      if (response.status === 200) {
23        this.triggerDownload();
24      } else if (response.status === 202) {
25        alert('이미지를 준비 중입니다. 잠시 후 다시 시도해주세요.');
26      } else {
27        alert('다운로드 중 오류가 발생했습니다.');
28      }
29    } catch (error) {
30      alert('서버 요청 중 문제가 발생했습니다.');
31      console.error(error);
32    }
33  }
34
35  triggerDownload() {
36    const link = document.createElement('a');
37    link.href = this.urlValue;
38    link.download = '';
39    document.body.appendChild(link);
40    link.click();
41    link.remove();
42  }
43}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.