-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
56e7482
commit a88c16f
Showing
50 changed files
with
343 additions
and
1,715 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
backend/media/src/main/java/co/airy/core/media/MediaController.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,61 @@ | ||
package co.airy.core.media; | ||
|
||
import co.airy.core.media.services.MediaUpload; | ||
import co.airy.log.AiryLoggerFactory; | ||
import co.airy.spring.web.payload.RequestErrorResponsePayload; | ||
import co.airy.uuid.UUIDv5; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.slf4j.Logger; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.InputStream; | ||
|
||
@RestController | ||
public class MediaController { | ||
private static final Logger log = AiryLoggerFactory.getLogger(MediaController.class); | ||
private final MediaUpload mediaUpload; | ||
|
||
public MediaController(MediaUpload mediaUpload) { | ||
this.mediaUpload = mediaUpload; | ||
} | ||
|
||
|
||
@PostMapping(value = "/media.uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
public ResponseEntity<?> mediaUpload(@RequestParam("file") MultipartFile multipartFile) { | ||
final String originalFileName = multipartFile.getOriginalFilename(); | ||
|
||
if (originalFileName == null) { | ||
return ResponseEntity.unprocessableEntity().body(new RequestErrorResponsePayload("Request is missing original file name")); | ||
} | ||
|
||
try { | ||
final InputStream is = multipartFile.getInputStream(); | ||
String fileName = UUIDv5.fromFile(is).toString(); | ||
|
||
final String originalFileExtension = originalFileName.contains(".") ? originalFileName.substring(originalFileName.lastIndexOf(".")) : ""; | ||
fileName = fileName.concat(originalFileExtension); | ||
|
||
return ResponseEntity.ok(new MediaUploadResponsePayload(mediaUpload.uploadMedia(is, fileName))); | ||
} catch (Exception e) { | ||
log.error("Media upload failed:", e); | ||
return ResponseEntity.badRequest().body(new RequestErrorResponsePayload(String.format("Media Upload failed with error: %s", e.getMessage()))); | ||
} | ||
} | ||
} | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
class MediaUploadResponsePayload { | ||
private String mediaUrl; | ||
} | ||
|
111 changes: 0 additions & 111 deletions
111
backend/media/src/main/java/co/airy/core/media/MessageMediaResolver.java
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
backend/media/src/main/java/co/airy/core/media/MetadataResolver.java
This file was deleted.
Oops, something went wrong.
87 changes: 0 additions & 87 deletions
87
backend/media/src/main/java/co/airy/core/media/Stores.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
Oops, something went wrong.