Skip to content

Commit

Permalink
feat: fb storage file list route
Browse files Browse the repository at this point in the history
  • Loading branch information
junglesub committed Oct 28, 2024
1 parent e1be2b4 commit 55338c8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/front/src/pages/admin/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -22,6 +23,6 @@ export const ADMINMENU = [
title: "파일 관리",
icon: <InsertDriveFileIcon />,
id: "files",
comp: UsersTable,
comp: AdminFiles,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public List<TbadminDto.UserDetail> adminGetUser(@RequestParam Map<String, String
String reqUserId = request.getAttribute("reqUserId").toString();
return tbadminService.adminGetUser(reqUserId, param);
}

@GetMapping("/firebasefilelist")
public List<String> adminGetFirebaseStorageList(@RequestParam Map<String, String> param, HttpServletRequest request) {
String reqUserId = request.getAttribute("reqUserId").toString();
return tbadminService.adminGetFirebaseStorageList(reqUserId);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/thc/realspr/service/FirebaseService.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand All @@ -33,4 +36,23 @@ public CompletableFuture<String> getSignedUrlAsync(String path) {
String url = getSignedUrl(path); // Assume this is the existing method to get signed URL
return CompletableFuture.completedFuture(url);
}

public List<String> listAllFiles(String folderName) {
Storage storage = StorageClient.getInstance().bucket().getStorage();
Bucket bucket = StorageClient.getInstance().bucket();

List<String> 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<List<String>> listAllFilesAsync(String folderName) {
List<String> files = listAllFiles(folderName);
return CompletableFuture.completedFuture(files);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/thc/realspr/service/TbadminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
@Service
public interface TbadminService {
public List<TbadminDto.UserDetail> adminGetUser(String userId, Map<String, String> param);

public List<String> adminGetFirebaseStorageList(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<TbadminDto.UserDetail> adminGetUser(String userId, Map<String, String> param) {
Expand All @@ -28,4 +31,11 @@ public List<TbadminDto.UserDetail> adminGetUser(String userId, Map<String, Strin
return tbadminMapper.allUsers();
}

public List<String> adminGetFirebaseStorageList(String userId) {

if (tbUserPermRepository.findById(new UserPermId(userId, "adminFirebaseFiles")).isEmpty())
throw new NoAuthorizationException("No Admin Permission");
return firebaseService.listAllFiles("KaFile");
}

}

0 comments on commit 55338c8

Please sign in to comment.