Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/too long #260

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add alter ego generation to zeflasher and ze server
mariobodemann committed Jul 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e9c59bf599efa11f970a7d72b980435f3d7cb2a7
Original file line number Diff line number Diff line change
@@ -94,12 +94,11 @@ private fun embeddedWebServer(
imageBin()
imagePng()

// Callable from ZeFlasher only?
adminCreateUser(users, ai)
adminListUsers(users)
adminDeleteUser(users)
adminCreateUserBadge(users)

// TODO: Check if callable from ZeBadge (no ssl)
updateUser(users)
getUser(users)
getUserProfileImageBinary(users)
Original file line number Diff line number Diff line change
@@ -8,8 +8,10 @@ import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import java.awt.image.BufferedImage
import java.io.File
import java.util.*
import javax.imageio.ImageIO


fun Route.adminCreateUser(users: UserRepository, ai: AI) =
@@ -46,6 +48,41 @@ fun Route.adminCreateUser(users: UserRepository, ai: AI) =
}
}

fun Route.adminCreateUserBadge(users: UserRepository) =
get("/api/user/{uuid}/badge") {
runCatching {
ifAuthorized {
withParameter("uuid") { uuid ->
val user = users.getUser(uuid)
if (user != null) {
val baseBadgeResource = javaClass.classLoader.getResource("zeAlternativeBadge.bmp")
val baseBadge = ImageIO.read(baseBadgeResource)
val resultBadge = BufferedImage(baseBadge.width, baseBadge.height, BufferedImage.TYPE_INT_RGB)

val profileImageFile = File("./profiles/${uuid}.png")
val profile = ImageIO.read(profileImageFile)

val g = resultBadge.graphics
g.drawImage(baseBadge, 0, 0, 296, 128, null)
g.drawImage(profile, 16, 16, 128 - 32, 128 - 32, null)

g.font = g.font.deriveFont(34f)
user.name.split(' ').forEachIndexed { index, part ->
g.drawString(part, 124, 54 + index * 40)
}

call.respondOutputStream {
ImageIO.write(resultBadge, "bmp", this)
}
}
}
}
}.onFailure {
it.printStackTrace()
call.respondText("Error: ${it.message}.")
}
}

fun Route.adminListUsers(users: UserRepository) =
get("/api/user") {
runCatching {
Binary file not shown.
16 changes: 13 additions & 3 deletions zehardware/zefirmware/zeflash.py
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@
#
# FLASH ME IF YOU CAN!!
#
import datetime
import os
import requests
import subprocess
import shutil
import subprocess
import time

import requests

OPEN_AI_TOKEN = os.getenv("OPEN_AI_TOKEN")
SERVER_TOKEN = os.getenv("ZESERVER_AUTH_TOKEN")
BASE_URL = "https://zebadge.app/"
@@ -267,6 +267,16 @@ def inject_user(user):
user_config
)

open(circuit + "/zeAlternative.bmp", "w").write(
requests.get(
url=f"{BASE_URL}/api/user/{user['uuid']}/badge",
headers={
'Content-Type': 'application/json',
'ZeAuth': SERVER_TOKEN
},
).content.decode()
)


if __name__ == '__main__':
badge_path = find_base_badge_path()