Skip to content

Commit

Permalink
Allow for longer filenames when sharing files
Browse files Browse the repository at this point in the history
Updated Kotlin version
  • Loading branch information
FredyH committed Mar 19, 2023
1 parent e965180 commit 2c63861
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform") version "1.8.0" apply false
kotlin("plugin.serialization") version "1.8.0" apply false
kotlin("multiplatform") version "1.8.10" apply false
kotlin("plugin.serialization") version "1.8.10" apply false
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
kotlin("plugin.serialization")
}

val kotlinWrappersVersion = "1.0.0-pre.479"
val kotlinWrappersVersion = "1.0.0-pre.515"

kotlin {
js(IR) {
Expand Down
32 changes: 18 additions & 14 deletions client/src/main/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import mui.material.styles.ThemeProvider
import mui.material.styles.createTheme
import react.*
import react.dom.client.createRoot
import react.router.NavigateFunction
import react.router.Route
import react.router.Routes
import react.router.*
import react.router.dom.HashRouter
import react.router.useNavigate
import web.dom.document
import web.window.window

Expand Down Expand Up @@ -63,7 +60,7 @@ fun useScope(): CoroutineScope {
}

fun useAccount(required: Boolean = true): Pair<AccountInfoV2?, StateSetter<AccountInfoV2?>> {
val contextData = useContext(AccountContext)
val contextData = useContext(AccountContext)!!
val navigate = useNavigate()

useEffectOnce {
Expand All @@ -90,6 +87,13 @@ fun useAccount(required: Boolean = true): Pair<AccountInfoV2?, StateSetter<Accou
return contextData.account to contextData.setAccount
}

private fun ChildrenBuilder.route(builder: (PathRouteProps).() -> Unit) {
Route {
@Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
builder(this as PathRouteProps)
}
}

val App = VFC {
val (account, setAccount) = useState<AccountInfoV2?>(null)

Expand All @@ -112,39 +116,39 @@ val App = VFC {
theme = usedTheme
HashRouter {
Routes {
Route {
route {
path = "/account"
element = createElement(AccountPageComponent)
}
Route {
route {
path = "/change-password"
element = createElement(ChangePasswordComponent)
}
Route {
route {
path = "/api-key"
element = createElement(ApiKeyComponent)
}
Route {
route {
path = "/share"
element = createElement(ShareComponent)
}
Route {
route {
path = "/create-account"
element = createElement(CreateAccountComponent)
}
Route {
route {
path = "/share/:token"
element = createElement(ShareDownloadComponent)
}
Route {
route {
path = "/contact"
element = createElement(ContactComponent)
}
Route {
route {
path = "/statistics"
element = createElement(StatisticsPage)
}
Route {
route {
path = "/"
element = createElement(LoginPageComponent)
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/kotlin/WebSocketSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WebSocketSender(private val path: String, private val file: File, private
onProgress(0)
sendJob = scope.launch {
var sent = 0.0
while (sent < file.size.toDouble()) {
while (sent < file.size) {
tokenChannel.receive()
val end = (sent + chunkSize).coerceAtMost(file.size)
socket.send(file.slice(sent, end))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import mui.material.*
import mui.system.sx
import react.Props
import react.ReactNode
import react.dom.html.ButtonType
import react.dom.html.ReactHTML
import react.dom.onChange
import react.fc
import react.router.useNavigate
import react.useState
import web.html.ButtonType

val ChangePasswordComponent = fc<Props>("ChangePasswordComponent") {
val navigate = useNavigate()
Expand Down
3 changes: 2 additions & 1 deletion client/src/main/kotlin/components/CreateAccountComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import react.*
import react.dom.html.ReactHTML
import react.dom.onChange
import react.router.useNavigate
import web.html.ButtonType

external interface CreateAccountProps : Props {
var showAlert: (String, AlertColor) -> Unit
Expand Down Expand Up @@ -105,7 +106,7 @@ val CreateAccountComponent = fc<CreateAccountProps>("CreateAccountComponent") {p

Button {
attrs {
type = react.dom.html.ButtonType.submit
type = ButtonType.submit
fullWidth = true
variant = ButtonVariant.contained
sx {
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/kotlin/components/LoginComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import mui.material.styles.TypographyVariant
import mui.material.styles.useTheme
import mui.system.sx
import react.*
import react.dom.html.ButtonType
import react.dom.html.ReactHTML
import react.dom.html.ReactHTML.form
import react.dom.html.ReactHTML.h1
import react.dom.html.ReactHTML.main
import react.dom.onChange
import react.router.Navigate
import react.router.useNavigate
import web.html.ButtonType
import web.html.HTMLInputElement
import web.html.InputType

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/kotlin/controllers/ShareController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fun Route.shareRoutes() {
return@webSocket
}
val announceMessage = Json.decodeFromString<AnnounceMessage>(announceFrame.data.decodeToString())
if (!validateFilename(announceMessage.fileName) || announceMessage.fileName.length !in 2..50) {
if (!validateFilename(announceMessage.fileName) || announceMessage.fileName.length !in 2..150) {
logger.warn("User $userId attempted share session with invalid filename: ${announceMessage.fileName}")
val errorMessage =
Json.encodeToString<ShareWebSocketMessage>(ErrorMessage("Invalid filename"))
Expand Down

0 comments on commit 2c63861

Please sign in to comment.