Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pse-trapp-public
IntentFinder
Commits
0e711893
Commit
0e711893
authored
Jun 04, 2021
by
Chiraz Boukadida
Browse files
[fix,31] versioning
parent
45dc3284
Pipeline
#73287
passed with stages
in 2 minutes and 16 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/server/Application.kt
View file @
0e711893
package
de.h_da.fbi.smebt.intentfinder.server
import
de.h_da.fbi.smebt.intentfinder.server.nlp.PythonBridge
import
de.h_da.fbi.smebt.intentfinder.server.sources.DocxReader
import
io.ktor.application.*
import
io.ktor.features.*
import
io.ktor.http.*
import
io.ktor.request.*
import
io.ktor.response.*
import
io.ktor.routing.*
import
io.ktor.serialization.*
import
kotlinx.serialization.json.Json
import
registerUploadRoutes
import
java.io.File
import
java.lang.RuntimeException
import
java.nio.file.Files
import
java.nio.file.Paths
import
kotlinx.serialization.Serializable
import
java.text.SimpleDateFormat
import
java.util.*
import
io.ktor.http.content.*
@Serializable
data class
FileStatus
(
val
path
:
String
,
val
status
:
String
)
fun
main
(
args
:
Array
<
String
>):
Unit
=
io
.
ktor
.
server
.
netty
.
EngineMain
.
main
(
args
)
...
...
@@ -42,50 +55,10 @@ fun Application.module(testing: Boolean = false) {
}
// Definition eines Endpunkts zum Hochladen einer DOCX-Datei
post
(
"/file/{chatbotId}"
)
{
call
.
respondText
(
"file was successful uploaded"
)
}
// Definition endpoint zur Änderung eine bereits existierende docx
put
(
"/file/{chatbotId}/{id}/{filename}"
){
}
// Definition eines Endpunkts zur Definition einer FAQ-Webseite mit JSON-Konfiguration
post
(
"/faqRessource/{chatbotId}/{jsonStructure}"
){
}
// get faq with Json Configuration
get
(
"/faqRessource"
){
//Rückgabe Json Object (vgl. #38)
}
// Definition eines Endpunkts zur Definition einer Docx-Datei mit JSON-Konfiguration
post
(
"/docxRessource/{chatbotId}/{filename}"
){
}
// get docx file with Json Configuration
get
(
"/docxRessource"
){
//Rückgabe Json Object (vgl. #37)
}
// Definition endpoint zum Auslesen aller hochgeladener docx mit status
get
(
"/files"
){
}
// Routen ohne Funktionalität
routing
{
}
post
(
"/{chatbotId}/file"
)
{
var
fileDescription
=
""
var
fileName
=
""
post
(
"/file/{chatbotId}"
)
{
var
status
=
"error"
var
status
=
"error"
val
multipartData
=
call
.
receiveMultipart
()
val
pathFile
=
call
.
parameters
[
"chatbotId"
].
toString
()
val
pathAsFile
=
File
(
"uploads/$pathFile"
)
...
...
@@ -104,62 +77,58 @@ fun Application.module(testing: Boolean = false) {
if
(!
file
.
exists
())
{
file
.
createNewFile
()
file
.
writeBytes
(
fileBytes
)
//call.respond("file not found but created")
status
=
"created"
}
else
{
file
.
writeBytes
(
fileBytes
)
status
=
"updated"
status
=
"created"
}
else
{
call
.
respond
(
HttpStatusCode
.
InternalServerError
,
"file alredy exist"
)
}
}
}
}
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$fileName'"
,
status
=
"$status"
))
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$fileName'"
,
status
=
"$status"
))
}
put
(
"/file/{chatbotId}/{id}/{filename}"
)
{
// Definition endpoint zur Änderung eine bereits existierende docx
put
(
"/{chatbotId}/file/{id}/{filename}"
)
{
var
fileDescription
=
""
var
fileName
=
""
var
newName
=
""
val
name
=
call
.
parameters
[
"filename"
].
toString
()
val
pathFile
=
call
.
parameters
[
"chatbotId"
].
toString
()
var
status
=
"error"
val
pathAsFile
=
File
(
"uploads/$pathFile"
)
if
(!
Files
.
exists
(
Paths
.
get
(
pathFile
)))
{
pathAsFile
.
mkdir
()
}
var
status
=
"error"
val
file
=
File
(
"uploads/$pathFile/$name "
)
val
multipartData
=
call
.
receiveMultipart
()
var
fileContent
=
""
var
fileContent
=
""
multipartData
.
forEachPart
{
part
->
when
(
part
)
{
is
PartData
.
FormItem
->
{
if
(
part
.
name
.
toString
().
equals
(
"description"
))
{
if
(
part
.
name
.
toString
().
equals
(
"description"
))
{
fileDescription
=
part
.
value
}
if
(
part
.
name
.
toString
().
equals
(
"id"
))
{
if
(
part
.
name
.
toString
().
equals
(
"id"
))
{
var
fileId
=
part
.
value
if
(
!
fileId
.
equals
(
call
.
parameters
[
"id"
].
toString
()))
call
.
respond
(
"file not f
ound
"
)
if
(!
fileId
.
equals
(
call
.
parameters
[
"id"
].
toString
()))
call
.
respond
(
HttpStatusCode
.
NotF
ound
)
}
}
is
PartData
.
FileItem
->
{
if
(
file
.
exists
())
{
if
(
file
.
readText
().
equals
(
part
.
streamProvider
().
toString
()))
{
call
.
respondText
(
"file exist but no change detected"
)
}
else
{
fileName
=
part
.
originalFileName
as
String
val
time
=
System
.
currentTimeMillis
()
val
date
=
Date
(
time
)
val
format
=
SimpleDateFormat
(
"yyMMddHHmm"
)
val
current
=
format
.
format
(
date
)
newName
=
file
.
nameWithoutExtension
+
"_"
+
current
+
"."
+
file
.
extension
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
File
(
"uploads/$pathFile/$fileName"
).
writeBytes
(
fileBytes
)
fileContent
=
part
.
streamProvider
().
reader
().
readText
()
status
=
"updated"
}
}
else
{
file
.
createNewFile
()
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
file
.
writeBytes
(
fileBytes
)
status
=
"created"
File
(
"uploads/$pathFile/$newName"
).
writeBytes
(
fileBytes
)
fileContent
=
part
.
streamProvider
().
reader
().
readText
()
status
=
"updated"
}
else
{
call
.
respond
(
HttpStatusCode
.
NotFound
,
"file not found"
)
}
}
...
...
@@ -168,13 +137,15 @@ fun Application.module(testing: Boolean = false) {
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$
file
Name'"
,
status
=
"$status"
))
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$
new
Name'"
,
status
=
"$status"
))
}
}
registerUploadRoutes
()
}
class
InternalServerErrorException
:
RuntimeException
()
src/ktor-server/uploads/1/Dok_2106040947.docx
0 → 100644
View file @
0e711893
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment