All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksoot.common.spring.util.ImageProperties Maven / Gradle / Ivy

The newest version!
package com.ksoot.common.spring.util;

import jakarta.validation.Valid;
import java.util.Arrays;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@NoArgsConstructor
@ToString
@ConfigurationProperties(prefix = "application.images")
@Valid
public class ImageProperties {

  public static final String ALL_VALUE = "*";

  public static final String[] ALL_TYPES = {"gif", "png", "jpg", "jpeg"};

  private String bucketName;

  private String[] allowedExtensions = ALL_TYPES;

  public void setAllowedExtensions(final String[] allowedExtensions) {
    if (ArrayUtils.isNotEmpty(allowedExtensions)
        && Arrays.asList(allowedExtensions).contains(ALL_VALUE)) {
      this.allowedExtensions = ALL_TYPES;
    } else {
      this.allowedExtensions = allowedExtensions;
    }
  }

  public boolean isAllowed(final String extension) {
    return Arrays.asList(allowedExtensions).contains(extension);
  }

  public String allowedExtensionsString() {
    return String.join(",", Arrays.asList(this.allowedExtensions));
  }

  //  public static void main(String[] args) {
  //    System.out.println("100MB = " + DataSize.ofMegabytes(100));
  //    System.out.println("20KB = " + DataSize.ofKilobytes(20));
  //  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy