Merge pull request 'dev' (#74) from dev into main
Reviewed-on: http://39.117.244.52:3000/kjs/ERP-node/pulls/74
This commit is contained in:
@@ -16,6 +16,7 @@ export interface FileUploadResponse {
|
||||
success: boolean;
|
||||
message: string;
|
||||
files: FileInfo[];
|
||||
data?: FileInfo[];
|
||||
}
|
||||
|
||||
export interface FileDownloadParams {
|
||||
@@ -134,6 +135,28 @@ export const getFileInfo = async (fileId: string, serverFilename: string) => {
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* 컴포넌트의 템플릿 파일과 데이터 파일을 모두 조회
|
||||
*/
|
||||
export const getComponentFiles = async (params: {
|
||||
screenId: number;
|
||||
componentId: string;
|
||||
tableName?: string;
|
||||
recordId?: string;
|
||||
columnName?: string;
|
||||
}): Promise<{
|
||||
success: boolean;
|
||||
templateFiles: FileInfo[];
|
||||
dataFiles: FileInfo[];
|
||||
totalFiles: FileInfo[];
|
||||
}> => {
|
||||
const response = await apiClient.get('/files/component-files', {
|
||||
params,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* 파일 업로드 및 JSON 데이터 생성
|
||||
* InteractiveScreenViewer에서 사용할 통합 함수
|
||||
|
||||
183
frontend/lib/api/globalFile.ts
Normal file
183
frontend/lib/api/globalFile.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { FileInfo } from "./file";
|
||||
|
||||
export interface GlobalFileInfo extends FileInfo {
|
||||
uploadPage: string;
|
||||
uploadTime: string;
|
||||
componentId: string;
|
||||
screenId?: number;
|
||||
accessible: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 전역 파일 저장소 관리 클래스
|
||||
* 페이지 간 파일 공유를 위한 클라이언트 사이드 파일 레지스트리
|
||||
*/
|
||||
export class GlobalFileManager {
|
||||
private static readonly STORAGE_KEY = 'globalFileRegistry';
|
||||
private static readonly SESSION_STORAGE_KEY = 'globalFileRegistrySession';
|
||||
|
||||
/**
|
||||
* 전역 파일 저장소 가져오기
|
||||
*/
|
||||
static getRegistry(): Record<string, GlobalFileInfo> {
|
||||
if (typeof window === 'undefined') return {};
|
||||
|
||||
// 1. 메모리에서 먼저 확인
|
||||
if ((window as any).globalFileRegistry) {
|
||||
return (window as any).globalFileRegistry;
|
||||
}
|
||||
|
||||
// 2. sessionStorage에서 확인 (세션 동안 유지)
|
||||
const sessionData = sessionStorage.getItem(this.SESSION_STORAGE_KEY);
|
||||
if (sessionData) {
|
||||
try {
|
||||
const parsedData = JSON.parse(sessionData);
|
||||
(window as any).globalFileRegistry = parsedData;
|
||||
return parsedData;
|
||||
} catch (error) {
|
||||
console.warn('세션 파일 데이터 파싱 실패:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. localStorage에서 확인 (영구 저장)
|
||||
const localData = localStorage.getItem(this.STORAGE_KEY);
|
||||
if (localData) {
|
||||
try {
|
||||
const parsedData = JSON.parse(localData);
|
||||
(window as any).globalFileRegistry = parsedData;
|
||||
return parsedData;
|
||||
} catch (error) {
|
||||
console.warn('로컬 파일 데이터 파싱 실패:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일을 전역 저장소에 등록
|
||||
*/
|
||||
static registerFile(fileInfo: GlobalFileInfo): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const registry = this.getRegistry();
|
||||
registry[fileInfo.objid] = fileInfo;
|
||||
|
||||
// 메모리, 세션, 로컬스토리지에 모두 저장
|
||||
(window as any).globalFileRegistry = registry;
|
||||
sessionStorage.setItem(this.SESSION_STORAGE_KEY, JSON.stringify(registry));
|
||||
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(registry));
|
||||
|
||||
console.log(`🌐 파일 등록됨: ${fileInfo.savedFileName} (총 ${Object.keys(registry).length}개)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 여러 파일을 한번에 등록
|
||||
*/
|
||||
static registerFiles(files: FileInfo[], context: {
|
||||
uploadPage: string;
|
||||
componentId: string;
|
||||
screenId?: number;
|
||||
}): void {
|
||||
files.forEach(file => {
|
||||
const globalFileInfo: GlobalFileInfo = {
|
||||
...file,
|
||||
uploadPage: context.uploadPage,
|
||||
uploadTime: new Date().toISOString(),
|
||||
componentId: context.componentId,
|
||||
screenId: context.screenId,
|
||||
accessible: true,
|
||||
};
|
||||
this.registerFile(globalFileInfo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 접근 가능한 파일 목록 가져오기
|
||||
*/
|
||||
static getAllAccessibleFiles(): GlobalFileInfo[] {
|
||||
const registry = this.getRegistry();
|
||||
return Object.values(registry).filter(file => file.accessible);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 페이지에서 업로드된 파일들 가져오기
|
||||
*/
|
||||
static getFilesByPage(pagePath: string): GlobalFileInfo[] {
|
||||
const registry = this.getRegistry();
|
||||
return Object.values(registry).filter(file =>
|
||||
file.uploadPage === pagePath && file.accessible
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 화면에서 업로드된 파일들 가져오기
|
||||
*/
|
||||
static getFilesByScreen(screenId: number): GlobalFileInfo[] {
|
||||
const registry = this.getRegistry();
|
||||
return Object.values(registry).filter(file =>
|
||||
file.screenId === screenId && file.accessible
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일 검색 (이름으로)
|
||||
*/
|
||||
static searchFiles(query: string): GlobalFileInfo[] {
|
||||
const registry = this.getRegistry();
|
||||
const lowerQuery = query.toLowerCase();
|
||||
return Object.values(registry).filter(file =>
|
||||
file.accessible &&
|
||||
(file.realFileName?.toLowerCase().includes(lowerQuery) ||
|
||||
file.savedFileName?.toLowerCase().includes(lowerQuery))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일을 접근 불가능하게 설정 (삭제 대신)
|
||||
*/
|
||||
static setFileAccessible(fileId: string, accessible: boolean): void {
|
||||
const registry = this.getRegistry();
|
||||
if (registry[fileId]) {
|
||||
registry[fileId].accessible = accessible;
|
||||
|
||||
// 저장소 업데이트
|
||||
(window as any).globalFileRegistry = registry;
|
||||
sessionStorage.setItem(this.SESSION_STORAGE_KEY, JSON.stringify(registry));
|
||||
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(registry));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 전역 저장소 초기화
|
||||
*/
|
||||
static clearRegistry(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
(window as any).globalFileRegistry = {};
|
||||
sessionStorage.removeItem(this.SESSION_STORAGE_KEY);
|
||||
localStorage.removeItem(this.STORAGE_KEY);
|
||||
|
||||
console.log('🧹 전역 파일 저장소 초기화됨');
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장소 상태 정보
|
||||
*/
|
||||
static getRegistryInfo(): {
|
||||
totalFiles: number;
|
||||
accessibleFiles: number;
|
||||
pages: string[];
|
||||
screens: number[];
|
||||
} {
|
||||
const registry = this.getRegistry();
|
||||
const files = Object.values(registry);
|
||||
|
||||
return {
|
||||
totalFiles: files.length,
|
||||
accessibleFiles: files.filter(f => f.accessible).length,
|
||||
pages: [...new Set(files.map(f => f.uploadPage))],
|
||||
screens: [...new Set(files.map(f => f.screenId).filter(Boolean) as number[])],
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user