From 55338c83d3bc604eaca9803f273b9a987ada2a8d Mon Sep 17 00:00:00 2001 From: junglesub Date: Mon, 28 Oct 2024 11:41:53 +0900 Subject: [PATCH] feat: fb storage file list route --- src/main/front/src/pages/admin/index.jsx | 3 ++- .../realspr/controller/TbadminController.java | 6 +++++ .../thc/realspr/service/FirebaseService.java | 22 +++++++++++++++++++ .../thc/realspr/service/TbadminService.java | 2 ++ .../service/impl/TbadminServiceImpl.java | 12 +++++++++- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/front/src/pages/admin/index.jsx b/src/main/front/src/pages/admin/index.jsx index 3073dac..0099a57 100644 --- a/src/main/front/src/pages/admin/index.jsx +++ b/src/main/front/src/pages/admin/index.jsx @@ -4,6 +4,7 @@ import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile"; import UsersTable from "./UsersTable"; import AdminFeed from "./AdminFeed"; +import AdminFiles from "./AdminFiles"; export const ADMINMENU = [ { @@ -22,6 +23,6 @@ export const ADMINMENU = [ title: "파일 관리", icon: , id: "files", - comp: UsersTable, + comp: AdminFiles, }, ]; diff --git a/src/main/java/com/thc/realspr/controller/TbadminController.java b/src/main/java/com/thc/realspr/controller/TbadminController.java index 6378284..ac9b7ba 100644 --- a/src/main/java/com/thc/realspr/controller/TbadminController.java +++ b/src/main/java/com/thc/realspr/controller/TbadminController.java @@ -22,4 +22,10 @@ public List adminGetUser(@RequestParam Map adminGetFirebaseStorageList(@RequestParam Map param, HttpServletRequest request) { + String reqUserId = request.getAttribute("reqUserId").toString(); + return tbadminService.adminGetFirebaseStorageList(reqUserId); + } } diff --git a/src/main/java/com/thc/realspr/service/FirebaseService.java b/src/main/java/com/thc/realspr/service/FirebaseService.java index 0d4049c..c613cc8 100644 --- a/src/main/java/com/thc/realspr/service/FirebaseService.java +++ b/src/main/java/com/thc/realspr/service/FirebaseService.java @@ -1,5 +1,6 @@ package com.thc.realspr.service; +import com.google.cloud.storage.Bucket; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -8,6 +9,8 @@ import com.google.cloud.storage.Storage; import com.google.firebase.cloud.StorageClient; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -33,4 +36,23 @@ public CompletableFuture getSignedUrlAsync(String path) { String url = getSignedUrl(path); // Assume this is the existing method to get signed URL return CompletableFuture.completedFuture(url); } + + public List listAllFiles(String folderName) { + Storage storage = StorageClient.getInstance().bucket().getStorage(); + Bucket bucket = StorageClient.getInstance().bucket(); + + List fileList = new ArrayList<>(); +// for (Blob blob : bucket.list().iterateAll()) { + for (Blob blob : bucket.list(Storage.BlobListOption.prefix(folderName + "/")).iterateAll()) { + fileList.add(blob.getName()); + } + + return fileList; + } + + @Async + public CompletableFuture> listAllFilesAsync(String folderName) { + List files = listAllFiles(folderName); + return CompletableFuture.completedFuture(files); + } } diff --git a/src/main/java/com/thc/realspr/service/TbadminService.java b/src/main/java/com/thc/realspr/service/TbadminService.java index 6a0a534..cc6e8ad 100644 --- a/src/main/java/com/thc/realspr/service/TbadminService.java +++ b/src/main/java/com/thc/realspr/service/TbadminService.java @@ -9,4 +9,6 @@ @Service public interface TbadminService { public List adminGetUser(String userId, Map param); + + public List adminGetFirebaseStorageList(String userId); } diff --git a/src/main/java/com/thc/realspr/service/impl/TbadminServiceImpl.java b/src/main/java/com/thc/realspr/service/impl/TbadminServiceImpl.java index f54f10f..460c03c 100644 --- a/src/main/java/com/thc/realspr/service/impl/TbadminServiceImpl.java +++ b/src/main/java/com/thc/realspr/service/impl/TbadminServiceImpl.java @@ -5,6 +5,7 @@ import com.thc.realspr.id.UserPermId; import com.thc.realspr.mapper.TbadminMapper; import com.thc.realspr.repository.TbUserPermRepository; +import com.thc.realspr.service.FirebaseService; import com.thc.realspr.service.TbadminService; import org.springframework.stereotype.Service; @@ -15,10 +16,12 @@ public class TbadminServiceImpl implements TbadminService { private final TbadminMapper tbadminMapper; private final TbUserPermRepository tbUserPermRepository; + private final FirebaseService firebaseService; - public TbadminServiceImpl(TbadminMapper tbadminMapper, TbUserPermRepository tbUserPermRepository) { + public TbadminServiceImpl(TbadminMapper tbadminMapper, TbUserPermRepository tbUserPermRepository, FirebaseService firebaseService) { this.tbadminMapper = tbadminMapper; this.tbUserPermRepository = tbUserPermRepository; + this.firebaseService = firebaseService; } public List adminGetUser(String userId, Map param) { @@ -28,4 +31,11 @@ public List adminGetUser(String userId, Map adminGetFirebaseStorageList(String userId) { + + if (tbUserPermRepository.findById(new UserPermId(userId, "adminFirebaseFiles")).isEmpty()) + throw new NoAuthorizationException("No Admin Permission"); + return firebaseService.listAllFiles("KaFile"); + } + }