Skip to content

Commit 98b03dc

Browse files
committed
feat: only-pets 모드를 추가한다
1 parent 3b53d05 commit 98b03dc

File tree

105 files changed

+271
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+271
-111
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jobs:
7575
"SLACK_TOKEN=${{ secrets.SLACK_TOKEN }}"
7676
"RELAY_APPROVE_TOKEN=${{ secrets.RELAY_APPROVE_TOKEN }}"
7777
"INTERNAL_AUTH_SECRET=${{ secrets.INTERNAL_AUTH_SECRET }}"
78+
"INTERNAL_IMAGE_SECRET=${{ secrets.INTERNAL_IMAGE_SECRET }}"
7879
7980
- name: build and push filebeat
8081
uses: docker/build-push-action@v4

deploy/api/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ARG INTERNAL_SECRET
1010
ARG SLACK_TOKEN
1111
ARG RELAY_APPROVE_TOKEN
1212
ARG INTERNAL_AUTH_SECRET
13+
ARG INTERNAL_IMAGE_SECRET
1314

1415
ARG JAR_FILE=./*.jar
1516
COPY ${JAR_FILE} gitanimals-render.jar
@@ -23,7 +24,8 @@ ENV db_url=${DB_URL} \
2324
internal_secret=${INTERNAL_SECRET} \
2425
slack_token=${SLACK_TOKEN} \
2526
relay_approve_token=${RELAY_APPROVE_TOKEN} \
26-
internal_auth_secret=${INTERNAL_AUTH_SECRET}
27+
internal_auth_secret=${INTERNAL_AUTH_SECRET} \
28+
internal_image_secret=${INTERNAL_IMAGE_SECRET}
2729

2830
ENTRYPOINT java -jar gitanimals-render.jar \
2931
--spring.datasource.url=${db_url} \
@@ -35,4 +37,5 @@ ENTRYPOINT java -jar gitanimals-render.jar \
3537
--internal.secret=${internal_secret} \
3638
--slack.token=${slack_token} \
3739
--relay.approve.token=${relay_approve_token} \
38-
--internal.auth.secret=${internal_auth_secret}
40+
--internal.auth.secret=${internal_auth_secret} \
41+
--internal.image.secret=${internal_image_secret}

src/main/kotlin/org/gitanimals/core/Mode.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ enum class Mode {
55
LINE,
66
LINE_NO_CONTRIBUTION,
77
NAME_WITH_LEVEL,
8+
NONE,
89
;
910
}

src/main/kotlin/org/gitanimals/core/PersonaType.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,13 +2156,13 @@ enum class PersonaType(val weight: Double, private var dropRate: String? = null)
21562156
mode: Mode
21572157
): String =
21582158
loadSvg(name, animationId, level, mode)
2159-
.drawContribution(mode, contributionCount)
2159+
.drawDisplayOptions(mode, contributionCount)
21602160

21612161
protected abstract fun loadSvg(name: String, animationId: Long, level: Long, mode: Mode): String
21622162

21632163
protected abstract fun act(id: Long, flippedWidth: Double = 0.0): String
21642164

2165-
protected fun String.drawContribution(
2165+
protected fun String.drawDisplayOptions(
21662166
mode: Mode,
21672167
contributionCount: Long,
21682168
): String {
@@ -2179,27 +2179,39 @@ enum class PersonaType(val weight: Double, private var dropRate: String? = null)
21792179
contributionCount.toSvg(0.0, 2.0)
21802180
).replace("*{contribution-display}", "default")
21812181
.replace("*{level-tag-display}", "default")
2182+
.replace("*{level-display}", "default")
21822183
}
21832184

21842185
Mode.LINE_NO_CONTRIBUTION -> {
21852186
this.replace("*{username-tag-display}", "none")
21862187
.replace("*{username-display}", "none")
21872188
.replace("*{contribution-display}", "none")
21882189
.replace("*{level-tag-display}", "default")
2190+
.replace("*{level-display}", "default")
21892191
}
21902192

21912193
Mode.NAME_WITH_LEVEL -> {
21922194
this.replace("*{username-tag-display}", "none")
21932195
.replace("*{username-display}", "default")
21942196
.replace("*{level-tag-display}", "none")
21952197
.replace("*{contribution-display}", "none")
2198+
.replace("*{level-display}", "default")
2199+
}
2200+
2201+
Mode.NONE -> {
2202+
this.replace("*{username-tag-display}", "none")
2203+
.replace("*{username-display}", "none")
2204+
.replace("*{contribution-display}", "none")
2205+
.replace("*{level-tag-display}", "none")
2206+
.replace("*{level-display}", "none")
21962207
}
21972208

21982209
else -> {
21992210
this.replace("*{username-tag-display}", "none")
22002211
.replace("*{username-display}", "none")
22012212
.replace("*{contribution-display}", "none")
22022213
.replace("*{level-tag-display}", "none")
2214+
.replace("*{level-display}", "default")
22032215
}
22042216
}
22052217
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.gitanimals.core.extension
2+
3+
import jakarta.servlet.http.HttpServletResponse
4+
import org.springframework.http.HttpHeaders
5+
6+
object HttpResponseExtension {
7+
8+
fun HttpServletResponse.cacheControl(maxAgeSeconds: Int): HttpServletResponse {
9+
this.setHeader(
10+
HttpHeaders.CACHE_CONTROL,
11+
"no-cache, no-store, must-revalidate, max-age=$maxAgeSeconds"
12+
)
13+
this.setHeader(HttpHeaders.PRAGMA, "no-cache")
14+
return this
15+
}
16+
}

src/main/kotlin/org/gitanimals/render/controller/AnimationController.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package org.gitanimals.render.controller
22

33
import jakarta.servlet.http.HttpServletResponse
44
import org.gitanimals.core.Mode
5+
import org.gitanimals.core.extension.HttpResponseExtension.cacheControl
56
import org.gitanimals.core.extension.StringExtension.deleteBrackets
67
import org.gitanimals.core.extension.StringExtension.trimNotDigitCharacters
78
import org.gitanimals.render.app.AnimationFacade
8-
import org.springframework.http.HttpHeaders
99
import org.springframework.web.bind.annotation.GetMapping
1010
import org.springframework.web.bind.annotation.PathVariable
1111
import org.springframework.web.bind.annotation.RequestParam
@@ -45,13 +45,4 @@ class AnimationController(
4545
mode = mode,
4646
)
4747
}
48-
49-
private fun HttpServletResponse.cacheControl(maxAgeSeconds: Int): HttpServletResponse {
50-
this.setHeader(
51-
HttpHeaders.CACHE_CONTROL,
52-
"no-cache, no-store, must-revalidate, max-age=$maxAgeSeconds"
53-
)
54-
this.setHeader(HttpHeaders.PRAGMA, "no-cache")
55-
return this
56-
}
5748
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.gitanimals.render.controller
2+
3+
import jakarta.servlet.http.HttpServletResponse
4+
import org.gitanimals.core.Mode
5+
import org.gitanimals.core.extension.HttpResponseExtension.cacheControl
6+
import org.gitanimals.core.extension.StringExtension.deleteBrackets
7+
import org.gitanimals.core.extension.StringExtension.trimNotDigitCharacters
8+
import org.gitanimals.render.app.AnimationFacade
9+
import org.springframework.beans.factory.annotation.Value
10+
import org.springframework.web.bind.annotation.GetMapping
11+
import org.springframework.web.bind.annotation.PathVariable
12+
import org.springframework.web.bind.annotation.RequestHeader
13+
import org.springframework.web.bind.annotation.RequestParam
14+
import org.springframework.web.bind.annotation.RestController
15+
16+
@RestController
17+
class InternalAnimationController(
18+
private val animationFacade: AnimationFacade,
19+
@Value("\${internal.image.secret}") private val internalImageSecret: String,
20+
) {
21+
22+
@GetMapping(value = ["/lines/{username}/only-pets"], produces = ["image/svg+xml"])
23+
fun getOnlyPetAnimation(
24+
@PathVariable("username") username: String,
25+
@RequestParam(name = "pet-id", defaultValue = "0") personaId: String,
26+
@RequestHeader("Image-Secret") renderSecret: String,
27+
response: HttpServletResponse,
28+
): String {
29+
require(renderSecret == this.internalImageSecret)
30+
response.cacheControl(3600)
31+
32+
return animationFacade.getLineAnimation(
33+
username = username.deleteBrackets(),
34+
personaId = personaId.trimNotDigitCharacters().toLong(),
35+
mode = Mode.NONE,
36+
)
37+
}
38+
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sentry.traces-sample-rate=1.0
3030

3131
internal.secret=a
3232
internal.auth.secret=b
33+
internal.image.secret=c
3334

3435
spring.application.name=render.gitanimals
3536
management.endpoints.web.exposure.include=health,prometheus

src/main/resources/persona/animal/bbibbi.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/cat.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/cheese-cat-collaborator.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/cheese-cat.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/dessert-fox-collaborator.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/dessert-fox-rudolph.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/dessert-fox.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/fishman-glasses.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/fishman.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/flamingo.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/galchi-cat.svg

Lines changed: 2 additions & 1 deletion
Loading

src/main/resources/persona/animal/ghost-collaborator.svg

Lines changed: 2 additions & 1 deletion
Loading

0 commit comments

Comments
 (0)