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
8 changes: 4 additions & 4 deletions analytics_service/src/main/scala/backend/server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def getAnalytics(folderId: String): IO[Response[IO]] = {
val smallest = sortedBySize.headOption
val largest = sortedBySize.lastOption
val totalSize = files.map(_.size_bytes).sum
val spaceLeft = maxDriveSpace - totalSize
val spaceLeft = (maxDriveSpace - totalSize)

val createdDates = files.flatMap(f => parseDate(f.created_at))
val mostRecentCreated =
createdDates.sorted.lastOption.map(_.toString).getOrElse("N/A")
files.sortBy(_.created_at).headOption.map(_.file_name).getOrElse("N/A")

val uploadedDates = files.flatMap(f => parseDate(f.created_at))
val mostRecentUploaded =
Expand Down Expand Up @@ -104,7 +104,7 @@ def getAnalytics(folderId: String): IO[Response[IO]] = {
"MostRecentFileUploadDate" -> Json.fromString(
mostRecentUploaded
),
"TotalSize" -> Json.fromInt(totalSize),
"TotalSize" -> Json.fromInt(totalSize / 1000000),
"NumFilesToday" -> Json.fromInt(
uploadedToday
),
Expand All @@ -128,7 +128,7 @@ def getAnalytics(folderId: String): IO[Response[IO]] = {
"NumFolders" -> Json.fromInt(
files.map(_.folder_id).distinct.size
),
"SizeLeft" -> Json.fromInt(spaceLeft),
"SizeLeft" -> Json.fromInt(spaceLeft / 1000000),
"BiggestFile" -> Json
.fromInt(
files
Expand Down
2 changes: 1 addition & 1 deletion api_gateway_service/src/main/scala/backend/server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object server extends IOApp:

private val corsPolicy = CORS.policy
.withAllowOriginHost(Set(
Origin.Host(Uri.Scheme.http, Uri.RegName("localhost"), Some(5173))
Origin.Host(Uri.Scheme.http, Uri.RegName(config.CLIENT_DOMAIN), Some(config.CLIENT_PORT))
))
.withAllowCredentials(true)
.withAllowMethodsIn(Set(Method.GET, Method.POST, Method.PUT, Method.DELETE, Method.OPTIONS))
Expand Down
2 changes: 2 additions & 0 deletions api_gateway_service/src/main/scala/backend/utils/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ object config {
val JWT_EXPIRY_IN_SECONDS = sys.env.get("JWT_EXPIRY_IN_SECONDS").flatMap(_.toIntOption).getOrElse(2592000)
val CHATBOT_SERVICE_PORT: String = sys.env.getOrElse("CHATBOT_SERVICE_PORT", "55550")
val CHATBOT_SERVICE_URL: String = sys.env.getOrElse("CHATBOT_SERVICE_URL", "http://localhost")
val CLIENT_PORT: Int = sys.env.get("CLIENT_PORT").flatMap(_.toIntOption).getOrElse(5173)
val CLIENT_DOMAIN: String = sys.env.getOrElse("CLIENT_DOMAIN", "localhost")

}
10 changes: 5 additions & 5 deletions chatbot_service/src/main/scala/backend/core/RuleEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object RuleEngine {

ChatRule(
name = "recent_upload_date_stat",
priority = 80,
priority = 81,
matches = (input, tokens) => matchesToken(input, tokens.RecentUploadDateStat.input_tokens),
execute = (tokens, r, user_id) => fetchAnalytics(user_id).flatMap { data =>
randomResponse(tokens.RecentUploadDateStat.output.text, tokens.RecentUploadDateStat.output.html_object, response => response.replace("{}", data.MostRecentFileUploadDate))(r)
Expand All @@ -98,7 +98,7 @@ object RuleEngine {

ChatRule(
name = "daily_uploads_stat",
priority = 80,
priority = 81,
matches = (input, tokens) => matchesToken(input, tokens.DailyUploadsStat.input_tokens),
execute = (tokens, r, user_id) => fetchAnalytics(user_id).flatMap { data =>
randomResponse(tokens.DailyUploadsStat.output.text, tokens.DailyUploadsStat.output.html_object, response => response.replace("{}", data.NumFilesToday.toString))(r)
Expand All @@ -107,7 +107,7 @@ object RuleEngine {

ChatRule(
name = "weekly_uploads_stat",
priority = 80,
priority = 81,
matches = (input, tokens) => matchesToken(input, tokens.WeeklyUploadsStat.input_tokens),
execute = (tokens, r, user_id) => fetchAnalytics(user_id).flatMap { data =>
randomResponse(tokens.WeeklyUploadsStat.output.text, tokens.WeeklyUploadsStat.output.html_object, response => response.replace("{}", data.NumFilesThisWeek.toString))(r)
Expand All @@ -116,7 +116,7 @@ object RuleEngine {

ChatRule(
name = "monthly_uploads_stat",
priority = 80,
priority = 81,
matches = (input, tokens) => matchesToken(input, tokens.MonthlyUploadsStat.input_tokens),
execute = (tokens, r, user_id) => fetchAnalytics(user_id).flatMap { data =>
randomResponse(tokens.MonthlyUploadsStat.output.text, tokens.MonthlyUploadsStat.output.html_object, response => response.replace("{}", data.NumFilesThisMonth.toString))(r)
Expand All @@ -125,7 +125,7 @@ object RuleEngine {

ChatRule(
name = "yearly_uploads_stat",
priority = 80,
priority = 81,
matches = (input, tokens) => matchesToken(input, tokens.YearlyUploadsStat.input_tokens),
execute = (tokens, r, user_id) => fetchAnalytics(user_id).flatMap { data =>
randomResponse(tokens.YearlyUploadsStat.output.text, tokens.YearlyUploadsStat.output.html_object, response => response.replace("{}", data.NumFilesThisYear.toString))(r)
Expand Down
8 changes: 4 additions & 4 deletions chatbot_service/src/main/scala/backend/data/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

"RecentFileStat": {
"input_tokens": [
"last uploaded", "most recent file", "last uploaded file", "newest file", "latest file",
"recent file", "recent upload", "last uploaded", "most recent file", "last uploaded file", "newest file", "latest file",
"most recently added", "last stored file", "most current file",
"whats the newest file", "show me latest upload", "display most recent file",
"file added last", "last file uploaded", "most fresh file",
Expand All @@ -111,7 +111,7 @@

"RecentUploadDateStat": {
"input_tokens": [
"last upload", "last upload date", "most recent upload time", "when last uploaded",
"when was", "when was last", "date of last", "time of last", "upload date", "upload time" ,"last upload", "last upload date", "most recent upload time", "when last uploaded",
"time of last upload", "last file upload time", "most recent storage date",
"date of last upload", "when was last upload", "show last upload time",
"display most recent upload date", "last time files were added",
Expand Down Expand Up @@ -139,7 +139,7 @@
"aggregate storage used", "all files combined size"
],
"output": {
"text": ["Total storage used: {} bytes"],
"text": ["Total storage used: {} megabytes"],
"html_object": null
}
},
Expand Down Expand Up @@ -310,7 +310,7 @@
"how much more can I store", "free storage quantity"
],
"output": {
"text": ["Free space remaining: {} bytes"],
"text": ["Free space remaining: {} megabytes"],
"html_object": null
}
},
Expand Down
15 changes: 14 additions & 1 deletion file_service/src/main/scala/backend/server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ import org.http4s.ember.server._
import org.http4s.server.Router
import routes.{chunk_routes, file_routes, folder_routes}
import utils.config
import org.http4s.server.middleware._
import org.http4s.headers.Origin
import org.typelevel.ci.CIString

object server extends IOApp {

private val corsPolicy = CORS.policy
.withAllowOriginHost(Set(
Origin.Host(Uri.Scheme.http, Uri.RegName(config.CLIENT_DOMAIN), Some(config.CLIENT_PORT))
))
.withAllowCredentials(true)
.withAllowMethodsIn(Set(Method.GET, Method.POST, Method.PUT, Method.DELETE, Method.OPTIONS))
.withAllowHeadersIn(Set(CIString("Content-Type"), CIString("Authorization"), CIString("Cookie")))

private val router = Router(
"/folder" -> folder_routes,
"/chunk" -> chunk_routes,
Expand All @@ -25,6 +36,8 @@ object server extends IOApp {
}
).orNotFound

private val corsEnabledRouter = corsPolicy(router)

def run(args: List[String]): IO[ExitCode] = {
val servicePort =
Port.fromString(config.SERVICE_PORT).getOrElse(port"55555")
Expand All @@ -34,7 +47,7 @@ object server extends IOApp {
.default[IO]
.withHost(ipv4"0.0.0.0")
.withPort(servicePort)
.withHttpApp(router)
.withHttpApp(corsEnabledRouter)
.build
.as(())

Expand Down
4 changes: 4 additions & 0 deletions file_service/src/main/scala/utils/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ object config {
sys.env.getOrElse("FILE_SERVICE_PORT", "55555")
val SERVICE_URL: String =
sys.env.getOrElse("FILE_SERVICE_URL", "http://localhost")
val CLIENT_PORT: Int =
sys.env.get("CLIENT_PORT").flatMap(_.toIntOption).getOrElse(5173)
val CLIENT_DOMAIN: String =
sys.env.getOrElse("CLIENT_DOMAIN", "localhost")
}