import type { JWT, OAuth2Client } from 'google-auth-library'; import type { DriveAuthSource } from '../auth/drive-auth.js'; /** * Google Drive v3 래퍼 — 파일·폴더 조회, 업로드, 내용 갱신, 이름 변경·이동, 휴지통. * * 모든 호출에 supportsAllDrives 를 싣는다. 서비스 계정은 자기 저장 공간이 없어서 실제로는 * 공유 드라이브 안에서 일하는 경우가 대부분인데, 이 플래그가 빠지면 공유 드라이브 파일이 * "없는 파일"(404)로 보인다. */ export type DriveClient = OAuth2Client | JWT; export declare const FOLDER_MIME = "application/vnd.google-apps.folder"; /** * Drive 파일·폴더 ID. 영숫자·밑줄·하이픈만 허용한다 — 이 값은 files.list 의 q 문자열 안에 * 그대로 들어가므로, 따옴표가 섞이면 질의가 다른 뜻이 된다. 'root' 는 내 드라이브 최상위 별칭. */ export declare const DRIVE_ID_RE: RegExp; /** files.list q 문자열 리터럴 이스케이프 (\ 와 ' ). */ export declare function escapeQueryValue(value: string): string; export interface DriveFile { id: string; name: string; mimeType: string; isFolder: boolean; size: number | null; md5Checksum: string | null; createdTime: string | null; modifiedTime: string | null; parents: string[]; driveId: string | null; trashed: boolean; webViewLink: string | null; description: string | null; } /** * Drive 에러를 "무엇을 고칠지"가 보이는 메시지로. 서비스 계정과 OAuth(drive.file) 는 * 같은 404 라도 원인이 달라 안내를 나눈다. */ export declare function driveError(e: unknown, source?: DriveAuthSource, clientEmail?: string | null): Error; export interface ListFilesInput { folderId?: string; nameContains?: string; mimeType?: string; includeTrashed?: boolean; pageSize?: number; pageToken?: string; } /** files.list 의 q 문자열 조립 (테스트가 이스케이프를 고정한다). */ export declare function buildListQuery(input: ListFilesInput): string; export declare function listFiles(auth: DriveClient, input: ListFilesInput): Promise<{ files: DriveFile[]; nextPageToken: string | null; }>; export declare function getFile(auth: DriveClient, fileId: string): Promise; export interface CreateFolderInput { name: string; parentId?: string; /** 같은 이름의 폴더가 부모 안에 이미 있으면 새로 만들지 않고 그것을 돌려준다 (기본 true). */ reuseExisting?: boolean; } export declare function createFolder(auth: DriveClient, input: CreateFolderInput): Promise<{ status: "exists"; folder: DriveFile; } | { status: "created"; folder: DriveFile; }>; /** 확장자 → MIME. 모르면 application/octet-stream (Drive 가 Google 문서로 변환하지 않는다). */ export declare function guessMimeType(filePath: string): string; export interface LocalFile { path: string; size: number; mimeType: string; } /** 업로드할 로컬 파일 점검 — 절대 경로, 일반 파일, 비어 있지 않음. */ export declare function inspectLocalFile(filePath: string, mimeType?: string): LocalFile; /** 로컬 파일 MD5 — 업로드 결과의 md5Checksum 과 비교해 전송 무결성을 확인한다. */ export declare function md5OfFile(filePath: string): Promise; export interface UploadFileInput { filePath: string; parentId?: string; name?: string; mimeType?: string; /** 같은 폴더에 같은 이름이 있을 때: error(기본) — 덮어쓰기 대신 drive_update_file_content 를 안내, create_new — 하나 더 만든다. */ onConflict?: 'error' | 'create_new'; } export declare function uploadFile(auth: DriveClient, input: UploadFileInput): Promise<{ status: "uploaded"; file: DriveFile; local: LocalFile; verified: boolean | null; }>; export interface UpdateContentInput { fileId: string; filePath: string; mimeType?: string; } /** 기존 파일의 내용을 로컬 파일로 교체 (같은 fileId·링크 유지, Drive 가 이전 버전을 보관). */ export declare function updateFileContent(auth: DriveClient, input: UpdateContentInput): Promise<{ status: "updated"; before: DriveFile; after: DriveFile; local: LocalFile; verified: boolean | null; }>; export interface UpdateMetadataInput { fileId: string; name?: string; description?: string; moveToFolderId?: string; } /** 이름·설명 변경, 다른 폴더로 이동. 하나 이상 바꿔야 한다. */ export declare function updateFileMetadata(auth: DriveClient, input: UpdateMetadataInput): Promise<{ status: "updated"; before: DriveFile; after: DriveFile; }>; /** 휴지통으로 이동 (30일 안에는 Drive 휴지통에서 되살릴 수 있다). */ export declare function trashFile(auth: DriveClient, fileId: string): Promise<{ status: "trashed"; before: DriveFile; after: DriveFile; }>;