Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 2 additions & 5 deletions application/web/src/jsMain/kotlin/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Writeopia</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="skiko.js"> </script>

<style>
/* Basic styles to ensure the Compose content fills the entire viewport.
Expand All @@ -21,11 +22,7 @@
</head>
<body>

<div id="root">
Loading...
</div>

<script src="main.js"></script>
<div id="composeApp"></div>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.flow.MutableStateFlow

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
ComposeViewport {
ComposeViewport("composeApp") {
ImageLoadConfig.configImageLoad()
CreateAppInMemory()
}
Expand Down
4 changes: 0 additions & 4 deletions application/web/src/wasmJsMain/kotlin/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
</head>
<body>

<div id="root">
Loading...
</div>

<script src="main.js"></script>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import io.writeopia.connection.Urls
import io.writeopia.connection.wrWebClient
import io.writeopia.sdk.models.document.Document
import io.writeopia.sdk.models.document.Folder
import io.writeopia.sdk.models.id.GenerateId
import io.writeopia.sdk.serialization.extensions.toApi
import io.writeopia.sql.WriteopiaDbBackend
import kotlin.time.Clock
import kotlin.time.ExperimentalTime

object DocumentsService {
Expand Down Expand Up @@ -65,6 +67,48 @@ object DocumentsService {
writeopiaDb: WriteopiaDbBackend
): Folder? = writeopiaDb.getFolderById(id, userId)

suspend fun createFolder(
parentFolderId: String,
title: String,
workspaceId: String,
writeopiaDb: WriteopiaDbBackend
): Folder {
val now = Clock.System.now()
val folder = Folder(
id = GenerateId.generate(),
parentId = parentFolderId,
title = title,
createdAt = now,
lastUpdatedAt = now,
workspaceId = workspaceId,
itemCount = 0
)

writeopiaDb.saveFolder(folder)
return folder
}

suspend fun upsertDocument(
document: Document,
workspaceId: String,
writeopiaDb: WriteopiaDbBackend,
useAi: Boolean
): Document {
val documentWithWorkspace = document.copy(
workspaceId = workspaceId,
lastUpdatedAt = Clock.System.now(),
lastSyncedAt = Clock.System.now()
)

writeopiaDb.saveDocument(documentWithWorkspace)

if (useAi) {
sendToAiHub(listOf(documentWithWorkspace), workspaceId)
}

return documentWithWorkspace
}

private suspend fun sendToAiHub(documents: List<Document>, workspaceId: String,) =
wrWebClient.post("${Urls.AI_HUB}/documents/") {
contentType(ContentType.Application.Json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import io.writeopia.sdk.serialization.extensions.toApi
import io.writeopia.sdk.serialization.extensions.toModel
import io.writeopia.sdk.serialization.json.SendDocumentsRequest
import io.writeopia.sdk.serialization.json.SendFoldersRequest
import io.writeopia.sdk.serialization.request.CreateFolderRequest
import io.writeopia.sdk.serialization.request.ImageUploadRequest
import io.writeopia.sdk.serialization.request.UpsertDocumentRequest
import io.writeopia.sdk.serialization.request.WorkspaceDiffRequest
import io.writeopia.sdk.serialization.response.FolderContentResponse
import io.writeopia.sdk.serialization.response.WorkspaceDiffResponse
Expand Down Expand Up @@ -193,6 +195,35 @@ fun Routing.documentsRoute(
}
}

authenticate("auth-jwt", optional = debug) {
post<CreateFolderRequest>("/api/workspace/{workspaceId}/folder/{parentFolderId}/create") { request ->
val userId = getUserId() ?: ""
val workspaceId = call.pathParameters["workspaceId"] ?: ""
val parentFolderId = call.pathParameters["parentFolderId"] ?: ""

runIfMember(userId, workspaceId, writeopiaDb, debug) {
try {
val folder = DocumentsService.createFolder(
parentFolderId = parentFolderId,
title = request.title,
workspaceId = workspaceId,
writeopiaDb = writeopiaDb
)

call.respond(
status = HttpStatusCode.Created,
message = folder.toApi()
)
} catch (e: Exception) {
call.respond(
status = HttpStatusCode.InternalServerError,
message = "${e.message}"
)
}
}
}
}

authenticate("auth-jwt", optional = debug) {
post<SendDocumentsRequest>("/api/workspace/document") { request ->
val userId = getUserId() ?: ""
Expand Down Expand Up @@ -242,6 +273,38 @@ fun Routing.documentsRoute(
}
}

authenticate("auth-jwt", optional = debug) {
post<UpsertDocumentRequest>("/api/workspace/{workspaceId}/document/upsert") { request ->
val userId = getUserId() ?: ""
val workspaceId = call.pathParameters["workspaceId"] ?: ""

runIfMember(userId, workspaceId, writeopiaDb, debug) {
try {
val documentModel = request.document
.copy(workspaceId = workspaceId)
.toModel()

val upsertedDocument = DocumentsService.upsertDocument(
document = documentModel,
workspaceId = workspaceId,
writeopiaDb = writeopiaDb,
useAi = useAi
)

call.respond(
status = HttpStatusCode.OK,
message = upsertedDocument.toApi()
)
} catch (e: Exception) {
call.respond(
status = HttpStatusCode.InternalServerError,
message = "${e.message}"
)
}
}
}
}

authenticate("auth-jwt", optional = debug) {
post<SendFoldersRequest>("/api/workspace/folder") { request ->
val userId = getUserId() ?: ""
Expand Down
Loading