-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($static-resource-center): get resource from Minio
- Loading branch information
1 parent
b5e1340
commit da01f3c
Showing
15 changed files
with
164 additions
and
19 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...ic-resource-center/src/main/java/com/jmsoftware/maf/authcenter/download/package-info.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
...r/src/main/java/com/jmsoftware/maf/authcenter/read/controller/ReadResourceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.jmsoftware.maf.authcenter.read.controller; | ||
|
||
import com.jmsoftware.maf.authcenter.read.entity.GetSingleResourcePayload; | ||
import com.jmsoftware.maf.authcenter.read.service.ReadResourceService; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.validation.Valid; | ||
|
||
/** | ||
* <h1>ReadResourceController</h1> | ||
* <p> | ||
* Change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 6/20/21 5:16 PM | ||
**/ | ||
@Validated | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Api(tags = {"Read resource API"}) | ||
public class ReadResourceController { | ||
private final ReadResourceService readResourceService; | ||
|
||
@GetMapping("/{bucket}/{object}") | ||
@ApiOperation(value = "Get single resource", notes = "Get or download single resource") | ||
public ResponseEntity<Resource> getSingleResource(@PathVariable String bucket, @PathVariable String object, | ||
@Valid GetSingleResourcePayload payload) { | ||
return readResourceService.getSingleResource(bucket, object, payload); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ter/src/main/java/com/jmsoftware/maf/authcenter/read/entity/GetSingleResourcePayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.jmsoftware.maf.authcenter.read.entity; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* <h1>GetSingleResourcePayload</h1> | ||
* <p> | ||
* Change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 6/20/21 7:16 PM | ||
**/ | ||
@Data | ||
public class GetSingleResourcePayload { | ||
private Boolean downloadable; | ||
} |
1 change: 1 addition & 0 deletions
1
static-resource-center/src/main/java/com/jmsoftware/maf/authcenter/read/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter.read; |
33 changes: 33 additions & 0 deletions
33
...-center/src/main/java/com/jmsoftware/maf/authcenter/read/service/ReadResourceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jmsoftware.maf.authcenter.read.service; | ||
|
||
import com.jmsoftware.maf.authcenter.read.entity.GetSingleResourcePayload; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* <h1>ReadResourceService</h1> | ||
* <p> | ||
* Change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 6/20/21 5:17 PM | ||
**/ | ||
@Validated | ||
public interface ReadResourceService { | ||
String BUCKET_OBJECT_NAME_REGEX = "^.+/.+$"; | ||
|
||
/** | ||
* Gets single resource. | ||
* | ||
* @param bucket the bucket | ||
* @param object the object | ||
* @param payload the payload | ||
* @return the single resource | ||
*/ | ||
ResponseEntity<Resource> getSingleResource(@NotBlank String bucket, @NotBlank String object, | ||
@Valid @NotNull GetSingleResourcePayload payload); | ||
} |
55 changes: 55 additions & 0 deletions
55
...rc/main/java/com/jmsoftware/maf/authcenter/read/service/impl/ReadResourceServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.jmsoftware.maf.authcenter.read.service.impl; | ||
|
||
import cn.hutool.core.util.BooleanUtil; | ||
import cn.hutool.core.util.ObjectUtil; | ||
import com.jmsoftware.maf.authcenter.read.entity.GetSingleResourcePayload; | ||
import com.jmsoftware.maf.authcenter.read.service.ReadResourceService; | ||
import com.jmsoftware.maf.springcloudstarter.helper.MinioHelper; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.core.io.InputStreamResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.ContentDisposition; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* <h1>ReadResourceServiceImpl</h1> | ||
* <p> | ||
* Change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 6/20/21 5:18 PM | ||
**/ | ||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ReadResourceServiceImpl implements ReadResourceService { | ||
private final MinioHelper minioHelper; | ||
|
||
@Override | ||
public ResponseEntity<Resource> getSingleResource(@NotBlank String bucket, @NotBlank String object, | ||
@Valid @NotNull GetSingleResourcePayload payload) { | ||
val statObjectResponse = minioHelper.statObject(bucket, object); | ||
if (ObjectUtil.isNull(statObjectResponse)) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
val inputStream = minioHelper.getObject(bucket, object); | ||
val bodyBuilder = ResponseEntity.ok(); | ||
if (BooleanUtil.isTrue(payload.getDownloadable())) { | ||
String contentDisposition = ContentDisposition.builder("attachment").filename(object).build().toString(); | ||
bodyBuilder.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); | ||
} | ||
return bodyBuilder | ||
.header(HttpHeaders.ACCEPT_RANGES, "bytes") | ||
.contentLength(statObjectResponse.size()) | ||
.contentType(MediaType.parseMediaType(statObjectResponse.contentType())) | ||
.body(new InputStreamResource(inputStream)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ce-center/src/main/java/com/jmsoftware/maf/authcenter/read/service/impl/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter.read.service.impl; |
1 change: 1 addition & 0 deletions
1
...esource-center/src/main/java/com/jmsoftware/maf/authcenter/read/service/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter.read.service; |
1 change: 0 additions & 1 deletion
1
static-resource-center/src/main/java/com/jmsoftware/maf/authcenter/upload/package-info.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ource-center/src/main/java/com/jmsoftware/maf/authcenter/upload/service/package-info.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
static-resource-center/src/main/java/com/jmsoftware/maf/authcenter/write/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter.write; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...source-center/src/main/java/com/jmsoftware/maf/authcenter/write/service/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter.write.service; |