Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New3 #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

New3 #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void deleteGifBitmap(GifBitmap gifBitmap) {
try {
deleteBlob(gifBitmap.getMediaRef());
gifMediaRepository.delete(gifBitmap);
} catch (Exception e) {
}
catch (Exception e) {
LOGGER.error("Error deleting GifBitmap: {}", e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,61 @@

import static com.quashbugs.quash.constants.Constants.MAX_RETRIES;

@Service
public class AzureStorageService extends AbstractStorageService {
// @Service
// public class AzureStorageService extends AbstractStorageService {

private final BlobServiceClient blobServiceClient;
// private final BlobServiceClient blobServiceClient;

private final BlobContainerClient containerClient;
// private final BlobContainerClient containerClient;

private static final Logger LOGGER = LoggerFactory.getLogger(AzureStorageService.class);
// private static final Logger LOGGER = LoggerFactory.getLogger(AzureStorageService.class);

@Autowired
public AzureStorageService(BugMediaRepository bugMediaRepository,
GifMediaRepository gifMediaRepository,
CrashLogRepository crashLogRepository,
ApplicationRepository applicationRepository,
ChatUploadRepository chatUploadRepository,
StorageProperties storageProperties) {
super(bugMediaRepository, gifMediaRepository, crashLogRepository, applicationRepository, chatUploadRepository, storageProperties);
// @Autowired
// public AzureStorageService(BugMediaRepository bugMediaRepository,
// GifMediaRepository gifMediaRepository,
// CrashLogRepository crashLogRepository,
// ApplicationRepository applicationRepository,
// ChatUploadRepository chatUploadRepository,
// StorageProperties storageProperties) {
// super(bugMediaRepository, gifMediaRepository, crashLogRepository, applicationRepository, chatUploadRepository, storageProperties);

try {
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(storageProperties.getAzureAccountName(), storageProperties.getAzureAccountKey());
this.blobServiceClient = new BlobServiceClientBuilder()
.endpoint("https://" + storageProperties.getAzureAccountName() + ".blob.core.windows.net")
.credential(credential)
.buildClient();
this.containerClient = blobServiceClient.getBlobContainerClient(storageProperties.getAzureContainerName());
} catch (Exception e) {
LOGGER.error("Error initializing AzureStorageService", e);
throw new RuntimeException(e);
}
}
// try {
// StorageSharedKeyCredential credential = new StorageSharedKeyCredential(storageProperties.getAzureAccountName(), storageProperties.getAzureAccountKey());
// this.blobServiceClient = new BlobServiceClientBuilder()
// .endpoint("https://" + storageProperties.getAzureAccountName() + ".blob.core.windows.net")
// .credential(credential)
// .buildClient();
// this.containerClient = blobServiceClient.getBlobContainerClient(storageProperties.getAzureContainerName());
// } catch (Exception e) {
// LOGGER.error("Error initializing AzureStorageService", e);
// throw new RuntimeException(e);
// }
// }

@Override
protected void uploadWithRetries(byte[] content, String objectName, String mimeType) {
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
BlobClient blobClient = containerClient.getBlobClient(objectName);
blobClient.upload(new ByteArrayInputStream(content), content.length, true);
blobClient.setHttpHeaders(new BlobHttpHeaders().setContentType(mimeType));
return;
} catch (Exception ex) {
logAndMaybeRetry(attempt, ex);
}
}
throw new RuntimeException("Failed to upload media after max retries.");
}
// @Override
// protected void uploadWithRetries(byte[] content, String objectName, String mimeType) {
// for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
// try {
// BlobClient blobClient = containerClient.getBlobClient(objectName);
// blobClient.upload(new ByteArrayInputStream(content), content.length, true);
// blobClient.setHttpHeaders(new BlobHttpHeaders().setContentType(mimeType));
// return;
// } catch (Exception ex) {
// logAndMaybeRetry(attempt, ex);
// }
// }
// throw new RuntimeException("Failed to upload media after max retries.");
// }

@Override
protected void deleteBlob(String blobName) {
BlobClient blobClient = containerClient.getBlobClient(blobName);
blobClient.delete();
}
// @Override
// protected void deleteBlob(String blobName) {
// BlobClient blobClient = containerClient.getBlobClient(blobName);
// blobClient.delete();
// }

@Override
public String generateSignedUrl(String objectName) {
BlobClient blobClient = containerClient.getBlobClient(objectName);
// @Override
// public String generateSignedUrl(String objectName) {
// BlobClient blobClient = containerClient.getBlobClient(objectName);
BlobServiceSasSignatureValues sasValues = new BlobServiceSasSignatureValues(OffsetDateTime.now().plusDays(7), new BlobSasPermission().setReadPermission(true));
String sasToken = blobClient.generateSas(sasValues);
return blobClient.getBlobUrl() + "?" + sasToken;
Expand Down