Skip to content

Commit

Permalink
fix parsing of URIs and channel URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
memo33 committed Dec 21, 2024
1 parent 2e445e8 commit 891dd87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/scala/sc4pac/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ object JsonData extends SharedData {

implicit val subPathRw: ReadWriter[os.SubPath] = readwriter[String].bimap[os.SubPath](_.toString(), os.SubPath(_))

implicit val uriRw: ReadWriter[java.net.URI] = readwriter[String].bimap[java.net.URI](_.toString(),
MetadataRepository.parseChannelUrl(_).left.map(new IllegalArgumentException(_)).toTry.get)
implicit val uriRw: ReadWriter[java.net.URI] = readwriter[String].bimap[java.net.URI](_.toString(), new java.net.URI(_))

private[sc4pac] def bareModuleRead(s: String) =
Sc4pac.parseModule(s) match {
Expand Down
9 changes: 8 additions & 1 deletion src/main/scala/sc4pac/api/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,16 @@ class Api(options: sc4pac.cli.Commands.ServerOptions) {
wrapHttpEndpoint {
for {
urls <- parseOr400[Seq[java.net.URI]](req.body, ErrorMessage.BadRequest("Malformed channel URLs.", "Pass channels as an array of strings."))
urls2 <- ZIO.foreach(urls)(url => ZIO.fromEither(
MetadataRepository.parseChannelUrl(url.toString) // sanitization
.left.map(err => jsonResponse(
ErrorMessage.BadRequest("Malformed channel URL.", err)
).status(Status.BadRequest)
)
))
pluginsData <- readPluginsOr409
pluginsData2 = pluginsData.copy(config = pluginsData.config.copy(channels =
if (urls.nonEmpty) urls.distinct else Constants.defaultChannelUrls
if (urls2.nonEmpty) urls2.distinct else Constants.defaultChannelUrls
))
path <- JD.Plugins.pathURIO
_ <- JsonIo.write(path, pluginsData2, None)(ZIO.succeed(()))
Expand Down

0 comments on commit 891dd87

Please sign in to comment.