summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/drm/drmUtils.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/components/drm/drmUtils.ts b/components/drm/drmUtils.ts
index 4ba63090..00cc83b2 100644
--- a/components/drm/drmUtils.ts
+++ b/components/drm/drmUtils.ts
@@ -4,6 +4,7 @@
* 2. 복호화 서버액션을 제공한다.
*
* decryptWithServerAction(file): 서버액션을 사용하여 복호화한 파일을 응답하는 함수
+ * isDRMFile(file): 파일이 DRM 암호화되어 있는지 검출하는 함수
*
*/
@@ -126,4 +127,63 @@ export async function decryptBufferWithServerAction(
return fileBuffer;
}
+}
+
+/**
+ * 파일이 DRM 암호화되어 있는지 검출하는 함수
+ * DRM 복호화 시도를 통해 DRM 여부를 판단합니다.
+ *
+ * @param file - 검출할 파일
+ * @returns DRM 파일이면 true, 일반 파일이면 false
+ */
+export async function isDRMFile(file: File): Promise<boolean> {
+ try {
+ const formData = new FormData();
+ formData.append('file', file);
+
+ const backendUrl = "http://localhost:6543/api/drm-proxy/decrypt";
+
+ console.log(`[DRM Check] 파일 DRM 검출 시도: ${file.name} (크기: ${file.size} bytes)`);
+
+ // DRM 복호화 시도
+ const response = await fetch(backendUrl, {
+ method: "POST",
+ body: formData,
+ });
+
+ // 응답이 성공적이면 DRM 파일로 판단
+ if (response.ok) {
+ const decryptedData = await response.arrayBuffer();
+
+ // 복호화된 데이터 크기가 원본과 다르거나, 복호화 성공 로그가 있으면 DRM 파일
+ const isDrmFile = decryptedData.byteLength !== file.size ||
+ decryptedData.byteLength > 0;
+
+ console.log(`[DRM Check] DRM 파일로 판정: ${file.name} (원본: ${file.size} bytes, 복호화: ${decryptedData.byteLength} bytes)`);
+
+ return isDrmFile;
+ } else {
+ // 응답이 실패하면 일반 파일로 판단
+ const errorText = await response.text().catch(() => '응답 텍스트를 가져올 수 없음');
+ console.log(`[DRM Check] 일반 파일로 판정: ${file.name} (응답 상태: ${response.status}, 오류: ${errorText})`);
+ return false;
+ }
+ } catch (error) {
+ // 네트워크 오류나 서버 연결 실패 시 일반 파일로 판단
+ const errorMessage = error instanceof Error
+ ? `${error.name}: ${error.message}`
+ : String(error);
+
+ console.log(`[DRM Check] 일반 파일로 판정 (오류 발생): ${file.name}`, {
+ error: errorMessage,
+ remark: `
+ [DRM 검출 실패 케이스]
+ 1. DRM 백엔드 서버가 없는 경우 - 일반 파일로 판정
+ 2. DRM 중앙 서버와 통신 불가한 경우 - 일반 파일로 판정
+ 3. 네트워크 오류 - 일반 파일로 판정
+ `
+ });
+
+ return false;
+ }
} \ No newline at end of file