Skip to content

Commit 0b33043

Browse files
committed
refactor: delete bytes from vide
#2137
1 parent bd4eab5 commit 0b33043

File tree

11 files changed

+14
-63
lines changed

11 files changed

+14
-63
lines changed

src/main/java/ai/elimu/entity/content/multimedia/Video.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public class Video extends Multimedia {
2626
@NotNull
2727
private Integer fileSize;
2828

29-
@NotNull
30-
@Lob
31-
@Column(length = 209715200) // 200MB
32-
private byte[] bytes;
33-
3429
/**
3530
* MD5 checksum of the file content.
3631
*/
@@ -44,6 +39,7 @@ public class Video extends Multimedia {
4439
@NotNull
4540
private String checksumGitHub;
4641

42+
@Deprecated
4743
@NotNull
4844
@Lob
4945
@Column(length = 1048576) // 1MB

src/main/java/ai/elimu/rest/v2/JpaToGsonConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public static VideoGson getVideoGson(Video video) {
354354
videoGson.setVideoFormat(video.getVideoFormat());
355355
videoGson.setChecksumMd5(video.getChecksumMd5());
356356
videoGson.setFileUrl(video.getUrl());
357-
videoGson.setFileSize(video.getBytes().length / 1024);
357+
videoGson.setFileSize(video.getFileSize());
358358
videoGson.setThumbnailUrl("/video/" + video.getId() + "_r" + video.getRevisionNumber() + "_thumbnail.png");
359359
Set<WordGson> wordGsons = new HashSet<>();
360360
for (Word word : video.getWords()) {

src/main/java/ai/elimu/web/content/multimedia/video/VideoCreateController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public String handleSubmit(
9191
video.setContentType(contentType);
9292

9393
video.setFileSize(bytes.length);
94-
video.setBytes(bytes);
9594
video.setChecksumMd5(ChecksumHelper.calculateMD5(bytes));
9695

9796
// TODO: convert to a default video format?

src/main/java/ai/elimu/web/content/multimedia/video/VideoCsvExportController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.web.bind.annotation.GetMapping;
1313
import org.springframework.web.bind.annotation.RequestMapping;
1414

15-
1615
@Controller
1716
@RequestMapping("/content/video/list/videos.csv")
1817
@RequiredArgsConstructor
@@ -28,7 +27,7 @@ public void handleRequest(
2827
log.info("handleRequest");
2928

3029
// Generate CSV file
31-
String csvFileContent = "id,content_type,content_license,attribution_url,title,checksum_md5,file_url,video_format" + "\n";
30+
String csvFileContent = "id,content_type,content_license,attribution_url,title,checksum_md5,file_url,file_size,video_format" + "\n";
3231
List<Video> videos = videoDao.readAllOrderedById();
3332
log.info("videos.size(): " + videos.size());
3433
for (Video video : videos) {
@@ -39,6 +38,7 @@ public void handleRequest(
3938
+ "\"" + video.getTitle() + "\","
4039
+ "\"" + video.getChecksumMd5() + "\","
4140
+ "\"" + video.getUrl() + "\","
41+
+ "\"" + video.getFileSize() + "\","
4242
+ video.getVideoFormat() + "\n";
4343
}
4444

src/main/java/ai/elimu/web/content/multimedia/video/VideoEditController.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ public String handleRequest(
6565
log.info("handleRequest");
6666

6767
Video video = videoDao.read(id);
68-
if (StringUtils.isBlank(video.getChecksumGitHub())) {
69-
String checksumGitHub = GitHubLfsHelper.uploadVideoToLfs(video, video.getBytes());
70-
video.setChecksumGitHub(checksumGitHub);
71-
video.setRevisionNumber(video.getRevisionNumber() + 1);
72-
videoDao.update(video);
73-
74-
// TODO: https://github.com/elimu-ai/webapp/issues/1545
75-
}
7668
model.addAttribute("video", video);
7769

7870
model.addAttribute("contentLicenses", ContentLicense.values());
@@ -127,7 +119,6 @@ public String handleSubmit(
127119
video.setContentType(contentType);
128120

129121
video.setFileSize(bytes.length);
130-
video.setBytes(bytes);
131122
video.setChecksumMd5(ChecksumHelper.calculateMD5(bytes));
132123

133124
// TODO: convert to a default video format?

src/main/java/ai/elimu/web/download/VideoController.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,6 @@ public class VideoController {
2222

2323
private final VideoDao videoDao;
2424

25-
@GetMapping(value="/{videoId}_r{revisionNumber}.{videoFormat}")
26-
public void handleRequest(
27-
Model model,
28-
@PathVariable Long videoId,
29-
@PathVariable Integer revisionNumber,
30-
@PathVariable String videoFormat,
31-
HttpServletResponse response,
32-
OutputStream outputStream) {
33-
log.info("handleRequest");
34-
35-
log.info("videoId: " + videoId);
36-
log.info("revisionNumber: " + revisionNumber);
37-
log.info("videoFormat: " + videoFormat);
38-
39-
Video video = videoDao.read(videoId);
40-
41-
response.setContentType(video.getContentType());
42-
43-
byte[] bytes = video.getBytes();
44-
response.setContentLength(bytes.length);
45-
try {
46-
outputStream.write(bytes);
47-
} catch (EOFException ex) {
48-
// org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
49-
log.warn(ex.getMessage());
50-
} catch (IOException ex) {
51-
log.error(ex.getMessage());
52-
} finally {
53-
try {
54-
try {
55-
outputStream.flush();
56-
outputStream.close();
57-
} catch (EOFException ex) {
58-
// org.eclipse.jetty.io.EofException (occurs when download is aborted before completion)
59-
log.warn(ex.getMessage());
60-
}
61-
} catch (IOException ex) {
62-
log.error(ex.getMessage());
63-
}
64-
}
65-
}
66-
6725
@GetMapping(value = "/{videoId}_r{revisionNumber}_thumbnail.png")
6826
public void handleThumbnailRequest(
6927
Model model,

src/main/java/ai/elimu/web/servlet/CustomDispatcherServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ private void populateDatabase(WebApplicationContext webApplicationContext) {
274274
video.setFileSize(bytes.length);
275275
video.setChecksumMd5(ChecksumHelper.calculateMD5(bytes));
276276
video.setChecksumGitHub("1331d7c476649f4449ec7c6663fc107ce2b4d88b");
277+
video.setThumbnail(Files.readAllBytes(new ClassRelativeResourceLoader(this.getClass()).getResource("placeholder.png").getFile().toPath()));
277278
} catch (IOException e) {
278279
logger.error(null, e);
279280
}

src/main/resources/META-INF/jpa-schema-export.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@
507507
attributionUrl text,
508508
contentLicense varchar(255),
509509
contentType varchar(255),
510-
bytes longblob,
511510
checksumGitHub varchar(255),
512511
checksumMd5 varchar(255),
513512
fileSize integer,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 2.5.109
2+
3+
ALTER TABLE `Video` DROP COLUMN `bytes`;

src/main/webapp/WEB-INF/jsp/content/multimedia/video/create.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<div class="file-field input-field col s12">
8282
<div class="btn">
8383
<span>File (M4V/MP4)</span>
84-
<form:input path="bytes" type="file" />
84+
<input name="bytes" type="file" />
8585
</div>
8686
<div class="file-path-wrapper">
8787
<input class="file-path validate" type="text" />

0 commit comments

Comments
 (0)