Skip to content

Commit

Permalink
feat: add middle sized screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Jan 21, 2025
1 parent 60bb642 commit 2ba4119
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 749 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class ScreenshotModelAssembler(
) {
override fun toModel(entity: Screenshot): ScreenshotModel {
val filenameWithSignature = getFilenameWithSignature(entity.filename)
val middleSizedFilenameWithSignature = getFilenameWithSignature(entity.middleSizedFilename)
val middleSizedFilenameWithSignature = entity.middleSizedFilename?.let { getFilenameWithSignature(it) }
val thumbnailFilenameWithSignature = getFilenameWithSignature(entity.thumbnailFilename)

val fileUrl = getFileUrl(filenameWithSignature)
val middleSizedUrl = getFileUrl(middleSizedFilenameWithSignature)
val middleSizedUrl = middleSizedFilenameWithSignature?.let { getFileUrl(it) }
val thumbnailUrl = getFileUrl(thumbnailFilenameWithSignature)

return ScreenshotModel(
Expand Down Expand Up @@ -64,7 +64,6 @@ class ScreenshotModelAssembler(
height = entity.height,
)
.add(Link.of(fileUrl, "file"))
.add(Link.of(middleSizedUrl, "middle_sized"))
.add(Link.of(thumbnailUrl, "thumbnail"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,21 @@ class DemoProjectCreator(
}

private fun saveScreenshot(): Screenshot {
applicationContext.getResource("classpath:demoProject/screenshot.png").inputStream
.use { screenshotImage ->
applicationContext.getResource("classpath:demoProject/screenshot-thumbnail.png").inputStream
.use { screenshotThumbnail ->
return screenshotService.saveScreenshot(
screenshotImage.readAllBytes(),
screenshotThumbnail.readAllBytes(),
null,
Dimension(SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT),
)
}
}
val image = applicationContext.getResource("classpath:demoProject/screenshot.png").inputStream
.use { it.readAllBytes() }
val middleSized = applicationContext.getResource("classpath:demoProject/screenshot-middle-sized.png").inputStream
.use { it.readAllBytes() }
val thumbnail = applicationContext.getResource("classpath:demoProject/screenshot-thumbnail.png").inputStream
.use { screenshotThumbnail -> screenshotThumbnail.readAllBytes() }

return screenshotService.saveScreenshot(
image,
middleSized,
thumbnail,
null,
Dimension(SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT),
)

}

val keys: MutableMap<String, Key> = mutableMapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class TestDataService(
val screenshotBuilders = builder.data.screenshots
screenshotService.saveAll(screenshotBuilders.map { it.self })
screenshotBuilders.forEach {
screenshotService.storeFiles(it.self, it.image?.toByteArray(), it.thumbnail?.toByteArray())
screenshotService.storeFiles(it.self, it.image?.toByteArray(), it.middleSized?.toByteArray(), it.thumbnail?.toByteArray())
}
screenshotService.saveAllReferences(builder.data.keyScreenshotReferences.map { it.self })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ScreenshotBuilder(
projectBuilder: ProjectBuilder,
) : EntityDataBuilder<Screenshot, ScreenshotBuilder> {
var thumbnail: ByteArrayOutputStream? = null
var middleSized: ByteArrayOutputStream? = null
var image: ByteArrayOutputStream? = null

override var self: Screenshot = Screenshot()
Expand Down
4 changes: 2 additions & 2 deletions backend/data/src/main/kotlin/io/tolgee/model/Screenshot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Screenshot : StandardAuditModel() {
return "$pathWithSlash$hash.$extension"
}

val middleSizedFilename: String
val middleSizedFilename: String?
get() {
if (!hasMiddleSized) {
return filename
return null
}
return "$pathWithSlash${hash}_middle_sized.$extension"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class ScreenshotService(
thumbnail: ByteArray?,
) {
thumbnail?.let { fileStorage.storeFile(screenshot.getThumbnailPath(), it) }
middleSized?.let { fileStorage.storeFile(screenshot.getMiddleSizedPath(), it)}
image?.let { fileStorage.storeFile(screenshot.getFilePath(), it) }
}

Expand Down Expand Up @@ -351,6 +352,10 @@ class ScreenshotService(
return "$SCREENSHOTS_STORAGE_FOLDER_NAME/${this.filename}"
}

private fun Screenshot.getMiddleSizedPath(): String {
return "$SCREENSHOTS_STORAGE_FOLDER_NAME/${this.middleSizedFilename}"
}

private fun Screenshot.getThumbnailPath(): String {
return "$SCREENSHOTS_STORAGE_FOLDER_NAME/${this.thumbnailFilename}"
}
Expand Down
7 changes: 7 additions & 0 deletions backend/data/src/main/resources/db/changelog/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4052,4 +4052,11 @@
<changeSet author="stepangranat (generated)" id="1735822703703-2">
<addForeignKeyConstraint baseColumnNames="created_by_id" baseTableName="invitation" constraintName="FK2q6wi3un2qq40cgjoln871ak2" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="user_account" validate="true"/>
</changeSet>
<changeSet author="stepangranat (generated)" id="1737470670674-1">
<addColumn tableName="screenshot">
<column defaultValueBoolean="false" name="has_middle_sized" type="BOOLEAN">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2ba4119

Please sign in to comment.