diff --git a/app/controllers/Game.scala b/app/controllers/Game.scala index edaee3d3be..99ecccf72e 100644 --- a/app/controllers/Game.scala +++ b/app/controllers/Game.scala @@ -38,19 +38,23 @@ object Game extends LilaController { RequireHttp11(req) { Api.GlobalLinearLimitPerIP(HTTPRequest lastRemoteAddress req) { Api.GlobalLinearLimitPerUserOption(me) { - val since = getLong("since", req) map { ts => new DateTime(ts) } - val until = getLong("until", req) map { ts => new DateTime(ts) } - val moves = getBoolOpt("moves", req) | true - val tags = getBoolOpt("tags", req) | true - val clocks = getBoolOpt("clocks", req) | false - val max = getInt("max", req) map (_ atLeast 1) - val perSecond = MaxPerSecond(me match { - case None => 10 - case Some(m) if m is user.id => 50 - case Some(_) => 20 - }) - val formatFlags = lila.game.PgnDump.WithFlags(moves = moves, tags = tags, clocks = clocks) - val config = PgnDump.Config(user, since, until, max, formatFlags, perSecond) + val config = PgnDump.Config( + user = user, + since = getLong("since", req) map { ts => new DateTime(ts) }, + until = getLong("until", req) map { ts => new DateTime(ts) }, + max = getInt("max", req) map (_ atLeast 1), + rated = getBoolOpt("rated", req), + flags = lila.game.PgnDump.WithFlags( + moves = getBoolOpt("moves", req) | true, + tags = getBoolOpt("tags", req) | true, + clocks = getBoolOpt("clocks", req) | false + ), + perSecond = MaxPerSecond(me match { + case None => 10 + case Some(m) if m is user.id => 50 + case Some(_) => 20 + }) + ) val date = (DateTimeFormat forPattern "yyyy-MM-dd") print new DateTime Ok.chunked(Env.api.pgnDump.exportUserGames(config)).withHeaders( CONTENT_TYPE -> pgnContentType, diff --git a/modules/api/src/main/PgnDump.scala b/modules/api/src/main/PgnDump.scala index 565a6b30bd..e9623d271c 100644 --- a/modules/api/src/main/PgnDump.scala +++ b/modules/api/src/main/PgnDump.scala @@ -44,15 +44,15 @@ final class PgnDump( batchSize = config.perSecond.value ).bulkEnumerator(maxDocs = config.max | Int.MaxValue) &> lila.common.Iteratee.delay(1 second) &> - Enumeratee.mapConcat(_.toSeq) &> + Enumeratee.mapConcat(_.filter(config.postFilter).toSeq) &> toPgn(config.flags) } - def exportGamesFromIds(ids: List[String]): Enumerator[String] = - Enumerator.enumerate(ids grouped 50) &> - Enumeratee.mapM[List[String]].apply[List[Game]](GameRepo.gamesFromSecondary) &> - Enumeratee.mapConcat(identity) &> - toPgn(WithFlags()) + // def exportGamesFromIds(ids: List[String]): Enumerator[String] = + // Enumerator.enumerate(ids grouped 50) &> + // Enumeratee.mapM[List[String]].apply[List[Game]](GameRepo.gamesFromSecondary) &> + // Enumeratee.mapConcat(identity) &> + // toPgn(WithFlags()) } object PgnDump { @@ -62,7 +62,10 @@ object PgnDump { since: Option[DateTime] = None, until: Option[DateTime] = None, max: Option[Int] = None, + rated: Option[Boolean] = None, flags: WithFlags, perSecond: MaxPerSecond - ) + ) { + def postFilter(g: Game) = rated.fold(true)(g.rated ==) + } }