<commit_before>package com.olegych.scastie.web.routes

import com.olegych.scastie.util.Base64UUID
import com.olegych.scastie.api.{SnippetId, SnippetUserPart}

import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.Directives._

import System.{lineSeparator => nl}

class FrontPageRoutes(production: Boolean) {

  private val index = getFromResource("public/index.html")

  private def embeddedRessource(snippetId: SnippetId): String = {
    val user =
      snippetId.user match {
        case Some(SnippetUserPart(login, update)) => {
          s"user: '$login', update: $update,"
        }
        case None => ""
      }

    val id = "id-" + Base64UUID.create

    val embeddedUrlBase =
      if (production) "https://scastie.scala-lang.org"
      else "http://localhost:9000"

    s"""|document.write("
        |<div id='$id'></div>
        |<script src='$embeddedUrlBase/embedded.js'></script>
        |<script>
        |window.addEventListener('load', function(event) {
        |  com.olegych.scastie.client.ClientMain.embeddedRessource({
        |    base64UUID: '${snippetId.base64UUID}',
        |    $user
        |    injectId: '$id',
        |    serverUrl: '$embeddedUrlBase'
        |  });
        |});
        |</script>
        |");""".stripMargin.split(nl).map(_.trim).mkString("")
  }

  val routes: Route =
    concat(
      get(
        concat(
          path("public" / Remaining)(
            path ⇒ getFromResource("public/" + path)
          ),
          path("embedded.js")(getFromResource("public/embedded.js"))
        )
      ),
      get(
        concat(
          pathSingleSlash(index),
          snippetId(_ => index),
          snippetIdExtension(".js")(sid => complete(embeddedRessource(sid)))
        )
      )
    )
}
<commit_msg>Fix embedded ressources<commit_after>package com.olegych.scastie.web.routes

import com.olegych.scastie.util.Base64UUID
import com.olegych.scastie.api.{SnippetId, SnippetUserPart}

import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.Directives._

import System.{lineSeparator => nl}

class FrontPageRoutes(production: Boolean) {

  private val index = getFromResource("public/index.html")

  private def embeddedRessource(snippetId: SnippetId): String = {
    val user =
      snippetId.user match {
        case Some(SnippetUserPart(login, update)) => {
          s"user: '$login', update: $update,"
        }
        case None => ""
      }

    val id = "id-" + Base64UUID.create

    val embeddedUrlBase =
      if (production) "https://scastie.scala-lang.org"
      else "http://localhost:9000"

    s"""|document.write("
        |<div id='$id'></div>
        |<script src='$embeddedUrlBase/embedded.js'></script>
        |<script>
        |window.addEventListener('load', function(event) {
        |  com.olegych.scastie.client.ScastieMain.embeddedRessource({
        |    base64UUID: '${snippetId.base64UUID}',
        |    $user
        |    injectId: '$id',
        |    serverUrl: '$embeddedUrlBase'
        |  });
        |});
        |</script>
        |");""".stripMargin.split(nl).map(_.trim).mkString("")
  }

  val routes: Route =
    concat(
      get(
        concat(
          path("public" / Remaining)(
            path ⇒ getFromResource("public/" + path)
          ),
          path("embedded.js")(getFromResource("public/embedded.js"))
        )
      ),
      get(
        concat(
          pathSingleSlash(index),
          snippetId(_ => index),
          snippetIdExtension(".js")(sid => complete(embeddedRessource(sid)))
        )
      )
    )
}

{'fraction_non_alphanumeric': 0.14864487286951664, 'fraction_numerical': 0.006705783738474434, 'mean_word_length': 2.367826904985889, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6722637', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1145, 'n_words': 178}