export limit
This commit is contained in:
parent
15bdc70f48
commit
429afa4290
|
@ -43,7 +43,8 @@ object Game extends LilaController {
|
|||
def exportApi = Scoped(_.Game.Read) { req => me =>
|
||||
val since = getLong("since", req) map { ts => new DateTime(ts) }
|
||||
val until = getLong("until", req) map { ts => new DateTime(ts) }
|
||||
fuccess(streamGamesPgn(me, since, until))
|
||||
val max = getInt("max", req)
|
||||
fuccess(streamGamesPgn(me, since, until, max))
|
||||
}
|
||||
|
||||
private val ExportRateLimitPerUser = new lila.memo.RateLimit[lila.user.User.ID](
|
||||
|
@ -53,10 +54,10 @@ object Game extends LilaController {
|
|||
key = "game_export.user"
|
||||
)
|
||||
|
||||
private def streamGamesPgn(user: lila.user.User, since: Option[DateTime], until: Option[DateTime]) =
|
||||
private def streamGamesPgn(user: lila.user.User, since: Option[DateTime], until: Option[DateTime], max: Option[Int] = None) =
|
||||
ExportRateLimitPerUser(user.id, cost = 1) {
|
||||
val date = (DateTimeFormat forPattern "yyyy-MM-dd") print new DateTime
|
||||
Ok.chunked(Env.api.pgnDump.exportUserGames(user.id, since, until)).withHeaders(
|
||||
Ok.chunked(Env.api.pgnDump.exportUserGames(user.id, since, until, max | Int.MaxValue)).withHeaders(
|
||||
CONTENT_TYPE -> pgnContentType,
|
||||
CONTENT_DISPOSITION -> ("attachment; filename=" + s"lichess_${user.username}_$date.pgn")
|
||||
)
|
||||
|
|
|
@ -29,13 +29,13 @@ final class PgnDump(
|
|||
}
|
||||
}
|
||||
|
||||
def exportUserGames(userId: String, since: Option[DateTime], until: Option[DateTime]): Enumerator[String] = {
|
||||
def exportUserGames(userId: String, since: Option[DateTime], until: Option[DateTime], max: Int): Enumerator[String] = {
|
||||
import reactivemongo.play.iteratees.cursorProducer
|
||||
import lila.db.dsl._
|
||||
GameRepo.sortedCursor(
|
||||
Query.user(userId) ++ Query.createdBetween(since, until),
|
||||
Query.sortCreated
|
||||
).enumerator() &> toPgn
|
||||
).enumerator(maxDocs = max) &> toPgn
|
||||
}
|
||||
|
||||
def exportGamesFromIds(ids: List[String]): Enumerator[String] =
|
||||
|
|
Loading…
Reference in a new issue