Skip to content

Commit ba00416

Browse files
committed
refactor(Streamer): inject IDateTimeZone as constructor arg
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent bb72eed commit ba00416

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\Files\IRootFolder;
2828
use OCP\Files\Mount\IMountManager;
2929
use OCP\IConfig;
30+
use OCP\IDateTimeZone;
3031
use OCP\IDBConnection;
3132
use OCP\IGroupManager;
3233
use OCP\IL10N;
@@ -105,6 +106,7 @@ public function createServer(
105106
$tree,
106107
$this->logger,
107108
$this->eventDispatcher,
109+
\OCP\Server::get(IDateTimeZone::class),
108110
));
109111

110112
// Some WebDAV clients do require Class 2 WebDAV support (locking), since

apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\Files\File as NcFile;
1616
use OCP\Files\Folder as NcFolder;
1717
use OCP\Files\Node as NcNode;
18+
use OCP\IDateTimeZone;
1819
use Psr\Log\LoggerInterface;
1920
use Sabre\DAV\Server;
2021
use Sabre\DAV\ServerPlugin;
@@ -41,6 +42,7 @@ public function __construct(
4142
private Tree $tree,
4243
private LoggerInterface $logger,
4344
private IEventDispatcher $eventDispatcher,
45+
private IDateTimeZone $timezoneFactory,
4446
) {
4547
}
4648

@@ -163,7 +165,7 @@ public function handleDownload(Request $request, Response $response): ?bool {
163165
// Full folder is loaded to rename the archive to the folder name
164166
$archiveName = $folder->getName();
165167
}
166-
$streamer = new Streamer($tarRequest, -1, count($content));
168+
$streamer = new Streamer($tarRequest, -1, count($content), $this->timezoneFactory);
167169
$streamer->sendHeaders($archiveName);
168170
// For full folder downloads we also add the folder itself to the archive
169171
if (empty($files)) {

apps/dav/lib/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
use OCP\IAppConfig;
8282
use OCP\ICacheFactory;
8383
use OCP\IConfig;
84+
use OCP\IDateTimeZone;
8485
use OCP\IDBConnection;
8586
use OCP\IGroupManager;
8687
use OCP\IPreview;
@@ -246,6 +247,7 @@ public function __construct(
246247
$this->server->tree,
247248
$logger,
248249
$eventDispatcher,
250+
\OCP\Server::get(IDateTimeZone::class),
249251
));
250252
$this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class));
251253

lib/private/Streamer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public static function isUserAgentPreferTar(IRequest $request): bool {
4141
* @param int $numberOfFiles The number of files (and directories) that will
4242
* be included in the streamed file
4343
*/
44-
public function __construct(IRequest|bool $preferTar, int|float $size, int $numberOfFiles) {
44+
public function __construct(
45+
IRequest|bool $preferTar,
46+
int|float $size,
47+
int $numberOfFiles,
48+
private IDateTimeZone $timezoneFactory,
49+
) {
4550
if ($preferTar instanceof IRequest) {
4651
$preferTar = self::isUserAgentPreferTar($preferTar);
4752
}
@@ -197,7 +202,7 @@ private function fixTimestamp(int $timestamp): int {
197202
if ($this->streamerInstance instanceof ZipStreamer) {
198203
// Zip does not support any timezone information
199204
// while tar is interpreted as Unix time the Zip time is interpreted as local time of the user...
200-
$zone = \OCP\Server::get(IDateTimeZone::class)->getTimeZone($timestamp);
205+
$zone = $this->timezoneFactory->getTimeZone($timestamp);
201206
$timestamp += $zone->getOffset(new \DateTimeImmutable('@' . (string)$timestamp));
202207
}
203208
return $timestamp;

lib/public/AppFramework/Http/ZipResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OC\Streamer;
1111
use OCP\AppFramework\Http;
12+
use OCP\IDateTimeZone;
1213
use OCP\IRequest;
1314

1415
/**
@@ -65,7 +66,7 @@ public function callback(IOutput $output) {
6566
$size += $resource['size'];
6667
}
6768

68-
$zip = new Streamer($this->request, $size, $files);
69+
$zip = new Streamer($this->request, $size, $files, \OCP\Server::get(IDateTimeZone::class));
6970
$zip->sendHeaders($this->name);
7071

7172
foreach ($this->resources as $resource) {

0 commit comments

Comments
 (0)