@@ -30,6 +30,9 @@ class Demo implements JsonSerializable {
3030 private string $ hash ;
3131 private string $ backend ;
3232 private string $ path ;
33+ private bool $ showPrivateData = false ;
34+
35+ private ?\DateTimeImmutable $ privateUntil ;
3336
3437 public function __construct (
3538 int $ id ,
@@ -48,7 +51,8 @@ public function __construct(
4851 int $ uploader ,
4952 string $ hash ,
5053 string $ backend ,
51- string $ path
54+ string $ path ,
55+ ?\DateTimeImmutable $ privateUntil ,
5256 ) {
5357 $ this ->id = $ id ;
5458 $ this ->url = $ url ;
@@ -69,6 +73,7 @@ public function __construct(
6973 $ this ->path = $ path ;
7074 $ this ->players = null ;
7175 $ this ->uploaderUser = null ;
76+ $ this ->privateUntil = $ privateUntil ;
7277 }
7378
7479 public function getId (): int {
@@ -154,11 +159,13 @@ public function setUploaderUser(User $uploaderUser): void {
154159 * 'hash': string,
155160 * 'backend': string,
156161 * 'path': string,
162+ * 'private_until': ?string,
157163 * } $row
158164 *
159165 * @return Demo
160166 */
161167 public static function fromRow (array $ row ): self {
168+ $ private = $ row ['private_until ' ];
162169 return new self (
163170 (int ) $ row ['id ' ],
164171 $ row ['url ' ],
@@ -176,7 +183,8 @@ public static function fromRow(array $row): self {
176183 (int ) $ row ['uploader ' ],
177184 $ row ['hash ' ],
178185 $ row ['backend ' ],
179- $ row ['path ' ]
186+ $ row ['path ' ],
187+ $ private ? new \DateTimeImmutable ($ private ) : null ,
180188 );
181189 }
182190
@@ -206,6 +214,10 @@ public function getPath(): string {
206214 return $ this ->path ;
207215 }
208216
217+ public function getPrivateUntil (): ?\DateTimeImmutable {
218+ return $ this ->privateUntil ;
219+ }
220+
209221 /**
210222 * @return array{
211223 * 'id': int,
@@ -226,12 +238,15 @@ public function getPath(): string {
226238 * 'backend': string,
227239 * 'path': string,
228240 * 'players': ?DemoPlayer
241+ * 'private_until': ?string,
229242 * }
230243 */
231244 public function jsonSerialize (): array {
245+ $ now = new \DateTimeImmutable ();
246+ $ isPublic = $ this ->showPrivateData || ($ this ->getPrivateUntil () ? $ this ->getPrivateUntil () <= $ now : true );
232247 $ data = [
233248 'id ' => $ this ->getId (),
234- 'url ' => $ this ->getUrl (),
249+ 'url ' => $ isPublic ? $ this ->getUrl () : '' ,
235250 'name ' => $ this ->getName (),
236251 'server ' => $ this ->getServer (),
237252 'duration ' => $ this ->getDuration (),
@@ -245,13 +260,18 @@ public function jsonSerialize(): array {
245260 'playerCount ' => $ this ->getPlayerCount (),
246261 'uploader ' => $ this ->uploaderUser ? $ this ->getUploaderUser ()->jsonSerialize () : $ this ->getUploader (),
247262 'hash ' => $ this ->getHash (),
248- 'backend ' => $ this ->getBackend (),
249- 'path ' => $ this ->getPath (),
263+ 'backend ' => $ isPublic ? $ this ->getBackend () : '' ,
264+ 'path ' => $ isPublic ? $ this ->getPath () : '' ,
265+ 'private_until ' => $ this ->getPrivateUntil ()?->format(\DateTimeImmutable::ATOM ),
250266 ];
251267 if (\is_array ($ this ->players )) {
252268 $ data ['players ' ] = $ this ->getPlayers ();
253269 }
254270
255271 return $ data ;
256272 }
273+
274+ function showPrivateData (bool $ show ): void {
275+ $ this ->showPrivateData = $ show ;
276+ }
257277}
0 commit comments